Statalist The Stata Listserver


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

st: RE: Program and local macro


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Program and local macro
Date   Tue, 29 Aug 2006 15:19:20 +0100

The key is in what can go as ... in 

forval i = ... { 

}

Your second solution is almost there: 

forvalues i=2/4 {
	forvalues j=1/`= nb_exam[`i']' {
		dis nb_exam[`j'] 
	}
}

A longer version might be clearer: 

forvalues i=2/4 {
	local J = nb_exam[`i'] 
	forvalues j=1/`J' {
		dis nb_exam[`j'] 
	}
}



Nick 
[email protected] 

[email protected]
 
> I don't understand why this syntax is invalid
> 
>  forvalues i=2/4 {
>   2. forvalues j=1/nb_exam[`i'] {
>   3. dis nb_exam[`j'] 
>   4. }
>   5. }
> invalid syntax
> 
> I have tried 
> 
>  forvalues i=2/4 {
>   2. forvalues j=1/`nb_exam[`i']' {
>   3. dis nb_exam[`j'] 
>   4. }
>   5. }
> invalid syntax
> 
> It's not better.

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