I do not think that the "debugging" would be nearly as ominous as suggested by the good wish of Adam in his post with the very ominous number #13 ("Best of luck in debugging!").
In my Stata 15 the code currently reads:
The statement that is causing the problem is in red. If the code red is changed to the new code in red as follows:
everything works as expected:
In my Stata 15 the code currently reads:
Code:
*! version 3.0.3 23may2006
program define _gmedian
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
Code:
*! version 3.0.3 23may2006, bug fix 29/09/2021
program define _gmedian
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': gen `typlist' `varlist' = ( /*
*/ `x'[(`n'[_N]+1)/2] + /*
*/ `x'[(`n'[_N]+2)/2] ) / 2 if `touse'==1
}
end
Code:
. bys outage_id: egen double method2 = median(restore_time) . * compare . . tabstat method?, by(outage_id) format(%12.0g) nototal Summary statistics: mean by categories of: outage_id outage_id | method1 method2 ----------+-------------------- 1 | 1528919542 1528919542 2 | 1529061132 1529061132 ------------------------------- . . assert method1==method2
Comment