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, **statalist.org** is already up and running.

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

From |
"Wiemann, Markus" <m.wiemann@fs.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
AW: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this? |

Date |
Thu, 26 May 2011 14:14:53 +0200 |

What about replace v1 = 1 if vx==1 & v1 == . replace v2 = 1 if vx==1 & v1 != . & v2 == . replace v3 = 1 if vx==1 & v1 != . & v2 != . Isn't that what you are looking for? Best Markus -----Ursprüngliche Nachricht----- Von: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von paul o'brien Gesendet: Donnerstag, 26. Mai 2011 13:44 An: statalist@hsphsun2.harvard.edu Betreff: Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this? thanks for this Nick. the thing is, i want second and third replacements to be conditional on the first and second, so the second replacement occurs only if the v1 is not missing and the third if both v1 and v2 are not missing. so, only one change required - either at v1, v2 or v3. Paul On 25/05/2011, Nick Cox <njcoxstata@gmail.com> wrote: > 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/ > * * 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/ * * 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/

**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>

**Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?***From:*Nick Cox <njcoxstata@gmail.com>

**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>

- Prev by Date:
**[no subject]** - Next by Date:
**Re: st: Bootstrapping stepwise selected survival analysis variables** - Previous by thread:
**Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?** - Next by thread:
**st: Job opening at Harvard Business School** - Index(es):