Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: egen to calculate industry medians with own frim excluded


From   "Friedrich Huebler" <[email protected]>
To   [email protected]
Subject   Re: st: egen to calculate industry medians with own frim excluded
Date   Wed, 19 Dec 2007 11:39:47 -0500

Erasmo,

The commands below should give you what you need. Other list members
may be able to offer more efficient solutions.

sysuse auto, clear
keep mpg rep78 foreign
egen group = group(rep78 foreign)
replace group = . if rep78 == . | foreign == .
gen median = .
count
local n = r(N)
quietly forvalues i = 1/`n' {
  gen temp = mpg if `i' != _n
  bysort group: egen temp2 = median(temp)
  replace median = temp2 in `i'
  drop temp temp2
}
replace median = . if group == .

Friedrich

On Dec 19, 2007 6:42 AM, Erasmo Giambona <[email protected]> wrote:
> Dear Statalisters,
>
> I am using the following code to get the median of my ffo variable
> within a certain industry/year for a sample of firms:
>
> egen ffo=median(med_ffoq ), by(industry year).
>
> However, I need to exclude the own firm before calculating the
> industry median for ffo. Does anyone has any suggestions on how I
> could do this with egen or any other command?
>
> Any help would be appreciated.
> Regards,
> Erasmo
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index