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]

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 The second -replace- won't take place if -v1- was originally missing. (The original missings have been changed to 1 on the first -replace-, so we have to keep track of their previous state.) If this doesn't help, give a little table of the possibilities missing v1 missing v2 missing v3 yes no no ... and the outcomes desired. Nick On Thu, May 26, 2011 at 12:44 PM, paul o'brien <paul.obrien@afe2.org.uk> wrote: > 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/

- Prev by Date:
**Re: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?** - Next by Date:
**AW: st: if vx==1 (replace v1=1 if v1 is missing, otherwise replace v2=1 ... : how do i do this?** - Previous by thread:
**st: quantile regression with an AR(1) disturbance** - Next by thread:
**st: date conversion** - Index(es):