I think your problem could be fixed by omitting the quotes around the
word factor in the replace line. I made some fake data containing random
number (y1-y10 and string) and ran the following loop that worked.
In general, scalars do not need quotes around them.
local i=1
while `i' <= `timeunits' {
scalar factor = 10^(`timeunits' - `i')
replace string = string+(factor*y`i')
local i = `i' + 1
}
On Tue, 26 Aug 2003, Rio, Martin wrote:
> 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?
>
> Thanks
>
> Mart�n Rio
> Charles River Associates
> Washington, DC
> phone: (202) 662-3957
> fax: (202) 662-3910
>
>
> *
> * 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/
>
_______________________________________________________________________________
Dimitriy V. Masterov
Work:
Center for Social Program Evaluation
1155 East 60th St. Room 038
Chicago, IL 60637
Work: (773)256-6005
Fax: (773)256-6313
Home:
1312 East 53rd St., Apt.309
Chicago, IL 60615
Mobile: (773)220-2760
*
* 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/