Rio, Martin
> I am writing a code on stata 8 intecooled (win2k), and am
> running into what
> I guess is a syntax problem.
> As soon as the code gets to the loop below, it returns :
> *yb1 invalid name
> r(198);
>
> Te loop is:
>
> while `i' <= `timeunits' {
> scalar factor = 10^(`timeunits' - `i')
> replace string = string+(`factor'*y`i')
> local i = `i' + 1
> }
>
> I think the syntax error is in the way I try to multiply
> each variable (y1,
> y2, ..., y`timeunits') by the corresponding factor. The way
> I am setting it
> up seems consistent with other Stata commands that I have
> used, but I am no
> an expert on Stata syntax. I'd appreciate if someone could
> point out my error?
`factor' is, it seems, a local macro which you
never defined. So Stata sees
replace string = string + (*y1)
which is illegal.
The scalar -factor- and any local macro `factor'
are completely unrelated.
You may have meant something like
tempname factor
...
while `i' <= `timeunits' {
scalar `factor' = 10^(`timeunits' - `i')
replace string = string+(`factor'*y`i')
local i = `i' + 1
}
except that the more modern way to do it is
forval i = 1/`timeunits' {
scalar `factor' = 10^(`timeunits' - `i'))
replace string = string + (`factor' * y`i')
}
where I've guessed that the loop starts at 1.
By the way, is your -string- a _numeric_ variable?
Nick
n.j.cox@durham.ac.uk
*
* 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/