Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: Optimizing recoding procedures


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: Optimizing recoding procedures
Date   Tue, 11 Dec 2012 17:41:19 +0000

if x==1 | x==2 | x==3 | y==1 | y==2 | y==3

could be

if inlist(x, 1, 2,3) | inlist(y, 1, 2, 3)

but

replace x = 0 if x==1 & x==2 & x==3 & y==1 & y==2 & y==3

will be legal but makes no sense. x can't be 1 and 2 at the same time;
similar comment for y.

There seem to be several other typos in your posting. I don't know of
-egen- functions -ral()- or -rany()-.

Nick

On Tue, Dec 11, 2012 at 4:56 PM, Thomas Lux <[email protected]> wrote:

> I am trying to optimize my data recoding procedures (in Stata 11).
> With the inlist-function it is possible to reduce the syntax in such a way:
>
>
>
> gen x = 1 if z==1
>
> replace x = 0 if x==1 | x==2 | x==3
>
>
> gen x = 1 if z==1
> replace x = 0 if inlist(y, 1, 2, 3)
>
>
> However, I am looking for functions that allow a reduction in a situation with two variables in the (second) if statement:
>
>
> gen x = 1 if z==1replace x = 0 if x==1 | x==2 | x==3 | y==1 | y==2 | y==3
>
> and:
>
>
> geb x = 1 if z==1replace x = 0 if x==1 & x==2 & x==3 & y==1 & y==2 & y==3
>
>
> Is there a way of doing this via a DIRECT function in the if statement (that is without taking the indirect route via "egen ral" respectively "egen rany")?
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index