Plenary session VIb - un.org fileInstalling the Stata Code for the Microsimulations – cont. 7....
Transcript of Plenary session VIb - un.org fileInstalling the Stata Code for the Microsimulations – cont. 7....
Plenary Session VIb:Implementing the
Microsimulations in Stata
Presentation for the Third Training Workshop of the Project “Assessing Development Strategies to Achieve the
MDGs in Asia”, Jakarta, March 30 – April 2, 2010
Martín CicowiezCEDLAS-UNLP
Marco V SánchezUN-DESA
Outline
• Introduction• Installing the MS Code
– the interaction MAMS-MS– the Stata microsimulations code
• Implementing the Microsimulations• Linking MAMS with the Microsimulations
Introduction
• This presentation assumes some familiarity with– Stata– MS methodology
• The focus is on implementing the Stata MS code– facilitates the interaction between MAMS-in-
GAMS and MS-in-Stata
Introduction – cont.
• The MS code has three main components:1. one written in GAMS that generates MAMS
results that are transferred to Stata2. other written in Stata that transforms MAMS
results – for the Linking Aggregate Variables (LAG) -- in matrices
3. other written in Stata that runs the microsimulation routines, using the matrices from (2) as inputs
Linking MAMS and the Microsimulations
1. Append the db-MAMS-ms.gms and test-db-MAMS-ms.xls files to the MAMS-in-GAMS folder.
2. Create a copy of the file test-db-MAMS-ms.xls, <app>-db-MAMS-ms.xls
– sets definition• aagg• flab2(flab)• tt(t1)• simcur2(sim)
– definition of aggregate activities• maagg(agg,a)
Linking MAMS and the Microsimulations – cont.
2. Adjust the file db-MAMS-ms.gms so that it reads the data in the file <app>-db-MAMS-ms.xls
– created in the previous step3. Run the file db-MAMS-ms.gms as a
restart after running the file drep.gms– generates MAMS results in CSV format for
Stata -- (mams-results.csv)
Installing the Stata Code for the Microsimulations
1. Create a new folder where the MS code will be installed
– for example, C:\microsim-arg2. Unzip the contents of the file microsim-
2010-03-29-dist.zip in the folder created in the previous step
– keep the folder structure!
The MS Stata Code: Folder Structure
indicators_do
output
microsim
db_in
db_out
do (master.do)
microsim-<app>
link-MAMS-ms
db_in
db_out
do (master2.do)
The MS Stata Code: File Structure
start loop
use db_sim.dta
end loop if iternum <=30
master.do run cuantiles.do
use $name_db_file
do prepare_db_<app>.do
do compute_indicators.do
RUN MICROSIM EFFECTS
save db_sim.dta
The MS Stata Code: File Structure –cont.
do sim_ylab2.do
do sim_skill.do
RUN MICROSIM EFFECTS do simul_link.do
do sim_unemp.do
do sim_sector.do
do sim_categ.do
do sim_ylab1.do
Installing the Stata Code for the Microsimulations – cont.
3. Make a copy of the file prepare_db_test.do in C:\microsim-arg\microsim\do to prepare_db_<app>.do
4. Save you raw household survey file in the folder C:\microsim-<app>\microsim\db_in
5. Adapt the file prepare_db_<app>.do to generate the variables indicated with *### for the country under study
– do not change anything else!
List of VariablesHOUSEHOLDSid household identifier num / strsize household size (number of memb numpopwt population weights numyh household total income numypc household per capita income numpl_moderate moderate poverty line numpl_extrema extreme poverty line numpl_1usd 1 US$ poverty line numpl_2usd 2 US$ poverty line num
List of Variables – cont.ALL INDIVIDUALSage age nummale gender (*) 1 = male
0 = femalemale_rep gender (**) 1 = male
0 = femaleskill nivel de calificación numstatus_lab estado laboral 1 = employed
2 = unemployed3 = inactive
member pertenencia a la ms mercado laboral 1 = included0 = not included
(**) it is used for reporting results by gender.
(*) in case this disaggregation is not present in CGE, assign value 1 to all -- our case.
List of Variables – cont.EMPLOYED INDIVIDUALSylab labor income numsector sector of employment num
ej: 1=agr, 2=mnf, 3=svccateg occupational category (*) num
ej: 1=formal, 2=informal(*) in case this disaggregation is not present in CGE, assign value 1 to all -- our case.
Installing the Stata Code for the Microsimulations – cont.
6. Adjust the file master2.do located in the folder C:\microsim-arg\link-MAMS-ms\; change– access path in local macro path_main– access path in global macro path_db_in2
Installing the Stata Code for the Microsimulations – cont.
7. Adjust the file master.do located in the folder C:\microsim-arg\microsim\; change– access path in local macro path_main– name of the household survey file in global
macro name_db_file– name of the file that processes the household
survey; from prepara_db_test.do to prepara_db_<app>.do
– number of iterations in local macro iternum
The MS Code: Two Flavors
• stand-alone• linked to MAMS results
– the focus of this presentation
Run the MS fed with Results from MAMS
• Run the file master2.do located in the folder C:\microsim-<app>\link-MAMS-ms\– uses results from MAMS to feed the MS – all
the effects– upon completion, the summary results can be
found in C:\microsim-<app>\link-MAMS-ms\output\microsim_all.csv
– the results for each simulation and tt can be found in C:\microsim-arg\microsim\output\intervals_simcur2_tt.log
The Summary of Results
• The file that summarizes the MS results contains for each simcur2 and tt the average over iterations of (see next table)
fgt_1usd fgt_2usd fgt_moderate fgt_extreme gini_yhpcfgt_1usd_u fgt_2usd_u fgt_moderate_u fgt_extreme_u gini_yhpc_ufgt_1usd_s fgt_2usd_s fgt_moderate_s fgt_extreme_s gini_yhpc_sfgt_1usd_o fgt_2usd_o fgt_moderate_o fgt_extreme_o gini_yhpc_ofgt_1usd_w1 fgt_2usd_w1 fgt_moderate_w1 fgt_extreme_w1 gini_yhpc_w1fgt_1usd_w2 fgt_2usd_w2 fgt_moderate_w2 fgt_extreme_w2 gini_yhpc_w2fgt_1usd_m fgt_2usd_m fgt_moderate_m fgt_extreme_m gini_yhpc_m
WARNING!!!• It is essencial that the order in which the
different labor categories are introduced is the same in– the file <app>-db-MAMS-ms.xls, and– the file prepara_db_<app>.do
• Besides, if the first activity in aagg is a-agr, the sector variable in the (processed) household survey should be 1 for individuals employed in agricultural activities.
WARNING!!!
• The labor factor is highly disaggregated (skill + activity).
• Therefore, the household survey may not have enough observations to construct income deciles.
• The code includes some checks – in case the number of observations is not enough, reduce “ncuantil”– use quintiles
Top-Down Approach to CGE-Microsimulations
MAMS
LINKING AGGREGATE VARIABLES
MICROSIMULATION
An Example
• Using MAMS-YEM, simulate the scenarios– base– pwe-oil: gradual increase in oil price
• note that QM and QD are complements -- sigma<1– mdg2-ftr
• The MS are fed with MAMS results – the household survey is Yemen 2005/2006– can use a different base year for SAM and
hhd survey
An Example – cont.(changes w.r.t. ttmin – baseyr MS)
UERAT_chgbase mdg2-ftr pwe-oil
f-labn 2010 -1.9% -27.6% -12.5%f-labn 2015 -14.4% -57.4% -39.0%f-labs 2010 20.6% -34.9% 6.9%f-labs 2015 22.6% -33.6% -8.1%f-labt 2010 1.1% -33.3% -23.5%f-labt 2015 -18.4% -33.3% -33.3%
WFAVG_chgbase mdg2-ftr pwe-oil
2010 -2.1% 37.3% 5.4%2015 3.1% 52.4% 21.9%
An Example – cont.real GDP at factor cost
2,500
2,700
2,900
3,100
3,300
3,500
3,700
3,900
4,100
4,300
4,500
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
base mdg2‐ftr pwe‐oil
An Example– cont.fgt0 US$ 2 (%) – m effect
(u+s+w1+w2+m)
0
10
20
30
40
50
60
70
2004 2010 2015
base mdg2ftr pweoil
An Example – cont.fgt0 US$ 2 (%) -- 2015
base mdg2ftr pweoil base mdg2ftr pweoilfgt_2usd 61.2 61.2 61.2fgt_2usd_u 60.6 57.6 58.8 -0.6 -3.6 -2.4fgt_2usd_s 60.7 57.6 58.9 0.1 0.0 0.1fgt_2usd_w1 60.9 57.6 59.1 0.2 0.0 0.2fgt_2usd_w2 60.5 49.4 55.7 -0.4 -8.2 -3.4fgt_2usd_m 60.4 49.3 55.7 -0.1 0.0 0.0
different w.r.t. previous effectlevels