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

# st: -inlist()- tip

 From Nick Cox <[email protected]> To [email protected] Subject st: -inlist()- tip Date Tue, 12 Apr 2011 20:07:51 +0100

```Musing about -inlist()- reminded me of an application that was
certainly omitted from

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

but which I've seen somewhere previously, perhaps on the list.

-inlist()- is perhaps best known for examples like

... if inlist(rep78, 3, 4, 5)

which can be thought of as equivalent to

... if rep78 == 3 || rep78 == 4 || rep78 == 5

However, consider also this

... if inlist(1, a, b, c, d, e)

which can be thought of as equivalent to

... if 1 == a | 1 == b | 1 == c | 1 == d | 1 == e

which in practice (mathematics schooling?) most of us would be more
likely to write

... if a == 1 | b == 1 | c == 1 | d == 1| e == 1

but that difference is immaterial.

If all this was already utterly obvious to you beforehand, my
apologies (or congratulations), but I've been wondering why this was
not obvious to me beforehand. I think it was because I had
internalised -inlist()- in terms of one application, whether a
variable was equal to one of a list of values, and was usually
thinking of it in that verbal form. (The Tip referred to above goes a
bit further.) Thus I missed the elementary algebra that if a variable
is equal to a value then that value is also equal to that variable.
There may be a few others who will be happy to discard that small
mental block.

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