Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Federico Belotti <f.belotti@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: median without current observation |
Date | Mon, 15 Apr 2013 10:22:52 +0200 |
The following code creates R mediany variables (R is the number of regions), where each variable takes the median of the distribution of "y" excluding the value of region `r'. levelsof region, local(reglist) foreach r of local reglist { egen me_y`r' = median(y) if region!=`r' tempvar tmp egen "`tmp'" = max(me_y `r') replace me_y `r' = `tmp' if region==`r' } hope this helps. Federico On Apr 15, 2013, at 9:29 AM, Andres Silva wrote: > Dear statausers, > > I want to create a variable "mediany", which needs to be regional > median (without considering the current value of "y"). I mean I need > to calculate the median with the remaining values of "y" in each > specific region. > > by region: egen mediany=median(y) > How can I tell stata not use the current "y" value? > > I appreciate any advice, thanks, Andres > * > * 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/ -- Federico Belotti, PhD Research Fellow Centre for Economics and International Studies University of Rome Tor Vergata tel/fax: +39 06 7259 5627 e-mail: federico.belotti@uniroma2.it web: http://www.econometrics.it * * 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/