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 at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: egen nth highest or lowest value


From   "Bartus Tamás" <tamas.bartus@uni-corvinus.hu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: egen nth highest or lowest value
Date   Thu, 11 Apr 2013 09:42:22 +0200

The code for, say, the lowest 5th value of variable x could be

sort x
gen tempvar = x in 5
egen newvar = mean(tempvar)

The code for the highest 5th value is

gsort - x
gen tempvar = x in 5
egen newvar = mean(tempvar)

Hope this helps,

Tamas

On 13/04/11, Caterina.ASTARITA@ec.europa.eu wrote:
> Dear Statalisters, 
> 
> is that possible to generate a new variable containing the nth lowest or nth highest value of another variable? 
> 
> Thanks
> 
> 
> *
> *   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/
> 
> 
--

Tamas Bartus, PhD
Associate Professor, Deputy Director
Institute of Sociology and Social Policy
Corvinus University, Budapest 
1093 Budapest, Közraktár utca 4-6.
Room 424.
Phone:  +36-1-482-7301         
Fax:          +36-1-482-7348
Homepage: http://web.uni-corvinus.hu/bartus

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index