I'm not clear, but I guess wildly that you're feeding
something too big to -foreach-. That's a pretty empty
statement as it is clear that Stata can't see your {.
In addition, I note that my last advice to you
on Statalist was
====================== 24 October 2005
Also I guess wildly that your data structure is quite
the wrong way round to do much easily in Stata. Solve
this problem, and other problems will be just as messy.
Consider reshaping to panel data structure, and much
may be a lot easier.
======================
and I repeat that advice, which just echoes standard
Stata wisdom in this territory.
More positively, I would be amazed if you really need
to write code like this. The wildcard
lcq?y????
may well serve to catch all the first set of variables, and no
others. So then it might be
foreach x of var lcq?y???? {
local d : subinstr local x "lc" "dol"
gen ratio`x'=lc`x'/dol`x'
}
but it still looks scary to me.
Nick
[email protected]
Terra Curtis
> I am trying to run a foreach loop but I keep getting an error which is
> puzzling me. My code is below, with the error:
>
> Code:
> foreach x in "q1y1989" "q2y1989" "q3y1989" "q4y1989"
> "q1y1990" "q2y1990"
> "q3y1990" "q4y1990" "q1y1991" "q2y1991" "q3y1991" "q4y1991" "q1y1992"
> "q2y1992" "q3y1992" "q4y1992" "q1y1993" "q2y1993" "q3y1993" "q4y1993"
> "q1y1994" "q2y1994" "q3y1994" "q4y1994" "q1y1995" "q2y1995" "q3y1995"
> "q4y1995" "q1y1996" "q2y1996" "q3y1996" "q4y1996" "q1y1997" "q2y1997"
> "q3y1997" "q4y1997" "q1y1998" "q2y1998" "q3y1999" "q4y1999" "q1y2000"
> "q2y2001" "q3y2001" "q4y2001" "q1y2002" "q2y2002" "q3y2002" "q4y2002"
> "q1y2003" "q2y2003" "q3y2003" "q4y2003" "q1y2004" q2y2004" "q3y2004"
> "q4y2004" "q1y2005" "q2y2005" {
> gen ratio`x'=lc`x'/dol`x'
> }
>
> Error:
> { required
> r(100);
>
> end of do-file
> r(100);
>
> In my do-file the "foreach x in ..." line is all one line.
> And as you can
> see I have included the "{". Can anyone spot the error?
>
*
* 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/