Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Simplifying multiple cases of the if command


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Simplifying multiple cases of the if command
Date   Fri, 16 Nov 2012 17:55:57 +0000

You can go

... if inlist(news, 1, 3, 5)

That is another way to do it. See also

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()

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

or

http://statadaily.wordpress.com/2011/10/20/functions-inlist/

Nick

On Fri, Nov 16, 2012 at 5:33 PM, sanja_lutzeyer@ncsu.edu
<slutzey@ncsu.edu> wrote:

> This might be a very easy question, but if I have a number of things
> that have to hold when generating a variable, is there a way to
> simplify the following?
>
> generate variable if news== 1 | news == 3 | news ==5
>
> to something like
> generate variable if news == 1 | 3 | 5? I tried this
>
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index