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 on April 23, and its replacement, statalist.org is already up and running.


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

st: RE: -inlist()- tip


From   "Jesper Lindhardsen" <JESLIN01@geh.regionh.dk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: -inlist()- tip
Date   Wed, 13 Apr 2011 08:32:03 +0200

This is indeed brilliant! I, for one, did not think of -inlist- in this
way, however simple and (potentially) obvious.
Cheers & thanks,

Jesper



Jesper Lindhardsen
MD, PhD candidate
Department of Cardiovascular Research
Copenhagen University Hospital, Gentofte
Denmark



-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 12 April 2011 21:08
To: statalist@hsphsun2.harvard.edu
Subject: st: -inlist()- tip

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/

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index