Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Ranking observations of a variable across a set of variables

From   "Jennifer L. Milosch" <>
Subject   Re: st: Ranking observations of a variable across a set of variables
Date   Wed, 02 Nov 2011 09:56:15 -0700

Thank you, this is exactly what I was looking for.

Jennifer L. Milosch
Ph.D. Candidate
Dept of Economics
UC Santa Barbara

Quoting Nick Cox <>:

For a detailed review of this and similar problems, see

SJ-9-1 pr0046 . . . . . . . . . . . . . . . . . . . Speaking Stata: Rowwise (help rowsort, rowranks if installed) . . . . . . . . . . . N. J. Cox
        Q1/09   SJ 9(1):137--157
        shows how to exploit functions, egen functions, and Mata
        for working rowwise; rowsort and rowranks are introduced

Note that -egen-'s -rank()- function is not producing incorrect
results; it just does not produce what Jennifer wants and does not
claim to. It ranks observations on the values of a variable, not
variables on the values of a set of variables in each observation.


On Wed, Nov 2, 2011 at 5:02 AM, Tirthankar Chakravarty
<> wrote:

You probably want Nick Cox's -rowranks- package, available from SSC:

input x1 x2 x3 x4
50 10 30 60
20 60 10 40
ssc install rowranks
rowranks x1-x4, generate(rank1-rank4) field

On Tue, Nov 1, 2011 at 8:24 PM, Jennifer L. Milosch
<> wrote:

I am trying to find the rank of an observation of a variable across a set of
variables. My data looks something like this:


I want to generate a variable for the rank of x1 compared to the values of
x1, x2, x3, and x4 for each observation in the data.  I have tried using

-bysort x1 x2 x3 x4: egen rank1=rank(x1)-

but it is returning a variable of all ones, which is not correct.  Using the
data above, I'm look for variables that are:

2 |4 |3 |1
3 |1 |4 |2

*   For searches and help try:

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index