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

From |
"Carlo Lazzaro" <carlo.lazzaro@tiscalinet.it> |

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

Subject |
st: R: if and if |

Date |
Thu, 13 Nov 2008 09:57:21 +0100 |

Dear Ashim, would - help cond() - be useful for your research purposes? Kind Regards, Carlo -----Messaggio originale----- Da: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] Per conto di Ashim Kapoor Inviato: giovedì 13 novembre 2008 8.56 A: statalist@hsphsun2.harvard.edu Oggetto: st: if and if 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/ * * 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: R: if and if***From:*"Ashim Kapoor" <ashimkapoor@gmail.com>

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

- Prev by Date:
**Re: st: Re: Memory** - Next by Date:
**R: st: R: Pooled effects for continuous data** - Previous by thread:
**st: if and if** - Next by thread:
**Re: st: R: if and if** - Index(es):

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