Bookmark and Share

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, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: median without current observation

From   Federico Belotti <>
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.

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:
> *
> *
> *

Federico Belotti, PhD
Research Fellow
Centre for Economics and International Studies
University of Rome Tor Vergata
tel/fax: +39 06 7259 5627

*   For searches and help try:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index