Statalist The Stata Listserver


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

Re: st: looping over parallel lists - is there a alternative to "for"?


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: looping over parallel lists - is there a alternative to "for"?
Date   Thu, 16 Mar 2006 12:59:47 +0100

Gawrich Stefan wrote:
> I do a lot of routine or repetitive data analysis and use loops and lists
> frequently (btw, thx to Nick Cox, his "How to fact lists with fortitude"
> helped me a lot).
>
> I'm wondering why the "for"-command is officialy out of date in Stata while
> one of it's best features  - the use of parallel lists - can't be done
> otherwise. Or am I missing something?
>
> One example: I routinely map ten different diseases with tmap and save the
> maps as a graphic file.
>
> for var var1-var10 \ any "Disease1" "Disease2" [...] \ any "Filename1"
> "Filename2" [...] : ///
> tmap choro X, id(county) map("county-Coordinates.dta") title("Y") \ graph
> export "Z.png", replace

Do we really need a parallel list here?

forv i = 1/10 {
	tmap choro var`i', id(county) title("Disease `i'")
	graph export "`i++'.png", replace
}

Or, how do you like:

local i 1
foreach var of varlist firstvar-lastvar {
	tmap choro `var', id(county) title("`:var label `var''")
	graph export "`i++'.png", replace
}


-- 
[email protected]
+49 (030) 25491-361
*
*   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