Statalist The Stata Listserver

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

st: RE: RE: foreach

From   "Nick Cox" <>
To   <>
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 


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


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:

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