Statalist The Stata Listserver


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

Re: st: Graph Title Loop


From   Friedrich Huebler <[email protected]>
To   [email protected]
Subject   Re: st: Graph Title Loop
Date   Mon, 25 Dec 2006 08:25:58 -0800 (PST)

Cigdem,

You don't need the -forvalues- loop. Instead add a counter to the
-foreach- loop. Because you combine a -forvalues- and -foreach- loop
your 5 -graph twoway- commands are executed 188*188 times.

levels country, local(countries)
local i = 1
foreach c of local countries {
  graph twoway (line gr_pwt_gdp yr if country=="`c'", title("`c'"))
  graph save `i'_1.gph
  ...
  local i = `i' + 1
}

Incidentally, there are some mistakes in the code you cite, e.g.
"forvalues i=3D1/188" or "id=3D=3D2", probably caused by copying and
pasting Turkish text.

Friedrich

--- cigdem akin <[email protected]> wrote:
> I would like to ask a question about adding country name to the
> title for graphing 188 countries.
> 
> I would like to generate 5 graphs for each country. In total there
> will be 188*5 graphs.
> 
> I would like to print 20 graphs at a time on one page. That is 4
> countries with 5 graphs per country.
> 
> I have used the folllowing code to generate the graphs:
> 
> 
> forvalues i=3D1/188 {
> 
> levels country, local(countries)
> 
> foreach c of local countries {
> graph twoway (line gr_pwt_gdp yr if country=3D=3D"`c'",
> title("`c'"))
> 
> graph save `i'_1.gph
> 
> graph twoway (line gr_pwt_pc_gdp yr if country=3D=3D"`c'",
> title("`c'"))
> 
> graph save `i'_2.gph
> 
> graph twoway (line gr_pwt_cons yr if country=3D=3D"`c'",
> title("`c'"))
> 
> graph save `i'_3.gph
> 
> graph twoway (line gr_pwt_pc_cons yr if country=3D=3D"`c'",
> title("`c'"))
> 
> graph save `i'_4.gph
> 
> graph twoway (line gr_pwt_pc_gov yr if country=3D=3D"`c'",
> title("`c'"))
> 
> graph save `i'_5.gph
> 
> }
> }

> 
> The problem is I would like to give country id number when saving
> each
> graph. Subindex refers to the type of graph. However this program
> does not
> achieve this. It saves everything as 1_1.gph 1_2.gph 1_3.gph,
> 1_4.gph 1_5 etc.
> 
> Basically it takes the first id and then generates 188 graphs with
> countryname titles and then for the next step, goes to id=3D=3D2
> and redoes the same thing.
> 
> Instead if I type `c'_1.gph etc. It adds countryname. However it
> will not be
> possible for me in the next program I wrote to combine the graphs
> in the way I want without the country id code.
> 
> How can I make sure that I can add country id number in saving the
> particular graph?
> 
> Thank you very much.
> 
> Cigdem Akin
> 
> George Washington University


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
*
*   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