Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: Transformations


From   chris wallace <c.wallace@qmul.ac.uk>
To   statalist <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Transformations
Date   12 Feb 2004 09:11:07 +0000

On Wed, 2004-02-11 at 22:55, Jason Payne wrote:
> Thank you for your help,
> 
> Is there a way to list multiple cases that dont fit a standard expression in the replace command. for example:
> 
> replace var1=1 if var2==1 or 3
> 
> I want cases 1 and 3 to have value 1 for var1, but not case 2 and rather than writing the whole syntax twice, i would like to shorten it: 
> 
> replace var1=1 if caseid==1
> replace var1=1 if caseid==3

replace var1=1 if caseid==1 | caseid==3

or, more generally (if you have a big list of caseid values), 

egen to_replace = eqany(caseid), v(1 3)
replace var1=1 if to_replace==1
drop to_replace

C.

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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