*! version 1.0.2 16apr1996 program define svy_dreg /* display results */ version 4.0 if "$S_E_cmd"=="svylogit" { local or "OR" } local options /* */ "Level(int $S_level) Prob CI DEFF DEFT MEFF MEFT noHEADer `or'" parse "`*'" if `level' < 10 | `level' > 99 { local level 95 } if "`prob'`ci'`deff'`deft'`meff'`meft'"=="" { local prob "prob" local ci "ci" } local count 2 if "`prob'"!="" { local PROB " " local count 3 } else local PROB "*" if "`ci'"!="" { local CI " " local count = `count' + 2 } else local CI "*" if "`deff'"!="" & `count' < 5 { local deff local DEFF " " local count = `count' + 1 } else local DEFF "*" if "`deft'"!="" & `count' < 5 { local deft local DEFT " " local count = `count' + 1 } else local DEFT "*" if "`meff'"!="" & `count' < 5 { local meff local MEFF " " local count = `count' + 1 } else local MEFF "*" if "`meft'"!="" & `count' < 5 { local meft local MEFT " " local count = `count' + 1 } else local MEFT "*" /* Get estimates. */ tempname t b V scalar `t' = invt($S_E_npsu - $S_E_nstr, `level'/100) matrix `b' = get(_b) matrix `V' = get(VCE) local dim = colsof(`b') /* Odds ratio. */ if "`or'"!="" { if `dim'==colnumb(`b',"_cons") { local dim = `dim' - 1 } } else local or "no" /* make it nonmissing for argument passing */ /* Print out header. */ if "`header'"=="" { Header } /* Print out column headers of table 1. */ DashLine Colhead `level' `or' " " "`PROB'" "`CI'" /* */ "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'" /* Print out body of table 1. */ DashLine 10 local i 1 while `i' <= `dim' { Body `i' `b' `V' `t' `or' " " "`PROB'" "`CI'" /* */ "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'" local i = `i' + 1 } DashLine /* See if there is more to print out. */ if "`deff'`deft'`meff'`meft'"=="" { FootNote exit } /* If here, we need to print out another table. */ if "`deff'"!="" { local DEFF " " } else local DEFF "*" if "`deft'"!="" { local DEFT " " } else local DEFT "*" if "`meff'"!="" { local MEFF " " } else local MEFF "*" if "`meft'"!="" { local MEFT " " } else local MEFT "*" if "`obs'"!="" { local OBS " " } else local OBS "*" if "`size'"!="" { local SIZE " " } else local SIZE "*" /* Print out column headers of table 2. */ DashLine Colhead `level' `or' * * * "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'" /* Print out body of table 2. */ DashLine 10 local i 1 while `i' <= `dim' { Body `i' `b' `V' `t' `or' * * * /* */ "`DEFF'" "`DEFT'" "`MEFF'" "`MEFT'" local i = `i' + 1 } DashLine FootNote end program define DashLine version 4.0 if "`1'"=="" { di in gr _dup(78) "-" exit } local dash1 = `1' - 1 local dash2 = 78 - `1' di in gr _dup(`dash1') "-" "+" _dup(`dash2') "-" end program define FootNote version 4.0 if "$S_E_fpc"!="" { /* print FPC note */ #delimit ; di in blu "Finite population correction (FPC) assumes " "simple random sampling without " _n "replacement of PSUs within each stratum with no " "subsampling within PSUs." ; #delimit cr } if "$S_E_f"=="singular" { di _n in blu "Note: covariance matrix is singular." } if "$S_E_fail$S_E_succ"!="" { if "$S_E_fail"!="" { local nfail "$S_E_fail" } else local nfail 0 if "$S_E_succ"!="" { local nsucc "$S_E_succ" } else local nsucc 0 if `nfail'==1 { local failure "failure" } else local failure "failures" if `nsucc'==1 { local success "success" } else local success "successes" di _n in blu "Note: `nfail' `failure' and `nsucc' " /* */ "`success' completely determined." } end program define Colhead version 4.0 local level "`1'" local or "`2'" macro shift 2 if "$S_E_cmd"=="svymean" | "$S_E_cmd"=="svyratio" /* */ | "$S_E_cmd"=="svytotal" { local col1 " Estimate" } else if "`or'"!="or" { local col1 " Coef." } else local col1 "Odds Ratio" `1' local head " `col1' Std. Err." `2' local head "`head' t P>|t| " `2' local s " " `3' local head "`head'`s' [`level'% Conf. Interval]" `3' local s " " `4' local head "`head'`s' Deff" `4' local s " " `5' local head "`head'`s' Deft" `5' local s " " `6' local head "`head'`s' Meff" `6' local s " " `7' local head "`head'`s' Meft" local col = 9 - length("$S_E_depv") di in gr _col(`col') "$S_E_depv |" "`head'" end program define Body version 4.0 local i "`1'" local b "`2'" local V "`3'" local t "`4'" local or "`5'" macro shift 5 local s 2 tempname v local colname : colnames(`b') local coli : word `i' of `colname' local col = 9 - length("`coli'") di in gr _col(`col') "`coli' |" _c if `V'[`i',`i']==0 { if `b'[1,`i']==0 { di in ye " (dropped)" exit } scalar `v' = . } else scalar `v' = `V'[`i',`i'] if "`or'"=="or" { local exp "exp" local eb "exp(`b'[1,`i'])*" } `1' local body : di _s(2) %9.0g `exp'(`b'[1,`i']) _s(3) %9.0g /* */ `eb'sqrt(`v') `1' local s 3 `2' local x : di _s(3) %8.3f `b'[1,`i']/sqrt(`v') /* */ %8.3f tprob($S_E_npsu-$S_E_nstr,`b'[1,`i']/sqrt(`v')) _s(2) `2' local body "`body'`x'" `3' local x : di _s(3) %9.0g `exp'(`b'[1,`i']-`t'*sqrt(`v')) /* */ _s(3) %9.0g `exp'(`b'[1,`i']+`t'*sqrt(`v')) `3' local body "`body'`x'" `4' local x : di _s(`s') %9.0g cond(S_E_deff[1,`i']!=0, /* */ S_E_deff[1,`i'],.) `4' local body "`body'`x'" `4' local s 3 `5' local x : di _s(`s') %9.0g cond(S_E_deft[1,`i']!=0, /* */ S_E_deft[1,`i'],.) `5' local body "`body'`x'" `5' local s 3 `6' local x : di _s(`s') %9.0g cond(S_E_meft[1,`i']!=0, /* */ S_E_meft[1,`i']^2,.) `6' local body "`body'`x'" `6' local s 3 `7' local x : di _s(`s') %9.0g cond(S_E_meft[1,`i']!=0, /* */ S_E_meft[1,`i'],.) `7' local body "`body'`x'" `7' local s 3 di in ye "`body'" end program define Header /* display header */ version 4.0 local wgt "$S_E_wgt" local exp "$S_E_exp" local strata "$S_E_str" local psu "$S_E_psu" if "`wgt'" == "" { local wgt "pweight" } if "`exp'" == "" { local exp "" } if "`strata'" == "" { local strata "" } if "`psu'" == "" { local psu "" } /* Set denominator df for F statistic and other stuff for F display. */ if "$S_E_adj"=="" { /* adjusted (default) */ local df = $S_E_npsu - $S_E_nstr - $S_E_mdf + 1 } else local df = $S_E_npsu - $S_E_nstr if "$S_E_f"=="singular" { local fstat "." } else local fstat "$S_E_f" if `fstat' >= 10000 { local fmtf "g" } else local fmtf "f" /* Set up display for subpop() option obs and size. */ if "$S_E_osub"!="" { if "$S_E_fpc"=="" & "$S_E_r2"=="" { /* print up one line */ local left5a "Subpopulation no. of obs = " local left5b : di %9.0f $S_E_osub local left6a "Subpopulation size =" local left6b : di %10.0g $S_E_nsub } else { local left6a "Subpopulation no. of obs = " local left6b : di %9.0f $S_E_osub local left7a "Subpopulation size =" local left7b : di %10.0g $S_E_nsub } } /* Set up display for R-squared. */ if "$S_E_r2"!="" { local right7a "R-squared = " local right7b : di %9.4f $S_E_r2 } /* Title. */ if "$S_E_cmd"=="svyreg" { di _n in gr "Survey linear regression" _n } else if "$S_E_cmd"=="svylogit" { di _n in gr "Survey logistic regression" _n } else if "$S_E_cmd"=="svyprobt" { di _n in gr "Survey probit regression" _n } /* Print lines 1-4 (see notes at end of file). */ #delimit ; di in gr "`wgt': `exp'" in gr _col(51) "Number of obs" _col(68) "= " in ye %9.0f $S_E_nobs _n in gr "Strata: `strata'" in gr _col(51) "Number of strata" _col(68) "= " in ye %9.0f $S_E_nstr _n in gr "PSU: `psu'" in gr _col(51) "Number of PSUs" _col(68) "= " in ye %9.0f $S_E_npsu ; if "$S_E_fpc"!="" { di in gr "FPC: $S_E_fpc" in gr _col(51) "Population size" _col(68) "=" in ye %10.0g $S_E_npop } ; else di in gr _col(51) "Population size" _col(68) "=" in ye %10.0g $S_E_npop ; /* Print lines 5-7 (see notes at end of file). */ di in gr "`left5a'" in ye "`left5b'" in gr _col(51) "F(" in ye %4.0f $S_E_mdf in gr "," in ye %7.0f `df' in gr ")" _col(68) "= " in ye %9.2`fmtf' `fstat' _n in gr "`left6a'" in ye "`left6b'" in gr _col(51) "Prob > F" _col(68) "= " in ye %9.4f fprob($S_E_mdf,`df',`fstat') ; if "`left7a'`right7a'"!="" { ; di in gr "`left7a'" in ye "`left7b'" in gr _col(51) "`right7a'" in ye "`right7b'" ; } ; di ; end ; exit ; There are 4 possible arrangements for the header: ------------------------------------------------------------------------------ pweight: weight Number of obs = 21 Strata: strata Number of strata = 4 PSU: psu Number of PSUs = 14 FPC: Nh Population size = 189 F( 2, 9) = 3.43 Subpopulation no. of obs = 8 Prob > F = 0.0780 Subpopulation size = 82 R-squared = 0.4129 ------------------------------------------------------------------------------ pweight: weight Number of obs = 21 Strata: strata Number of strata = 4 PSU: psu Number of PSUs = 14 Population size = 189 F( 2, 9) = 3.11 Subpopulation no. of obs = 8 Prob > F = 0.0937 Subpopulation size = 82 R-squared = 0.4129 ------------------------------------------------------------------------------ pweight: weight Number of obs = 21 Strata: strata Number of strata = 4 PSU: psu Number of PSUs = 14 FPC: Nh Population size = 189 F( 2, 9) = 3.43 Subpopulation no. of obs = 8 Prob > F = 0.0780 Subpopulation size = 82 ------------------------------------------------------------------------------ pweight: weight Number of obs = 21 Strata: strata Number of strata = 4 PSU: psu Number of PSUs = 14 Population size = 189 Subpopulation no. of obs = 8 F( 2, 9) = 3.11 Subpopulation size = 82 Prob > F = 0.0937 ------------------------------------------------------------------------------