I don't want to sound like a cracked record, but once again
this is the subject of an FAQ.
FAQ . . . . . . . . . . Calculating percentile ranks or plotting positions
7/02 How can I calculate percentile ranks?
How can I calculate plotting positions?
http://www.stata.com/support/faqs/stat/pcrank.html
The main fallacy in Ana Gabriela's code is calculating ranks
-by x:-. As Jeph points out, more general code would be more
careful about missing values. As the FAQ points out, there
are other definitions of fractional rank.
That said, I am not clear about the utility of calculating
ranks given just three distinct values.
Nick
[email protected]
Jeph Herrin
> 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?
*
* 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/