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]

From |
"paul o'brien" <paul.obrien@afe2.org.uk> |

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 |
Thu, 26 May 2011 12:44:08 +0100 |

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/

**Follow-Ups**:**AW: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?***From:*"Wiemann, Markus" <m.wiemann@fs.de>

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

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

- Prev by Date:
**st: Bootstrapping stepwise selected survival analysis variables** - Next by Date:
**st: quantile regression with an AR(1) disturbance** - 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:
**Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?** - Index(es):