*! Version 1.00 * Calculation of Deviance Statistic after logistic command * Joseph Hilbe, STB 6/20/92 program define ldev version 3.0 if "$S_E_cmd"~="logistic" { error 301 } local in "opt" local if "opt" local weight "fweight" parse "`*'" parse "$S_E_vl", parse(" ") if "$S_E_wgt"!="" { if "`weight'"=="" { local wgt "[{S_E_wgt}{S_E_exp}]" local subttl ", weighted statistics" } else local subttl ", unweighted statistics" } if "`if'`in'`all'"=="" { local if "$S_E_if" local in "$S_E_in" } qui { local depvar "$S_E_depv" tempvar order num dev D cv gen `order'=_n _crcacnt cons `*' local df $S_1+1 lpredict `num', number lpredict `dev', deviance sort `num' by `num':gen `D'=sum(`dev'^2) if _n==1 replace `D'=sum(`D') local Dstat=`D'[_N] by `num': gen `cv'=1 if _n==1 replace `cv'=sum(`cv') local cvp=`cv'[_N] local adjdf=`cvp'-`df' noi di in gr _n(2) "Logistic estimates for `depvar', goodness-of-fit test" noi di in gr _n _col(3) " no. of observations" _col(31) "=" in ye %11.0g `order'[_N] noi di in gr _col(3) " no. of covariate patterns" _col(31) "=" in ye %11.0g `cvp' noi di in gr _col(3) " Deviance chi2(" in ye "`adjdf'" in gr ")" _col(31) "=" in ye %14.2f `Dstat' noi di in gr _col(3) " P>chi2" _col(31) "=" in ye %16.4f chiprob(`adjdf',`Dstat') sort `order' end