Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: foreach


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: foreach
Date   Fri, 27 Oct 2006 15:34:04 +0100

Juanita is almost right. However, the alternative
is no alternative. The whole point about -of- is
that it signals to -foreach- that some smartness
will be needed: in this example, to treat the 
varlist as such. -in- by contrast signals that 
what follows is to be taken literally. The loop
will choke on 

p03a01a-p03a01m 

which will _not_ be expanded as desired. It
will be treated -- in context -- as if it were
a single varname, which it is not. 

Nick 
[email protected] 

Riano, Juanita
 
> I think the problem with the varlist is that you need to use "of"
> instead of "in" :
> 
> Replace:
> foreach var in varlist p03a01 p03a01a-p03a01m 
> 
> With:
> foreach var of varlist p03a01 p03a01a-p03a01m 
> 
> Or alternatively use
> 
> foreach x in p03a01 p03a01a-p03a01m

*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index