Can someone please explain to me why one cannot use scalars to define the
upper bound in a range of a forvalues loop. A forvalues loop with a local
works, a while loop with a scalar works, a while loop with a local works,
but not a forvalues loop with a scalar. There seems to be nothing in the
programming manual about this issue.
This is the code for the examples above:
tempname m1 m2
scalar `m1'=5
local `m2'=5
forvalues a=1(1)``m2'' {
di "`a'"
}
local a=1
while `a'<=``m2'' {
di "`a'"
local a=`a'+1
}
local a=1
while `a'<=`m1' {
di "`a'"
local a=`a'+1
}
forvalues a=1(1)`m1' {
di "`a'"
}
I am using Stata 8.2 SE with XP.