[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: if
Nick Cox <email@example.com>
Re: st: if
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
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'
On Tue, Oct 18, 2011 at 9:32 AM, Bulent Koksal <firstname.lastname@example.org> 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: