Thomas Steichen
> I just tried two related commands that I thought should yield
> the same result... both should set the generated variable to 1
> if -id- contains one of the numbers in -v()-:
> . egen sex =eqany(id), v(1 2 7 8 17/22 25 26 39/42 45 46 53/58 61
62)
> . egen sex1=eqany(id), v(1 2 7 8 17:22 25 26 39:42 45 46 53:58 61
62)
> Note that the only difference (other than varname)
> is the use of the colon vs slash in the -v(numlist)-.
> The resulting Stata-generated var labels are:
> sex: id == 1 2 7 8 17 18 19 20 21 22 25 26 39 40 41 42 45 46 53 54
55 56 57 58
> 61 62
> sex1: id == 1 2 7 8 17 25 26 39 45 46 53 61 62
> Unfortunately, the labels properly echo the values of the variables!
> Is this an error or a misconception by me?
This is not, I think, at all intrinsic to -egen, eqany()-,
although I had to read the help on numlists a few times
before the point became clear.
Of all the alternative syntaxes
for numlists, it seems that only #1/#2 and #1(#3)#2
are at all frequently used.
#1:#2 is _not_ a synonym for #1/#2.
(In fact, #1:#2 by itself is not even legal.)
There is really a triadic operator here.
#1 #2:#3
Stata looks at #1 and #2, calculates the difference
and takes steps of that size from #2 until
and unless it passes #3. With
8 17:22
the first step is 9, which would produce 26, but we have
already passed 22, so the game produces no more numbers.
The other examples are all similar.
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/