Statalist The Stata Listserver


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

Re: st: RE: error with -egen median if-


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: RE: error with -egen median if-
Date   Mon, 22 May 2006 12:58:06 -0400

Alex Ogan:
The bug is reproducible, it seems. Note that the median function for
-egen- is implemented as _gmedian.ado and is written in Stata 3 code,
which is the version I started in, but no longer remember... let's
rewrite it in Stata 6 code and see if that works.  Save the following
as _gmed6.ado in your c:\ado folder or equivalent, and try your code
again using egen y=med6(x).

program define _gmed6
version 6, missing
syntax newvarname =/exp [if] [in] [, BY(varlist)]
tempvar touse x n
quietly {
 gen byte `touse'=1 `if' `in'
 gen double `x' = `exp'
 sort `touse' `by' `x'
 by `touse' `by': gen long `n'=sum(`x'<.)
 by `touse' `by': g `varlist' = ( /*
  */ `x'[(`n'[_N]+1)/2] + /*
  */ `x'[(`n'[_N]+2)/2] ) / 2 if `touse'==1
}
end

On 5/22/06, Alex Ogan <[email protected]> wrote:
Here is a more simple example.  I also should have mentioned I am using
Stata/SE 8.2.
. egen testsum_1 = sum(numvar)
. egen testmedian_1 = sum(numvar)
. egen testsum_2 = sum(numvar) if strvar=="a"
(2 missing values generated)
. egen testmedian_2 = median(numvar) if strvar=="a"
a not found
r(111);
*
*   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