[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: RE: error with -egen median if-
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
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
On 5/22/06, Alex Ogan <email@example.com> wrote:
Here is a more simple example. I also should have mentioned I am using
. 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
* For searches and help try: