Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: fraction ranking


From   Jeph Herrin <[email protected]>
To   [email protected]
Subject   Re: st: fraction ranking
Date   Wed, 06 Dec 2006 07:41:01 -0500

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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index