Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.

# Re: st: median without current observation

 From Nick Cox To "statalist@hsphsun2.harvard.edu" Subject Re: st: median without current observation Date Mon, 15 Apr 2013 09:51:33 +0100

```This is an FAQ.

FAQ     . . Creating variables recording prop. of the other members of a group
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  N. J. Cox
4/05    How do I create variables summarizing for each
individual properties of the other members of a
group?
http://www.stata.com/support/faqs/data-management/creating-variables-recording-properties/

Your problem is similar to that in Section 5, but the code can be
simplified a bit.

gen mymedian = .
bysort region : gen myid = _n
su myid, meanonly

quietly forvalues i = 1/`r(max)' {
egen work = median(y / (myid != `i')), by(region)
replace mymedian = work if myid == `i'
drop work
}

drop myid

Nick
njcoxstata@gmail.com

On 15 April 2013 08:29, Andres Silva <asilvam@uc.cl> wrote:

> 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?
*
*   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/
```