Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: generating variable that reflects order of values of another variable


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: generating variable that reflects order of values of another variable
Date   Wed, 16 Jan 2013 14:38:29 +0000

This sounds like ranking to me.

At its very simplest, this could be just

sort var1
gen var2 = _n

but -if- or -in- qualifiers, missing values and tied values could mess
things up.

See help on -egen-'s -rank()- function for a more general tool,
including options for different ranking conventions.

Nick

On Wed, Jan 16, 2013 at 2:28 PM, Rubil Ivica <irubil@eizg.hr> wrote:

> Suppose I have N observations on a variable var1. How to generate
> another variable var2 which takes on values 1 to N, where 1 is assigned
> to the observation with the lowest value of var1, N is assigned to the
> observation with the highest value of var1, and all other values between
> 1 and N are assigned accordingly?
>
> Thanks.
>
>
>
> --
> Ivica Rubil
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/statalist-faq/
> *   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index