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

From |
Johannes Geyer <JGeyer@diw.de> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: if and if |

Date |
Thu, 13 Nov 2008 11:25:58 +0100 |

> I have a question. Where did you read that the command > > if j==1 > > will be testing the FIRST observation. I don't think that it is in the > stata help for if. Could you point me in the right direction here. One source would also be: http://www.stata.com/support/faqs/lang/ifqualifier.html >cond would not be useful cos it can do ONLY 2 conditions. I want to be >able to use it in MANY conditions. Is there a SUPER cond which can do >that ? -cond- can handle more conditions, you simply include other -cond- in the condition like in http://www.stata.com/support/faqs/data/condition.html But I am not sure whether this helps to solve your problem. Johannes > > > Also I liked your use of the local in that way. I did not think of > that . Did you read that somewhere too ? > > Thank you, > Ashim. > > On Thu, Nov 13, 2008 at 2:10 PM, Svend Juul <SJ@soci.au.dk> wrote: > > > > Ashim wrote: > > > > I realize that there are 2 kinds if's in Stata. > > > > Type 1 : would be something like replace j = 2 if k==2 > > here the replace in j would happen ONLY in the corresponding > > observation of k. THIS IS WHAT I WANT. > > > > > > Type 2 : the programming if something like > > > > local j > > > > if `j'==2 { > > > > do something. > > > > } > > > > ************************************************************** > > > > I guess I want to do something which is in between the above 2. > > > > I want to say the following : -- > > > > replace j=2 if k==2 > > replace m=2 if k==2 > > replace n=2 if k==2 > > > > in ONE shot. > > > > so I try : - > > ************************************** Block A > > if k==2 { > > replace j=2 > > replace m=2 > > replace n=2 > > } > > ********************************************* > > This does not work. Because k==2 would mean k==2 in ALL observations. > > ... > > > > =============================================================== > > > > Actually the command -if k==2- means k==2 in the FIRST observation. > > In Stata terms, your type 1 -if- is a qualifier; your type 2 -if- is > > a command. > > > > There is probably no smart way to do what you want. In some cases > > you might benefit from putting the condition in a macro, like: > > > > sysuse auto.dta , clear > > local X "if foreign==1" > > replace price = 1 `X' > > replace weight = 2 `X' > > > > Hope this helps > > Svend > > __________________________________________ > > > > Svend Juul > > Institut for Folkesundhed, Afdeling for Epidemiologi > > (Institute of Public Health, Department of Epidemiology) > > Vennelyst Boulevard 6 > > DK-8000 Aarhus C, Denmark > > Phone: +45 8942 6090 > > Home: +45 8693 7796 > > Email: sj@soci.au.dk > > __________________________________________ > > > > * > > * 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/

**Follow-Ups**:**Re: st: if and if***From:*"Ashim Kapoor" <ashimkapoor@gmail.com>

**References**:**Re: st: if and if***From:*"Ashim Kapoor" <ashimkapoor@gmail.com>

- Prev by Date:
**Re: R: st: R: if and if** - Next by Date:
**Re: st: R: if and if** - Previous by thread:
**Re: st: if and if** - Next by thread:
**Re: st: if and if** - Index(es):

© Copyright 1996–2016 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |