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: RE: new var from an old one if a third var has a certain value
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: new var from an old one if a third var has a certain value
Date
Mon, 24 Jan 2011 18:33:47 +0000
There is a very direct answer:
. gen var3 = var1 if var2 == whatever
You are also not far away from
. gen var3 = cond(var2 == whatever, var1, .)
Using -cond()- has no advantages for this problem -- except perhaps that some people might like it being explicit that missing is the value supplied when var2 != whatever.
However, watch out. Tests for equality are only reliable when <whatever> is an integer (or a string).
Nick
[email protected]
Caterina Astarita
I need to generate a new variable that have the values of an
old one if a third variable has a certain value, othewise a
missing value.
Let's say we have two variables var1 and var2, I would like to
generate a var3 that has the value of var1 but only if var2
has a certain value otherwise not.
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/