Nick Cox wrote:
Not clear to me that -group(X)- assigns values in
order of increasing X (even if, as E Berkhout suggests
in a separate posting, I sort -sort X- first).
...
A look at the code for each shows that both
produce sorted values and that's the intent
in each case.
-levels- is not appropriate directly for
problems in which categories are defined by
numbers with fractional parts. Otherwise
I can't comment further on what is not clear
to you without knowing what your doubts are.
Well, when I look at the documentation for these two,
neither mentions anything about returning sorted values.
That raises some doubt. And when I look at the code for
-egen-'s -group- I see
sort `touse' `varlist'
quietly by `touse' `varlist': /*
*/ gen `type' `g'=1 if _n==1 & `touse'
replace `g'=sum(`g')
- it's not clear to me that I don't need the last line to have
one inserted before it
sort `varlist'
replace `g'=sum(`g')
to get the ordering (of -g- on `varlist') you say is clearly intended.
Is the preceeding -by : gen- guaranteed not to unsort the -sort-? Not
the sort of thing I usually count on. So there's another reason for doubt.
Sure, I could add the line and restore my confidence, but I
don't like fiddling with official Stata code. Or, I could test
out -egen-'s -group- to see if it has the behaviour I want, but
obviously it was much easier to code my own ranking.
Thanks again.
cheers,
Jeph
*
* 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/