[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: legend in -twoway line- |

Date |
Tue, 2 Mar 2004 12:39:05 -0000 |

I am not clear where you want these legend labels to come from. -separate- picks up the value labels of each variable; don't they end in the legend? Nick n.j.cox@durham.ac.uk > -----Original Message----- > From: owner-statalist@hsphsun2.harvard.edu > [mailto:owner-statalist@hsphsun2.harvard.edu]On Behalf Of Sascha O. > Becker > Sent: 02 March 2004 12:30 > To: statalist@hsphsun2.harvard.edu > Subject: st: legend in -twoway line- > > > Dear Nick, > > thanks for your very helpful suggestion on -separate- and -labutil- ! > > One thing I was not able to resolve, though, is how to get the legend > labels "automated". The way I understand the -legend- option > in -twoway > line- is that the -legend- option only allows to change > labels one by one, so it does not seem to be possible to attach > pre-defined labels as if it were value labels. > > One has to specify the legend with each single label in brackets > (e.g. legend(label (1 "Employees") (2 "Self-Employed") ) > which does not seem to lend itself to sdavemthing like > > legend(mylabel) > > where mylabel is a "standard" value label > > Is there a workaround for this as well? > > Cheers, Sascha > > > Date: Mon, 1 Mar 2004 13:23:39 -0000 > > From: "Nick Cox" <n.j.cox@durham.ac.uk> > > Subject: st: RE: looping over a series of line plots > > > > Something like this may help. In this > > - -labnoeq- is in -labutil- on SSC. > > > > foreach v of var <whatever> { > > preserve > > collapse `v', by(year occ) > > separate `v', by(occ) short > > local vars "`r(varlist)'" > > labnoeq `vars' > > local vlabel "`:variable label `v''" > > > > twoway line `vars' year, /// > > xtitle("Year") ytitle(`vlabel') /// > > title("`vlabel'-type of occupation") > > restore > > } > > > > > > Nick > > n.j.cox@durham.ac.uk > > > > Sascha O. Becker > > > >>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. > > * > * 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/ > * * 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/

**Follow-Ups**:**st: Graph question***From:*Javier Bacarreza <superpiti@yahoo.com>

- Prev by Date:
**RE: st: On the analysis of intraday data** - Next by Date:
**st: -collapse-** - Previous by thread:
**st: Difficult ML** - Next by thread:
**st: Graph question** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |