Why not:
sort x
gen rank=_n/_N
? If you want to exclude potential missing values of x, then
count if !missing(x)
local N = r(N)
sort x
gen rank = _n/`N'
Or maybe I'm missing something.
Jeph
Ana Gabriela Guerrero Serdan wrote:
Hi,
I have stata 9.1 and Im trying to do a fractional
ranking of a discrete variable (x) with three values
(1,2,3).
Im using the following commands:
sort x
egen n=count(x)
gen order=_n
by x: egen i=rank(order)
gen y=i/n
I somehow dont get values for y in a fractional way?
any ideas where Im doing wrong?
thanks
*
* 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/
*
* 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/