I am a bit new to loops and having a trouble with creating and exporting multiple graphs using one.
My panel data set contains some information of 163 countries covering years 1990-2011 and looks something like:
************************************************** *******************
country year s t ID
US 1990 s1 t1 [s & t are numeric] 1
US 1991 s2 t2 1
US .... ..... ...... 1
UK 1990 ...... ...... 2
UK .... ...... .... 2
...... .... ...... .... .....
************************************************** ********************
I'd like to create scatterplots with the individual country name as the title and export them with the ID number as the name of the png file. It's important for me that the names of the png files are in a simple numeric form because it's much easier to work with this way (Eventually I want to use Tex to compile all of them so I can have a single PDF containing all the graph files).
************************************************** *****************************
levels id
foreach i of num 1/163 {
twoway (scatter t year if id==`i', msize(small) mcolor(gold) connect(l) clwidth(thin) clcolor(gold) sort ) ///
(scatter s year if id==`i', connect(l) clwidth(thin) clcolor(navy) clpattern(shortdash) msize(small) mcolor(navy) sort), xtick(1990 (1) 2011) ylabel(-0.3 1.8) ///
title(country)
graph export "$dsav/`i'.png", replace
}
************************************************** ******************************
I know the graph title line is not correct. How do I tell Stat to go over all 163 countries and then name and export files the way I specified earlier? Should I use a loop within a loop?
Thanks for your help in advance!
My panel data set contains some information of 163 countries covering years 1990-2011 and looks something like:
************************************************** *******************
country year s t ID
US 1990 s1 t1 [s & t are numeric] 1
US 1991 s2 t2 1
US .... ..... ...... 1
UK 1990 ...... ...... 2
UK .... ...... .... 2
...... .... ...... .... .....
************************************************** ********************
I'd like to create scatterplots with the individual country name as the title and export them with the ID number as the name of the png file. It's important for me that the names of the png files are in a simple numeric form because it's much easier to work with this way (Eventually I want to use Tex to compile all of them so I can have a single PDF containing all the graph files).
************************************************** *****************************
levels id
foreach i of num 1/163 {
twoway (scatter t year if id==`i', msize(small) mcolor(gold) connect(l) clwidth(thin) clcolor(gold) sort ) ///
(scatter s year if id==`i', connect(l) clwidth(thin) clcolor(navy) clpattern(shortdash) msize(small) mcolor(navy) sort), xtick(1990 (1) 2011) ylabel(-0.3 1.8) ///
title(country)
graph export "$dsav/`i'.png", replace
}
************************************************** ******************************
I know the graph title line is not correct. How do I tell Stat to go over all 163 countries and then name and export files the way I specified earlier? Should I use a loop within a loop?
Thanks for your help in advance!
Comment