mcaceresb / stata-gtools

Faster implementation of Stata's collapse, reshape, xtile, egen, isid, and more using C plugins
https://gtools.readthedocs.io
MIT License
182 stars 38 forks source link

gegen rank vs. egen rank #68

Closed economoser closed 4 years ago

economoser commented 5 years ago

It seems that, oddly, the -rank- subcommand of -gegen- does not support a by-option, while the original -egen- command does. Maybe a bug? See example below:

. bys year: gegen inc_rank = rank(inc)
by: prefix not allowed with rank
r(198); t=0.02 9:18:35

. bys year: egen inc_rank = rank(inc)
(9925 missing values generated)
r; t=0.10 9:18:39
mcaceresb commented 5 years ago

This is not so much of a bug as maybe a design flaw. I purposely disallowed that in case the user tried to pass something that is allowed with by but that I wouldn't account for... However, in this case I force the input to be a single variable, so it might be OK.

I'l probably allow the by prefix in the next release. In the meantime you can comment out lines 152 to 155 in gegen.ado as a quickfix (i.e. these lines).