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: if


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: if
Date   Tue, 18 Oct 2011 09:41:31 +0100

Yes (with limits on the number of arguments). The Stata equivalent is

gen newvar = inlist(bankid, 2, 25, 46, 76)

For more on this function, see

SJ-6-4  dm0026  . . . . . . Stata tip 39: In a list or out? In a range or out?
        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
        Q4/06   SJ 6(4):593--595                                 (no commands)
        tip for use of inlist() and inrange()

For a recent tutorial on useful functions, see

http://ideas.repec.org/p/boc/usug11/21.html

http://www.stata-journal.com/article.html?article=dm0058

Note that even without -inlist()- you could do this once

gen somebanks = bankid ==2 | bankid==25 | bankid == 45 | bankid == 76

and ever after with the same variables you could do this

... if somebanks

Similarly, you could do this once

local somebanks bankid ==2 | bankid==25 | bankid == 45 | bankid == 76

and ever after in the same session you could do this

... if `somebanks'


Nick

On Tue, Oct 18, 2011 at 9:32 AM, Bulent Koksal <[email protected]> wrote:

>   In SAS I can write a command like
>
> if bankid in (2,25,46,76) then newvar=1; else newvar=0;
>
> How can I do this in Stata? I don't want to keep writing  bankid ==2 |
> bankid==25 etc.
>
> any easy way of doing this? Thank for any help.

*
*   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/


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