Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: foreach command with multiple varlists
From
Fatma Romeh <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: foreach command with multiple varlists
Date
Thu, 28 Mar 2013 20:26:13 +0000
Dear statalist,
I have a question regarding the "foreach" command. I'm wondering whether I can use multiple valists with "foreach"? More specifically, I'm looking for something like that:
foreach x of varlist x1-x4 & y of varlist y1-y4 & z of varlist z1-z4 {
gen w= `x' if `y'==2 & `z'==1
}
when I did that, I got this error message: "& invalid name". What I want to do is to use the "foreach" command to replace these commands:
gen w= x1 if y1==2 & z1==1
gen w= x2 if y2==2 & z2==1
gen w= x3 if y3==2 & z3==1
gen w= x4 if y4==2 & z4==1
Is there a way to do that?
Many thanks,
Fatma,
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/