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: egen nth highest or lowest value


From   "Bartus Tamás" <[email protected]>
To   [email protected]
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, [email protected] 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index