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: median without current observation


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
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
[email protected]


On 15 April 2013 08:29, Andres Silva <[email protected]> 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/


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