set more off clear all cls // Directory setup 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 Volatility data is stored (do not modify) gl voladata = "Volatility_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" // Some common charactristics of the plots 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" *=============================================================================== /* *=======================* * 3. Volatility Figures * *=======================* ------------------------------------------------------------ fig4 This file produces figures for the evolution of annual earnings volatility as measured by the 90-10 and 50-10 percentile differences of annual (researn1F) and five-year (researn5F) growth in log earnings residuals. P90-P50, P50-P10 ------------------------------------------------------------- SUBGROUPS: - ALL (all) - MEN (male) - WOMEN (fem) VARIABLE LIST: - researn1F - researn5F */ * CHOOSE WHICH VARIABLES YOU WANT TO PLOT: researn1F researn5F local earn_meas_list = "researn1F researn5F" * CHOOSE WHICH POPULATION GROUPS YOU WANT TO MAKE PLOTS FOR: male fem all local subgroup = "male fem all" * CHOOSE THE COLORS: blue red navy blue maroon forest_green purple gray orange local colors = "blue red" * CHOOSE THE SYMBOLS: O S + x D 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" * COMBINE ALL FIGURES INTO A SINGLE PDF: no yes local combinepdf = "no" local figname = "" // (do not modify) *=============================================================================== foreach var of local earn_meas_list { foreach subgp of local subgroup { graph set window fontface "${fontface}" global vari = "`var'" *Read the data *What is the group under analysis? if "`subgp'" == "all"{ insheet using "$maindir/data/${voladata}/L_${vari}_sumstat.csv", case clear local labtitle2 = "All" } if "`subgp'" == "male"{ insheet using "$maindir/data/${voladata}/L_${vari}_male_sumstat.csv", case clear keep if male == 1 // Keep the group we want to plot local labtitle2 = "Men" } if "`subgp'" == "fem"{ insheet using "$maindir/data/${voladata}/L_${vari}_male_sumstat.csv", case clear keep if male == 0 // Keep the group we want to plot local labtitle2 = "Women" } gen p9050$vari = p90$vari - p50$vari gen p5010$vari = p50$vari - p10$vari *Define which variables are plotted local varilist = "p9050$vari p5010$vari" *Defime the time variable local timevar = "year" if "${vari}" == "researn1F"{ *What are the x-axis limits local lyear = ${yrfirst} local ryear = ${yrlast} *Define labels local labtitle = "{&Delta}{sup:1}{&epsilon}{sub:it}" *limits of y-axis if "`ylimsfix'" == "no"{ local ylimlo = "" local ylimup = "" local ylimdf = "" } if "`ylimsfix'" == "yes"{ local ylimlo = 0.2 local ylimup = 0.65 local ylimdf = 0.1 } } if "${vari}" == "researn5F"{ *What are the x-axis limits local lyear = ${yrfirst} + 3 local ryear = ${yrlast} - 2 replace year = year + 3 *Define labels local labtitle = "{&Delta}{sup:5}{&epsilon}{sub:it}" *limits of y-axis if "`ylimsfix'" == "no"{ local ylimlo = "" local ylimup = "" local ylimdf = "" } if "`ylimsfix'" == "yes"{ local ylimlo = 0.5 local ylimup = 0.95 local ylimdf = 0.1 } } *Define Title, Subtitle, and axis labels local xtitle = "" local ytitle = "Dispersion of `labtitle'" local title = "Measures of Dispersion of `labtitle' for Sample: `labtitle2'" local subtitle = "" *Define name and output file local namefile = "fig4_`subgp'_${vari}" *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 = "" *Limits of y-axis local ymin = "`ylimlo'" local ymax = "`ylimup'" local ydis = "`ylimdf'" if "`ymin'" == ""{ local ylbls = "" } else{ local ylbls = "`ymin'(`ydis')`ymax'" } *Define the color scheme local cframe = "" local mcframe = "" foreach co of local colors{ local cframe = "`cframe'"+" "+"`co'" local mcframe = "`mcframe'"+" "+"`co'*0.25" } *Some global defined local xtitlesize = "${xtitlesize}" // Size of xtitle font local ytitlesize = "${ytitlesize}" // Size of ytitle font local xlabsize = "${xlabsize}" local ylabsize = "${ylabsize}" 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 *What are the recession years gen rece = inlist(year,${receyears}) tsset year *Plot if "`combinepdf'" == "no"{ 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 cap noisily: graph export `folderfile'/`namefile'.`formatfile', replace } if "`combinepdf'" == "yes"{ 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 cap noisily: graph export `folderfile'/`namefile'.png, replace } local figname = "`figname'" + " " + "`namefile'" } } 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'/fig4.pdf, replace nomsg }