// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // 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" // 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 1B (NORMALIZED TOP PERCENTILES) * *====================================================* This file produces changes in upper percentiles of income 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. NOTE: - 99.9 percentile is not available to be plotted for women as the sample sizes did not meet the vetting requirements at Statistics Canada. SUBGROUPS: - ALL (all) - MEN (male) - WOMEN (fem) - Note: a few statistics (e.g., 99.99 percentiles) are unavailable for women due to small samples VARIABLE LIST: - permearn - logearn - researn */ * 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" * CHOOSE WHICH PERCENTILES YOU WANT TO INCLUDE IN EACH PLOT: p1 p2_5 p5 p10 p12_5 p25 p37_5 p50 p62_5 p75 p87_5 p90 p95 p97_5 p99 p99_9 p99_99 (up to 9 percentiles per figure) local p_list = "p99_99 p99_9 p99 p95 p90" * DEFINE COLOURS TO BE USED IN PLOTS local colors = "blue green red navy black maroon forest_green purple gray orange" * DEFINE MARKER SYMBOLS local labsym = "O + S x D" * CHOOSE IF THE LIMITS FOR THE Y-AXIS ARE FIXED FOR POPULATION GROUPS: yes no local ylimsfix = "yes" * 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} } * Rescale by first year foreach vv in p1$vari p2_5$vari p5$vari p10$vari p12_5$vari p25$vari /// p37_5$vari p50$vari p62_5$vari p75$vari p87_5$vari p90$vari p95$vari /// p97_5$vari p99$vari p99_9$vari p99_99$vari { sum `vv' if year == `lyear', meanonly gen n`vv' = `vv' - r(mean) } *Generate recession vars gen rece = inlist(year,${receyears}) graph set window fontface "${fontface}" *Define which variables are plotted local varilist = "" foreach perc of local p_list{ local varilist = "`varilist'"+" "+"n`perc'$vari" } *Defime the time variable local timevar = "year" *Define limits of x-axis local xmin = "`lyear'" local xmax = "`ryear'" local xdis = 3 *Define labels *Define labels local n_perc : word count `p_list' forval i=1/`n_perc' { local lab`i' = "`: word `i' of `p_list''" } * Define number of columns and position of legend local cols = "1" local posi = "11" *Define Title, Subtitle, and axis labels local xtitle = "" local ytitle = "Percentiles Relative to `lyear'" local title = "Changes in percentiles of `labtitle' for Sample: `labname'" local subtitle = "" *Define name and output file local namefile = "fig1B_`subgp'_${vari}" *Define limits of y-axis if "`ylimsfix'" == "yes" { if "${vari}" == "logearn"{ local ymin = -0.1 local ymax = 1.5 local ydis = 0.2 } if "${vari}" == "researn" { local ymin = -.1 local ymax = 1.3 local ydis = 0.2 } if "${vari}" == "permearn" { local ymin = 0 local ymax = 1.2 local ydis = 0.2 } local ylbls = "`ymin'(`ydis')`ymax'" } else { 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 whether the legend is active or no local lgactive = "on" *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 = "${xtitlesize}" // Size of xtitle font local ytitlesize = "${ytitlesize}" // Size of ytitle font local xlabsize = "${xlabsize}" // Size of x-axis label local ylabsize = "${ylabsize}" // Size of y-axis label local titlesize = "${titlesize}" // Size of title font local subtitlesize = "${subtitlesize}" // Size of subtiotle font local formatfile = "${formatfile}" // format of saved file local folderfile = "${folderfile}" // folder where the plot is saved local marksize = "${marksize}" // Marker size local legesize = "${legesize}" // 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'/figure1b.pdf, replace nomsg }