Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Re: eqany


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Re: eqany
Date   Mon, 8 Jul 2002 16:33:44 +0100

> Ronnie Babigumira wrote
>
> I am cleaning data (that's all I seem to be doing) and I am a little
> puzzled here. A while ago, I asked on how to identify illegal entries when
> a variable takes on values in batches (e.g. 11 to 19 21 to 25 etc). Nick
> Cox pointed me to
>
> . egen OK = eqany(cropcod2), values(110/120 220/227 330/334 440/446)
> . list houscode cropcod2 if !OK
>
> This has very well for, however, today I tried
>
> . egen OK = eqany(inpcode), values(500/505 599 601 1100/1111 /*
> . */ 1200/1201 2100/2160/ 2200/2220 2299 2300/2302)
> . list houscode inpcode if !OK
>
> I get an error message;
>
> . egen OK = eqany(inpcode), values(500/505 599 601 1100/1111 /*
> > */ 1200/1201 2100/2160 2200/2220 2299 2300/2302)
> varlist not allowed
> r(101);
>
> Any one familiar with this and a way around it?
>
> >>> Tom Steichen identified a typo in what is above. However,
> I suspect that this typo is just in what Ronnie sent to the list
> and that there is something more fundamental here.
>
> My answer is just a variation on the answer to Daniel
> Caro on 28 June.
>
> You are, I believe, tripping some limitation to the built-in
> command -numlist-, which is called by -egen, eqany()-. If
> I am right, this can be shown directly by pushing your numlist
> at -numlist-.
>
> An alternative for this problem is the use of -merge- as a variation on a
> trick documented by Kit Baum at
> http://www.stata.com/support/faqs/data/characteristics.html
>
> Put the values you want to select as a single variable in one
> Stata .dta file and then -merge- it with your main data file.
> The observations you want are the intersection of the two,
> for which _merge == 3. You can choose either one-to-one or match merging.
>
> Nick
> [email protected]

Well, it seems that the answer is more complicated yet.

-egen, eqany()- stops when it passes the numlist of
Ronnie's values to -numlist-.

Use Ronnie's numlist directly with -numlist- and it is happy with
that numlist supplied in abbreviated form.

The explanation may lie in the fact that the -numlist- statement
within -eqany()- is receiving the numlist in unabbreviated (expanded)
form, by virtue of its prior expansion when it leaves -syntax-.

There may be some redundant code there in -eqany()-, which can be blamed
on the original programmer, I guess, but the deeper question
is why -numlist- is choking on a numlist with fewer elements
than its advertised limit. (See -limits-.)


Nick
[email protected]

*
*   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