Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

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 <paul.obrien@afe2.org.uk> 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/

**Follow-Ups**:**Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?***From:*"paul o'brien" <paul.obrien@afe2.org.uk>

**References**:**st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?***From:*"Paul O'Brien" <paul.obrien@afe2.org.uk>

- Prev by Date:
**Re: st: svy subpop option and e(sample)** - Next by Date:
**Re: st: number of dates in x axis** - Previous by thread:
**st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?** - Next by thread:
**Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?** - Index(es):