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

From |
"Ashim Kapoor" <ashimkapoor@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: if and if |

Date |
Thu, 13 Nov 2008 13:25:59 +0530 |

Hello everyone, 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. While I mean to say make j / m / n = 2 in those observations where k is 2. How do I do this in a quick manner in Block A ? I understand that I can always do :- foreach var of j m n { replace `var'=2 if k==2 } But is there a better way ? The reason I want this is the following : - I want if k==2 { replace j=1 replace m=5 replace n=89 } so the above method fails as I do not have the SAME value 2 to be put in each of j / m /n. Any slick way of doing this ? Thank you, Ashim * * 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**:**st: RE: if and if***From:*"Nick Cox" <n.j.cox@durham.ac.uk>

**st: R: if and if***From:*"Carlo Lazzaro" <carlo.lazzaro@tiscalinet.it>

- Prev by Date:
**Re: st: R: Pooled effects for continuous data** - Next by Date:
**Re: st: Writing graphs to the log file** - Previous by thread:
**st: logit with clusters** - Next by thread:
**st: R: if and if** - Index(es):

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