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]
Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?
Date
Wed, 25 May 2011 20:21:18 +0100
I am not sure that you mean what you say by "otherwise". What is
definite is that
if vx == 1
as a command will be interpreted as
if vx[1] == 1
which is unlikely to be what you want. See
FAQ . . . . . . . . . . . . . . . . . . . . . if command vs. if qualifier
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . J. Wernow
6/00 I have an if command in my program that only seems
to evaluate the first observation, what's going on?
http://www.stata.com/support/faqs/lang/ifqualifier.html
for detailed explanation.
I am assuming that -vx- is not a scalar, but a variable.
It sounds as if you want statements like these:
replace v1 = 1 if missing(v1) & vx == 1
If you really want the "otherwise", you will need something like this
gen ismissv1 = missing(v1)
gen ismissv2 = missing(v2)
replace v1 = 1 if missing(v1) & vx == 1
replace v2 = 1 if missing(v2) & vx == 1 & !ismissv1
replace v3 = 1 if missing(v3) & vx == 1 & !ismissv1 & !ismissv2
Somehow I guess that you are after something more like this
replace v1 = 1 if missing(v1) & vx == 1
replace v2 = 1 if missing(v2) & vx == 1
replace v3 = 1 if missing(v3) & vx == 1
although you don't mention the missing(v3).
Nick
On Wed, May 25, 2011 at 7:57 PM, Paul O'Brien <[email protected]> wrote:
> i cannot think how to do this in Stata:
>
> if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 if v2 is missing, otherwise replace v3=1).
>
> thanks for any help you can give.
>
*
* 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/