// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // This program generates the inequality figures // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! set more off clear all cls // augment $root with directory where all the files are stored. *gl maindir "D:/Dropbox/Dropbox/RAs/Global_Income_Dynamics_ALL" gl maindir "/Users/mauriciotorresferro/Dropbox/RAs/Global_Income_Dynamics_ALL" /*------------------------------------------------------------------------------ - Paste the names of the subfolders where the main data files and moments are stored. - The various subfolders containing the data files are in $maindir/data. - For example, all data related to inequality can be found in $maindir/data/Inequality. ------------------------------------------------------------------------------*/ // Where the Inequality data is stored (do not modify) gl ineqdata = "Inequality_data" // paste name of the folder where you want the figures to be stored. gl outfolder="Figures" gl folderfile = "$maindir/${outfolder}" // Where the figures are stored ("Figures") (do not modify) gl outfolder = "Figures" gl folderfile = "$maindir/${outfolder}" // Years, from 1983 to 2016 gl yrfirst = 1983 // First year in the dataset gl yrlast = 2016 // Last year in the dataset // Recession years in Canada gl receyears = "1986,1989,1990,1991,2001,2003,2008,2009,2015,2016" * PLOT CHARACTERISTICS * gl xtitlesize = "medium" gl ytitlesize = "medium" gl xlabsize = "medium" gl ylabsize = "medium" gl titlesize = "large" gl subtitlesize = "medium" gl formatfile = "pdf" gl fontface = "Times New Roman" gl marksize = "medium" gl legesize = "medium" /* *=============================================* * INEQUALITY: FIGURE 2A - NORMALIZED MEASURES * *=============================================* This file produces normalized 90--10 percentile differences and 2.56*StDev of permanent earnings, log earnings, and residual earnings. These figures can be produced for three population subgroups, which are men, women, or both men and women. SUBGROUPS: - ALL (all) - MEN (male) - WOMEN (fem) VARIABLE LIST: - permearn - logearn - researn Potential plot variables for this figure include the following: nsd${vari} = standard deviation of earnings measure - stdv_1983 np9010${vari} = p9010${vari} - p9010${vari}_1983 np9901${vari} = p9901${vari} - p9901${vari}_1983 np99901${vari} = p99901${vari} - p99901${vari}_1983 np999901${vari} = p999901${vari} - p999901${vari}_1983 np9990${vari} = p9990${vari} - p9990${vari}_1983 np999_p99${vari} = p999_p99${vari} - p999_p99${vari}_1983 np9999_p999${vari} = p9999_p999${vari} - p9999_p999${vari}_1983, where vari belongs to {permearn,logearn,researn}. To modify plot variables one must adjust the local varilist = "nsd$vari np9010$vari" on line 169. */ * CHOOSE WHICH VARIABLES YOU WANT TO PLOT * local earn_meas_list = "permearn logearn researn " * CHOOSE WHICH POPULATION GROUPS YOU WANT TO MAKE PLOTS FOR * local subgroup = "male fem all" * DEFINE COLOURS TO BE USED IN PLOTS (ONLY LINE 110) local colors = "red blue green navy black maroon forest_green purple gray orange" * DEFINE MARKER SYMBOLS local labsym = "O S" * CHOOSE IF THE LEGEND IS ACTIVE OR NOT: on off local lgactive = "on" * CHOOSE THE POSITION AND LEGEND FORMAT local cols = "1" // Number of columns local posi = "1" // Position (1:Top-right; 5:Bottom-right; 7:Bottom-left; 11:Top-left) * CHOOSE IF THE LIMITS FOR THE Y-AXIS ARE FIXED FOR POPULATION GROUPS: yes no local ylimsfix = "yes" // none defined for this figure * COMBINE ALL FIGURES INTO A SINGLE PDF: no yes local combinepdf = "no" local figname = "" // (do not modify) foreach subgp of local subgroup { // SUBGROUP LOOP foreach var of local earn_meas_list { // VARIABLE LOOP *Which variable will be ploted gl vari = "`var'" *What is the group under analysis? if "`subgp'" == "all"{ insheet using "$maindir/data/${ineqdata}/L_`var'_sumstat.csv", clear local labname = "All" } if "`subgp'" == "male" & "${vari}"== "logearn" { insheet using "$maindir/data/${ineqdata}/L_`var'_male_sumstat_imp.csv", clear keep if male == 1 // Keep the group we want to plot local labname = "Men" } if "`subgp'" == "male" & ("${vari}"== "researn" | "${vari}"== "permearn") { insheet using "$maindir/data/${ineqdata}/L_`var'_male_sumstat.csv", clear keep if male == 1 // Keep the group we want to plot local labname = "Men" *** There are some missing values for women replace p99_99${vari}="." if p99_99${vari}=="x" destring(p99_99${vari}), replace } if "`subgp'" == "fem" & "${vari}" == "logearn" { insheet using "$maindir/data/${ineqdata}/L_`var'_male_sumstat_imp.csv", clear keep if male == 0 // Keep the group we want to plot local labname = "Women" } if "`subgp'" == "fem" & ("${vari}"== "researn" | "${vari}"== "permearn") { insheet using "$maindir/data/${ineqdata}/L_`var'_male_sumstat.csv", clear keep if male == 0 // Keep the group we want to plot local labname = "Women" *** There are some missing values for women replace p99_99${vari}="." if p99_99${vari}=="x" destring(p99_99${vari}), replace } * What is the label for title? if "${vari}" == "logearn"{ local labtitle = "log y{sub:it}" } if "${vari}" == "researn" { local labtitle = "{&epsilon}{sub:it}" } if "${vari}" == "permearn"{ local labtitle = "{&epsilon}{sup:P}{sub:it}" } *What are the x-axis limits if "${vari}" == "logearn"{ local lyear = ${yrfirst} local ryear = ${yrlast} } if "${vari}" == "researn" { local lyear = ${yrfirst} local ryear = ${yrlast} } if "${vari}" == "permearn"{ local lyear = ${yrfirst}+2 local ryear = ${yrlast} } *Normalize Percentiles gen var${vari} = sd${vari}^2 gen p9010${vari} = p90${vari} - p10${vari} gen p9901${vari} = p99${vari} - p1${vari} gen p99901${vari} = p99_9${vari} - p1${vari} gen p999901${vari} = p99_99${vari} - p1${vari} gen p9990${vari} = p99${vari} - p90${vari} gen p999_p99${vari} = p99_9${vari} - p99${vari} gen p9999_p999${vari} = p99_99${vari} - p99_9${vari} * Rescale by first year foreach vv in sd$vari p9010$vari { sum `vv' if year == `lyear', meanonly gen n`vv' = `vv' - r(mean) } *Generate recession vars gen rece = inlist(year,${receyears}) *Rescale standard deviation for plots replace sd$vari = 2.56*sd$vari graph set window fontface "${fontface}" *Define which variables are plotted local varilist = "nsd$vari np9010$vari" *Defime the time variable local timevar = "year" *Define limits of x-axis local xmin = "`lyear'" local xmax = "`ryear'" local xdis = 3 *Define labels local lab1 = "2.56*{&sigma}" local lab2 = "P90-P10" local lab3 = "" local lab4 = "" local lab5 = "" local lab6 = "" local lab7 = "" local lab8 = "" local lab9 = "" *Define Title, Subtitle, and axis labels local xtitle = "" local ytitle = "Dispersion Relative to `lyear'" local title = "Changes in dispersion of `labtitle' for Sample: `labname'" local subtitle = "" *Define name and output file local namefile = "fig2A_`subgp'_${vari}_n" *Define limits of y-axis (none defined for this set of figures.) if "`ylimsfix'" == "yes" { if "${vari}" == "logearn"{ local ymin = "" local ymax = "" local ydis = "" } if "${vari}" == "researn" { local ymin = "" local ymax = "" local ydis = "" } if "${vari}" == "permearn" { local ymin = "" local ymax = "" local ydis = "" } local ylbls = "" } *Define the color scheme local mcframe = "" local cframe = "" foreach co of local colors{ local cframe = "`cframe'"+" "+"`co'" local mcframe = "`mcframe'"+" "+"`co'*0.25" } local xtitlesize = "medium" // Size of xtitle font local ytitlesize = "medium" // Size of ytitle font local xlabsize = "medium" // Size of x-axis label local ylabsize = "medium" // Size of y-axis label local titlesize = "large" // Size of title font local subtitlesize = "medium" // Size of subtiotle font local formatfile = "pdf" // format of saved file local folderfile = "${folderfile}" // folder where the plot is saved local marksize = "medium" // Marker size local legesize = "medium" // Marker size *Calculating plot limits local it = 1 foreach vv of local varilist{ if `it' == 1{ qui: sum `vv' local upt = r(min) local ipt = r(max) local opt1 = "`upt'" local opt2 = "`ipt'" local it = 0 } else{ qui: sum `vv' local upt = r(min) local ipt = r(max) local opt1 = "`opt1',`upt'" local opt2 = "`opt2',`ipt'" local it = 2 } } if `it' == 0 { local rmin = `upt' local rmax = `ipt' } else{ local rmin = min(`opt1') local rmax = max(`opt2') } local ymin1 : di %4.2f round(`rmin'*(0.9),0.1) local ymax1 : di %4.2f round(`rmax'*(1+0.1),0.1) local ydis1 = (`ymax1' - `ymin1')/5 if "`combinepdf'" == "no"{ *Without dashed line* tw (bar rece year if `timevar' >= `xmin' & `timevar' <= `xmax', ylabel(,nogrid axis(1)) c(l) color(gray*0.5) yscale(off)) /// (connected `varilist' `timevar' if `timevar' >= `xmin' & `timevar' <= `xmax', /// Plot lcolor(`cframe') /// Line color lpattern(solid longdash dash dash_dot solid longdash dash dash_dot solid longdash dash dash_dot) /// Line pattern msymbol(`labsym') /// Marker msize("`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" ) /// Marker size mfcolor(`mcframe') /// Fill color mlcolor(`cframe') /// Marker line color yaxis(2) yscale(alt axis(2)) ytitle(`ytitle', axis(2) size(`ytitlesize')) ylabel(`ylbls', labsize(`ylabsize') grid axis(2))) /// , /// yaxis optins xtitle("") xtitle(`xtitle',size(`xtitlesize')) xlabel(`xmin'(`xdis')`xmax',grid labsize(`xlabsize')) /// xaxis options legend(`lgactive' size(`legesize') col(`cols') symxsize(7.0) ring(0) position(`posi') /// order(2 "`lab1'" 3 "`lab2'" 4 "`lab3'" 5 "`lab4'" 6 "`lab5'" 7 "`lab6'" 8 "`lab7'" 9 "`lab8'" 10 "`lab9'") /// region(color(none) lcolor(white))) graphregion(color(white)) /// Legend options graphregion(color(white) ) /// Graph region define plotregion(lcolor(black)) /// Plot regione define title(`title', color(black) size(`titlesize')) subtitle(`subtitle', color(black) size(`subtitlesize')) // Title and subtitle graph export `folderfile'/`namefile'.`formatfile', replace } if "`combinepdf'" == "yes"{ *Without dashed line* tw (bar rece year if `timevar' >= `xmin' & `timevar' <= `xmax', ylabel(,nogrid axis(1)) c(l) color(gray*0.5) yscale(off)) /// (connected `varilist' `timevar' if `timevar' >= `xmin' & `timevar' <= `xmax', /// Plot lcolor(`cframe') /// Line color lpattern(solid longdash dash dash_dot solid longdash dash dash_dot solid longdash dash dash_dot) /// Line pattern msymbol(`labsym') /// Marker msize("`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" "`marksize'" ) /// Marker size mfcolor(`mcframe') /// Fill color mlcolor(`cframe') /// Marker line color yaxis(2) yscale(alt axis(2)) ytitle(`ytitle', axis(2) size(`ytitlesize')) ylabel(`ylbls', labsize(`ylabsize') grid axis(2))) /// , /// yaxis optins xtitle("") xtitle(`xtitle',size(`xtitlesize')) xlabel(`xmin'(`xdis')`xmax',grid labsize(`xlabsize')) /// xaxis options legend(`lgactive' size(`legesize') col(`cols') symxsize(7.0) ring(0) position(`posi') /// order(2 "`lab1'" 3 "`lab2'" 4 "`lab3'" 5 "`lab4'" 6 "`lab5'" 7 "`lab6'" 8 "`lab7'" 9 "`lab8'" 10 "`lab9'") /// region(color(none) lcolor(white))) graphregion(color(white)) /// Legend options graphregion(color(white) ) /// Graph region define plotregion(lcolor(black)) /// Plot regione define title(`title', color(black) size(`titlesize')) subtitle(`subtitle', color(black) size(`subtitlesize')) // Title and subtitle graph export `folderfile'/`namefile'.png, replace } local figname = "`figname'" + " " + "`namefile'" } // END OF VARIABLE LOOP } // END OF SUBGROUP LOOP if "`combinepdf'" == "yes" { putpdf begin, land margin(all, 0cm) foreach fig of local figname { putpdf paragraph, halign(center) putpdf image `folderfile'/`fig'.png putpdf pagebreak erase `folderfile'/`fig'.png } putpdf save `folderfile'/figure2a_normalized.pdf, replace nomsg }