*! version 1.0.2 24apr1996 program define svy_disp /* display results */ version 4.0 local options "Level(int $S_level) CI DEFF DEFT MEFF MEFT OBS SIZE" parse "`*'" if `level' < 10 | `level' > 99 { local level 95 } if "`ci'`deff'`deft'`meff'`meft'`obs'`size'"=="" { local ci "ci" local deff "deff" } local count 2 if "`ci'"!="" { local CI " " local count 4 } else local CI "*" if "`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 "*" if "`obs'"!="" & `count' < 5 { local obs local OBS " " local count = `count' + 1 } else local OBS "*" if "`size'"!="" & `count' < 5 { local size local SIZE " " local count = `count' + 1 } else local SIZE "*" /* Get estimates. */ tempname t capture di matrix(S_E_b[1,1]) if _rc==0 { local b "S_E_b" local V "S_E_V" } else { tempname b V matrix `b' = get(_b) matrix `V' = get(VCE) scalar `t' = invt($S_E_npsu - $S_E_nstr, `level'/100) } local dim = colsof(`b') /* Print out header. */ Header /* Print out column headers of table 1. */ DashLine Colhead `level' " " "`CI'" "`DEFF'" "`DEFT'" /* */ "`MEFF'" "`MEFT'" "`OBS'" "`SIZE'" /* Print out body of table 1. */ local i 1 while `i' <= `dim' { LeftBody `i' `b' Body `i' `b' `V' `t' `level' " " "`CI'" "`DEFF'" "`DEFT'" /* */ "`MEFF'" "`MEFT'" "`OBS'" "`SIZE'" local i = `i' + 1 } DashLine /* See if there is more to print out. */ if "`deft'`meff'`meft'`obs'`size'"=="" { FootNote exit } /* If here, we need to print out another table. */ 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' * * * "`DEFT'" "`MEFF'" "`MEFT'" "`OBS'" "`SIZE'" /* Print out body of table 2. */ local i 1 while `i' <= `dim' { LeftBody `i' `b' Body `i' `b' `V' `t' `level' * * * "`DEFT'" /* */ "`MEFF'" "`MEFT'" "`OBS'" "`SIZE'" 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_miss"!="" { di } } if "$S_E_miss"!="" { di in blu "(*) Some variables contain missing values." } 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 "" } if "$S_E_cmd"=="svymean" { di _n in gr "Survey mean estimation" _n } else if "$S_E_cmd"=="svytotal" { di _n in gr "Survey total estimation" _n } else if "$S_E_cmd"=="svyratio" { di _n in gr "Survey ratio estimation" _n } if "$S_E_miss"!="" { local fnote "(*)" } #delimit ; di in gr "`wgt':" _col(11) "`exp'" in gr _col(51) "Number of obs`fnote'" _col(68) "= " in ye %9.0f $S_E_nobs _n in gr "Strata:" _col(11) "`strata'" in gr _col(51) "Number of strata" _col(68) "= " in ye %9.0f $S_E_nstr _n in gr "PSU:" _col(11) "`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:" _col(11) "$S_E_fpc" in gr _col(51) "Population size" _col(68) "=" in ye %10.0g $S_E_npop ; if "$S_E_sub"!="" { ; di in gr "Subpop.:" _col(11) "$S_E_sub" _n ; } ; else di ; } ; else { ; if "$S_E_sub"!="" { ; di in gr "Subpop.:" _col(11) "$S_E_sub" _col(51) "Population size" _col(68) "=" in ye %10.0g $S_E_npop _n ; } ; else di in gr _col(51) "Population size" _col(68) "=" in ye %10.0g $S_E_npop _n ; } ; #delimit cr end program define Colhead version 4.0 local level "`1'" macro shift LeftCol local head "$S_2 |" global S_2 /* erase macro */ `1' local head "`head' Estimate" `1' local head "`head' Std. Err." `2' local head "`head'`s' [`level'% Conf. Interval]" `2' local s " " `3' local head "`head'`s' Deff" `3' local s " " `4' local head "`head'`s' Deft" `4' local s " " `5' local head "`head'`s' Meff" `5' local s " " `6' local head "`head'`s' Meft" `6' local s " " `7' local head "`head'`s' Obs" `7' local s " " `8' local head "`head'`s' Pop. Size" di in gr "`head'" end program define LeftCol version 4.0 if "$S_E_by"=="" { global S_1 10 /* column of vertical line */ if "$S_E_cmd"=="svymean" { global S_2 " Mean" exit } if "$S_E_cmd"=="svytotal" { global S_2 " Total" exit } if "$S_E_cmd"=="svyratio" { global S_1 19 global S_2 " Ratio " exit } } /* If here, we have subpops. */ if "$S_E_cmd"=="svymean" { local name "Mean" } else if "$S_E_cmd"=="svytotal" { local name "Total" } else if "$S_E_cmd"=="svyratio" { local name "Ratio" } local nbyvar : word count $S_E_by if ("$S_E_lab"!="" & `nbyvar' == 2) | "$S_E_cmd"=="svyratio" { global S_1 19 } else global S_1 16 local col = $S_1 - 8 global S_2 : di "`name'" _col(`col') "Subpop." end program define Body version 4.0 local i "`1'" local b "`2'" local V "`3'" local t "`4'" local level "`5'" macro shift 5 local s 2 if S_E_err[1,`i'] > 0 { if S_E_err[1,`i']==1 { di in ye " (no observations)" } else if S_E_err[1,`i']==2 { di in ye " (stratum with 1 PSU detected)" } else if S_E_err[1,`i']==3 { di in ye " (sum of weights equals zero)" } else if S_E_err[1,`i']==4 { di in ye " (denominator estimate equals zero)" } exit } if "`b'"=="S_E_b" { scalar `t' = invt(S_E_npsu[1,`i'] - S_E_nstr[1,`i'], /* */ `level'/100) local j 1 } else local j `i' `1' if `b'[1,`i'] < 1e7 { `1' local body : di _s(2) %9.0g `b'[1,`i'] /* `1' */ _s(3) %9.0g sqrt(`V'[`j',`i']) `1' } `1' else { `1' local body : di _s(1) %10.0g `b'[1,`i'] /* `1' */ _s(3) %9.0g sqrt(`V'[`j',`i']) `1' } `1' local s 3 `2' local x : di _s(3) %9.0g `b'[1,`i']-`t'*sqrt(`V'[`j',`i']) /* */ _s(3) %9.0g `b'[1,`i']+`t'*sqrt(`V'[`j',`i']) `2' local body "`body'`x'" `3' local x : di _s(3) %9.0g cond(S_E_deff[1,`i']!=0,S_E_deff[1,`i'],.) `3' local body "`body'`x'" `4' local x : di _s(`s') %9.0g cond(S_E_deft[1,`i']!=0, /* */ S_E_deft[1,`i'],.) `4' local body "`body'`x'" `4' local s 3 `5' local x : di _s(`s') %9.0g cond(S_E_meft[1,`i']!=0, /* */ S_E_meft[1,`i']^2,.) `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'],.) `6' local body "`body'`x'" `6' local s 3 `7' local x : di _s(`s') %9.0g S_E_nobs[1,`i'] `7' local body "`body'`x'" `7' local s 3 `8' if S_E_npop[1,`i'] < 1e7 { `8' local x : di _s(`s') %9.0g S_E_npop[1,`i'] `8' } `8' else { `8' local s = `s' - 1 `8' local x : di _s(`s') %10.0g S_E_npop[1,`i'] `8' } `8' local body "`body'`x'" di in ye "`body'" end program define LeftBody version 4.0 local i "`1'" local b "`2'" local colname : colnames(`b') local coli : word `i' of `colname' if "$S_E_by"=="" { if `i'==1 { DashLine $S_1 } if "$S_E_cmd"!="svyratio" { local col = $S_1 - 1 - length("`coli'") di in gr _col(`col') "`coli' |" _c exit } local eqname : coleq(`b') local eqi : word `i' of `eqname' local col = 9 - length("`eqi'") di in gr _col(`col') "`eqi'/`coli'" _col($S_1) "|" _c exit } /* If here, we have subpops. */ if mod(`i'-1, $S_E_nby) == 0 { /* print line, then varname */ DashLine $S_1 if "$S_E_cmd"=="svyratio" { local k = int((`i'-1)/$S_E_nby) + 1 local numi : word `k' of $S_E_vl local k = `k' + 1 local deni : word `k' of $S_E_vl di in gr "`numi'/`deni'" _col($S_1) "|" } else { local eqname : coleq(`b') local eqi : word `i' of `eqname' di in gr "`eqi'" _col($S_1) "|" } } local nbyvar : word count $S_E_by if "$S_E_lab"!="" & `nbyvar'==2 { /* two labels */ local j = 2*mod(`i'-1, $S_E_nby) + 1 local word1 : word `j' of $S_E_lab local col1 = $S_1 - 10 - length("`word1'") local j = `j' + 1 local word2 : word `j' of $S_E_lab local col2 = $S_1 - 1 - length("`word2'") di in gr _col(`col1') "`word1'" _col(`col2') "`word2' |" _c exit } if "$S_E_lab"=="" & `nbyvar'==1 { local coli "$S_E_by==`coli'" } local col = $S_1 - 1 - length("`coli'") di in gr _col(`col') "`coli' |" _c end