Statalist The Stata Listserver


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

st: Foreach??


From   "Raphael Fraser" <[email protected]>
To   [email protected]
Subject   st: Foreach??
Date   Mon, 23 Oct 2006 17:00:26 -0500

I have 12 variables I7-Q7. I would like to run the following code for
each variable in the varlist and save the result d1, d2,  ..., d12.
However, it appears that the macro i is not being incremented. Does
any body know why?

My thought is each time foreach loops over a variable the macro i
should be incremented.

foreach var of varlist I7-Q7 {
	use edata, clear
	keep if `var' == 1
	bysort id (dov): gen etime = dov - dov[_n-1]
	keep if etime > 14
	drop etime
	local i = 1
	save d`i', replace
	local ++i
}

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