Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: foreach command with multiple varlists

From   Fatma Romeh <>
To   "" <>
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,


*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index