Statalist


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

RE: st: How to create a rank?


From   "Newson, Roger B" <[email protected]>
To   <[email protected]>
Subject   RE: st: How to create a rank?
Date   Tue, 4 Mar 2008 12:51:59 -0000

If you check the entry for -rank()- under -whelp egen-, then you will
find that -rank()- supports multiple definitions of ranks. The default
is

rank(Y_j) = 0.5 + 0.5*Sum_k(Y_k==Y_j) + Sum_k(Y_k<Y_j)

where Y_j is the value of the variable being ranked in the j'th
observation, rank(Y_j) is its rank, Y_k is the k'th observation, and
Sum_k is the sum over all k from 1 to N, where N is the number of
observations being ranked. This definition implies that tied Y_j values
are given the mean of the ranks that they would have had, if they had
been ranked randomly. This often implies fractional ranks. However,
there are other possibilities on offer. You can decide which one is
right for your purposes.

I hope this helps.

Roger


Roger B Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: [email protected] 
Web page: www.imperial.ac.uk/nhli/r.newson/
Departmental Web page:
http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/pop
genetics/reph/

Opinions expressed are those of the author, not of the institution.

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Song
Sent: 04 March 2008 03:58
To: [email protected]
Subject: Re: st: How to create a rank?

Thank you. I solved my problem. By the way, if there exist ties, egen
rank = 
rank(revenue) also creates a problem. In my case, the command produced 
***.5, etc. instead of a whole number.

Reo.

----- Original Message ----- 
From: "Nick Cox" <[email protected]>
To: <[email protected]>
Sent: Monday, March 03, 2008 3:11 AM
Subject: RE: st: How to create a rank?


> As mentioned in my earlier posting, this fixes the reversal but does
the
> wrong thing in the presence of ties.
>
> For ranks, use -egen, rank()-. It's as simple as that.
>
> Nick
> [email protected]
>
> Jeremy Miles
>
> How about :
>
> gen revenue_reversed = revenue * -1
> sort revenue_reversed
> egen rank=group(revenue_reversed)
>
> Song
>
>>  I am trying to create 'rank' based on total revenues. I used the
> following
>>  command:
>>
>>  sort revenue
>>  egen rank=group(revenue)
>>
>>  The result is that the smallest revenue is 1 and the highest revenue
> is 100,
>>  for example. How can I reverse the rank? I want the highest revenue
> to be
>>  number '1'.
>
> *
> *   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/

*
*   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