Dear statalisters,
I have micro data on individuals and the following variables:
different wage and income measures, working status (3 categories) and
year I and would like to plot trends in all of those wage and income
measures across occupations and produce simple line plots.
Since I want to produce a whole series of similar plots, I was
looking for a smart way to save on code but I got stuck.
Here is what I do to produce a single graph (my question follows below
the code):
******* BEGIN OF CODE
collapse wage, by(year occ);
g wageocc1=wage if occ==1;
g wageocc2=wage if occ==2;
g wageocc3=wage if occ==3;
collapse (sum) wageocc*, by(year);
list;
twoway line wageocc* year,
xtitle("Year")
ytitle("Hourly Wage")
title("Hourly Wage by type of occupation")
legend(label (1 "Employees") (2 "Self-Employed") (3 "Not
employed");
******* END OF CODE
My question is how I might automatize a whole series of graphs.
Here is what I thought I could do:
+++++++++++
foreach var in varlist {
collapse `varname', by(year occ);
...
...
twoway line `varname'occ* year,
xtitle("Year")
ytitle(-variable label-) <<------- Here I would like to have
the variable label of that variable which I currently loop about
title(-variable label-"type of occupation") <<------- Here I
would like to have the variable label
of that variable which I currently looped about
legend(label (1 "Employees") (2 "Self-Employed") (3 "Not
employed"); <<------- Here I would like to have the
VALUE
labels of the working
status/occupation variable, so
something like -legend (label occlabel)-
}
+++++++++++
However, it seems that I do not get this to work the way I want: e.g.
the -legend- option only allows to change
labels one by one, so it does not seem to be possible to attach
pre-defined labels.
Any suggestions if there is a work-around?
Best regards, Sascha Becker
--
Dr. Sascha O. Becker
Center for Economic Studies
University of Munich
Schackstr. 4 - 80539 Munich, Germany
Tel +49 (89) 2180-6252 http://www.lmu.de
Fax +49 (89) 39 73 03 [email protected]
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/