From | Richard Williams <[email protected]> |
To | [email protected] |
Subject | Re: st: syntax error in forvalues range definition using a tempvar?? |
Date | Sat, 16 Jul 2005 21:50:57 -0500 |
At 05:00 PM 7/16/2005 -0700, Brian R. Sala wrote:
Can someone enlighten me on this syntax error, please.Actually, `maxn' is a variable and hence every case has a value for it. All cases may have the same value on the variable, but it is still a variable. forvalues doesn't like you specifying a variable here, it wants a single number.
why does this fail:
. tempvar maxn
. egen byte `maxn' = max(assignment_count)
. tab `maxn'
__000001 | Freq. Percent Cum.
------------+-----------------------------------
4 | 20,299 100.00 100.00
------------+-----------------------------------
Total | 20,299 100.00
. forvalues i = 1/`maxn' {
2. di `i'
3. }
invalid syntax
r(198);
clearly, `maxn' has a value. Superficially, this looks equivalent to the syntax shown in the STATA 8 programming manual (pp. 206-207).
Here, `maxn' is a constant and not a variable; what the local statement has done is set it equal to the value the first case has on `max_assignments'. Since every case has the same value on `max_assignments' you are fine, but if `max_assignments' had different values you could be in trouble if the first case didn't have the value you want.yet when I do this: . tempvar max_assignments . egen byte `max_assignments' = max(assignment_count) . local maxn = `max_assignments' . forvalues i = 1/`maxn' { 2. display `i' 3. } 1 2 3 4
© Copyright 1996–2024 StataCorp LLC | Terms of use | Privacy | Contact us | What's new | Site index |