// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // 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" 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 2B - NORMALIZED MEASURES * *=============================================* This file produces normalized 90--50 and 50--10 percentile differences for permanent earnings, log earnings, and residual earnings over time. 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: np9505${vari}, np9050${vari}, np5010${vari}, where vari belongs to {permearn,logearn,researn}. To modify plot variables one must adjust the local varilist = "p9050$vari p5010$vari" on line 157. */ * 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 102) 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 p9505${vari} = p95${vari} - p5${vari} gen p9050${vari} = p90${vari} - p50${vari} gen p5010${vari} = p50${vari} - p10${vari} * Rescale by first year foreach vv in p9505$vari p9050${vari} p5010${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 = "np9050$vari np5010$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 = "P90-P50" local lab2 = "P50-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 = "fig2B_`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'/figure2b_normalized.pdf, replace nomsg }