Trying to produce a graph from already a coding file that is available online and it certainly is reproducible but somehow I'm having the problem error like the following. any suggestions please?
35. graph export `"employed_`yr'.png"', width(1024) replace
36. graph drop _all
37. }
( is not a valid command name
r(199);
----------------------- copy starting from the next line -----------------------
[CODE]
* Example generated by -dataex-. For more info, type help dataex
clear
input int year float(employed pct_employed) byte(sex age)
1996 .3872871 38.72871 1 18
1996 .3816296 38.16296 2 18
1996 .4836962 48.36962 1 19
1996 .4296204 42.96204 2 19
1996 .53107786 53.10779 1 20
1996 .4443613 44.43613 2 20
1998 .5453635 54.53635 1 21
1998 .42638135 42.63813 2 21
1998 .5508977 55.08977 1 22
1998 .42666095 42.6661 2 22
1998 .55386233 55.38623 1 23
1998 .24216937 24.216936 1 63
1999 .16501196 16.501196 2 63
1999 .2057684 20.57684 1 64
1999 .1595816 15.95816 2 64
1999 .1625402 16.25402 1 65
1999 .1262957 12.62957 2 65
1999 .17879164 17.879164 1 66
1999 .1136752 11.36752 2 66
1999 .12712555 12.712555 1 67
1999 .09668726 9.668727 2 67
****************** CODE **********************
*************************************************
label define percentage "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%" ///
60 "60%" 70 "70%" 80 "80%" 90 "90%" 100 "100%"
/* Initialize locals to store all of the graphs, by gender */
local graphs_men = ""
local graphs_women = ""
/* Get all values of sample years */
levelsof year, local(years)
/* Loop through all years */
foreach yr of local years{
/* Graph men and women separately, making sure that y axis range is the same
for all graphs. I specify these ranges manually here, as well as the
placement of the year.
These are copied from the married code, except that I expanded Y value
ranges to 100.
*/
graph twoway `graphs_men'
(line pct_employed age if year==`yr' & sex==1, lcolor(`"24 105 109"')),
yscale(r(0 100))
ylabel(0(10)100, valuelabels)
xtitle("")
xscale(r(18 64))
ytitle("")
xlabel(20(5)60)
plotregion(margin(zero))
text(15 55 `"`yr'"', size(large))
name(employed_men_`yr', replace)
subtitle(`"Percentage of men employed, by age"', justification(left) margin(b+1 t-1) bexpand)
nodraw
graph twoway `graphs_women'
(line pct_employed age if year==`yr' & sex==2, lcolor(`"219 112 41"')),
yscale(r(0 100))
ylabel(0(10)100, valuelabels)
xtitle("")
xscale(r(18 64))
ytitle("")
xlabel(20(5)60)
plotregion(margin(zero))
text(15 55 `"`yr'"', size(large))
name(employed_women_`yr', replace)
subtitle(`"Percentage of women employed, by age"', justification(left) margin(b+1 t-1) bexpand)
nodraw
/* Add all previous lines to each graph, at 10% opacity. */
local graphs_men = `"`graphs_men'"' + `" (line pct_employed age if year==`yr' & sex==1, lcolor(`"24 105 109%10"'))"';
local graphs_women = `"`graphs_women'"' + `" (line pct_employed age if year==`yr' & sex==2, lcolor(`"219 112 41%10"'))"'
/* Combine graphs and export at a resolution that twitter will accept
once converted to a .gif (without having to mess with resizing). */
graph combine employed_men_`yr' employed_women_`yr',
rows(1)
note(`"Source: Civilian, non-institutional American population from 1968-2020 IPUMS CPS ASEC samples (cps.ipums.org), @graykimbrough"')
xsize(10) ysize(5) iscale(*1.3)
name(combined_employed_`yr', replace)
graph export `"employed_`yr'.png"', width(1024) replace
graph drop _all
}
0 Response to Graphing problem with data for employment
Post a Comment