Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Looping graph and changing title


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Looping graph and changing title
Date   Wed, 24 Aug 2005 15:26:21 +0100

A cleaner way: 

gen safe_copy = trim(country_name) 
levelsof safe_copy, local(countries) 

foreach c of local countries { 
      noi di " `c' "
	twoway (line exp_lblended mktdate if safe_copy == "`c'") , 
		title(" `c' ")
} 

Nick 
n.j.cox@durham.ac.uk 

Nick Cox 

> I'd write this as follows. Perhaps 
> you might like to test it. 
> 
> gen long id = _n 
> egen series = group(country_codeifs)
> su series, meanonly 
> 
> forval x = 1/`=r(max)' {
> 	su id if series == `x', meanonly 
> 	local c = trim(country_name[`=r(min)']) 
>       noi di " `c' "
> 	twoway (line exp_lblended mktdate if series == `x') , 
> title(" `c' ")
> } 
 
Jorge Morgenstern
  
> > I'm having a similar (but not exactly equal) problem to the 
> > one Rafa Hoyos 
> > had a few days ago, but the resolution doesn't apply to me. I 
> > want a graph 
> > for each category (each country) in my dataset. I then 
> > generate the variable 
> > series and loop up to its maximum.
> > What's really odd it's that, if I disable the twoway command, 
> > the list of 
> > countries displays correctly. If I enable it, only the first 
> > country is 
> > displayed, and only the first graph shows the title. The 
> rest of the 
> > iterations generate an empty display line and an empty titled graph.
> > Regards, thanks for helping.
> > Jorge.
> > 
> > egen series=group(country_codeifs)
> > quietly tab series
> > local cant=r(r)
> > forval x=1/`cant' {
> >     local c= trim(country_name[r(N)/r(r)*`x'])  *****this 
> > inputs the first 
> > record of each category to the title variable
> >     noi di " `c' "
> >     twoway (line exp_lblended mktdate if series==`x') , 
> title(" `c' ")
> > } 

*
*   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/



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