On Mon, 18 Feb 2008, Allin Cottrell wrote:
> One more question: is there any way to generate a new variable
> which is the rank of an already existing one (so that biggest
> value on the existing variable gets 1, second biggest 2, and so
> on...).
I think what you want is
genr y = ranking(x)
One small enhancement: if you want the result exactly like you said, you
probably want something like
<script>
nulldata 10
set seed 37634
z = uniform()
r = ranking(z)
rr = max(r) - r + 1
print z r rr --byobs
</script>
note: if you have "ties", you'll get non-integer rankings. From the
documentation for the upcoming version:
ranking
Output: series
Argument: y (series)
Returns a series with the ranks of y. The rank for observation i is the
number of elements in the series that are less than yi plus one half the
number of elements in the series that are equal to yi. (Intuitively, you
may think of chess points, where victory gives you one point and a draw
gives you half a point.) One is added so the lowest rank is 1 instead of
0.
Riccardo (Jack) Lucchetti
Dipartimento di Economia
Università Politecnica delle Marche
r.lucchetti(a)univpm.it
http://www.econ.univpm.it/lucchetti