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
Andres Silva <[email protected]>
To
[email protected]
Subject
Re: st: median without current observation
Date
Mon, 15 Apr 2013 11:23:14 +0200
Hi Nick and Federico,
Thank you!!!, Andres
On Mon, Apr 15, 2013 at 11:17 AM, Nick Cox <[email protected]> wrote:
> Federico and I made different guesses about the data structure and
> what is needed.
>
> In Federico's case, the code can be simplified, I think
>
> levelsof region, local(reglist)
> gen me_y = .
> foreach r of local reglist {
> su y if region != `r', detail
> replace me_y = r(p50) if region==`r'
> }
>
> Nick
> [email protected]
>
> On 15 April 2013 09:22, Federico Belotti <[email protected]> wrote:
>
>> 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?
>>>
> *
> * 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/
*
* 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/