Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: alt to inlist?


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: alt to inlist?
Date   Tue, 24 Jan 2006 07:39:26 +0900

Danielle H. Ferry wrote:

Is there something like inlist which does not require that all arguments
exist? I would like to keep observations where varname = a or b or c or d or
... But  it could be that varname never takes the value of d. Another issue
is
that my list of arguments is v. long (~145), so a simple or statement is not
possible. I found a stata faq that suggested using inlist, but this doesn't
like it when one of the arguments in the list doesn't exist, and my varname
is
a string, so I'd have to write many of these inlist statements (b/c the
limit
is 2 strings).

--------------------------------------------------------------------------------

A variable *name* doesn't exist in the list of arguments?  The circumstances
sound peculiar--either variable d exists in a dataset or it doesn't and if
the former, then you'll select all observations in the dataset.  Could you
tell us a bit more just what it is that you're trying to accomplish?  There
might be a better route to your objective that someone on the List can
suggest given a little more detail.

According to the help file, -inlist()- takes up to ten string arguments in
its list of possibilities (a, b, c, . . . in the help file syntax example).
And, in my experience, -inlist()- doesn't care if one of these arguments--or
even if any of them--doesn't exist.  Just the first argument needs to exist
(z in the help file's syntax example).  You can use multiple instances
of -inlist()-:

keep if inlist(Z, a, b, c, d, e, f, g, h, i, k) | ///
 inlist(z, l, m, n, o, p, q, r, s, t, u) | ///
 inlist(z, . . . .)

but, again, there might be a more direct way to do what it is that you're
trying to do.

Joseph Coveney

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index