Statalist


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

st: RE: Re: Re: using by with graph


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: Re: using by with graph
Date   Thu, 13 Dec 2007 13:59:47 -0000

Unless you are working with Stata 6 or earlier, -forval- is easier than 
-while- here, and indeed almost everywhere else. 

Steven's code could thus go 

forval i=1/100 {
	scatter data301 time if countrygroup==`i'
	graph export group`i'.tif, replace
}

In terms of the original question, rather more 
general approaches to looping over groups are indicated in 

FAQ    Making foreach go through all values of a variable
8/05   Is there a way to tell Stata to try all values of a
       particular variable in a foreach statement without
       specifying them?
http://www.stata.com/support/faqs/data/foreach.html

Nick
[email protected] 

Steven Proud

Depending on how your countrygroups are defined, I've assumed that
they're 1 
to 100 for instance.

local i=1
while `i'<=100 {
scatter data301 time if countrygroup==`i'
graph export group`i'.tif, replace
local i=`i'+1
}

This saves a graph as a tif file for all 100 country groups.


Daniel Wilde

> I have a panel dataset. I want to create simple graphs for each unit 
> (called countrygroup) across time. Initially I tried -
>
> by countrygroup: scatter data301 time
>
> But Stata tells me by does not work with scatter. I then tried
>
> scatter data301 time, by countrygroup
>
> This works but Stata puts all the graphs on one page. There are over
100 
> of them so they are too small to be useful. Is there anyway I can see
each 
> graph on its own page? Or save them individually. Is there a command
for 
> this. I know I could use the if function but this seems time
consuming.
>
> P.S (I am using Stata version 8.2)

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index