Statalist The Stata Listserver


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

RE: st: Forvalues & foreach


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: Forvalues & foreach
Date   Fri, 10 Feb 2006 10:18:34 -0000

It doesn't work because it is illegal. 
Look at the on-line help again. 

You can go 

forval i = 2/3 { 
	local min_int "5 10" 
	foreach x of local min_int { 
		...
	}
} 

or you can go 

forval i = 2/3 { 
	foreach x in 5 10 { 
		...
	}
} 

but what you have is neither one thing nor
the other. 

Nick 
[email protected] 

Mosca, Ilaria
 
> I just tried, but even this does not seem to work. 
> 
>  forvalues i=2/3 {
>            local min_int "5 10"
>            foreach x of min_int {
>            gen extratime1`i'=time<=`x'
>            gen extratimepop1`i'= extratime1`i'*popperc
>            bys category: table extratimepop1`i',c(sum popperc)
>            }
>  }
> 
> Now I get the following message:
> 
> invalid syntax
> r(198);
> 

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