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

Re: st: Transformations


From   "Michael Blasnik" <[email protected]>
To   <[email protected]>
Subject   Re: st: Transformations
Date   Thu, 12 Feb 2004 10:16:51 -0500

Instead of the egen eqany() command, a better (one line) approach would be
to use the inlist function.

replace var1=1 if inlist(var2,1,3)

Michael Blasnik
[email protected]

----- Original Message ----- 
From: "chris wallace" <[email protected]>
To: "statalist" <[email protected]>
Sent: Thursday, February 12, 2004 4:11 AM
Subject: RE: st: Transformations


> 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index