📄 _sum_table.ado
字号:
*! version 1.0.5 01apr2005
program _sum_table
version 9
if "`e(cmd)'" == "" {
error 301
}
syntax [, Level(cilevel) ]
is_svysum `e(cmd)'
if !r(is_svysum) {
error 301
}
// get equation names
local coleq : coleq e(b), quote
local coleq : list clean coleq
local coleq : list uniq coleq
Chk4Scalars k_eq
// check for total number of equations
local k_eq 0
Chk4PosInt k_eq
if `k_eq' == 0 {
local k_eq : word count `coleq'
}
else if `k_eq' > `:word count `coleq'' {
di as err ///
"estimation command error: e(k_eq) is larger than the number of equations"
exit 322
}
local df_r .
Chk4Int df_r
tempname error
matrix `error' = e(error)
local erropt error(`error')
tempname z
if missing(`df_r') {
scalar `z' = invnorm((100+`level')/200)
}
else scalar `z' = invttail(`df_r',(100-`level')/200)
tempname Tab
.`Tab' = ._tab.new, col(5) lmargin(0) ignore(.b)
// column 1 2 3 4 5
.`Tab'.width 13 |11 11 14 12
.`Tab'.titlefmt . %11s %12s %25s .
.`Tab'.strfmt . %11s . . .
.`Tab'.pad . 2 2 5 3
.`Tab'.numfmt . %9.0g %9.0g %9.0g %9.0g
.`Tab'.strcolor . result . . .
// NOTE: Changing any of the above values will be reflected in
// the ColumnTitles subroutine. This may also affect
// _coef_table_header.ado also.
if "`e(clustvar)'" != "" {
local clustvar = abbrev("`e(clustvar)'",12)
di as txt ///
"{ralign 60:(standard errors adjusted for clustering on `clustvar')}"
}
ColumnTitles `Tab' `level' `df_r'
DisplayEqns `coleq' : `Tab', l(`level') df(`df_r') z(`z') `erropt'
.`Tab'.sep, bottom
end
program ColumnTitles
args Tab level df
is_svysum `e(cmd)'
local is_sum = r(is_svysum)
if "`e(over)'" != "" {
local depvar "Over"
}
local sum = proper("`e(cmd)'")
if missing(`df') {
local stat z
}
else local stat t
.`Tab'.sep, top
if `"`e(vcetype)'"' != "" | "`e(cmd)'" == "proportion" {
local vcetype `"`e(vcetype)'"'
if "`e(vcetype)'" == "Bootstrap" {
local obs "Observed"
local citype "Normal-based"
}
else if "`e(cmd)'" == "proportion" {
local citype "Binomial Wald"
}
local ciwd : length local citype
local vcewd : length local vcetype
if `"`e(mse)'"' != "" {
capture which `e(vce)'_`e(mse)'.hlp
if !c(rc) {
local vcetype ///
"{help `e(vce)'_`e(mse)'##|_new:`vcetype'}"
local plus = `: length local vcetype' - `vcewd'
local plus "+`plus'"
}
}
if `vcewd' <= 12 {
// NOTE: see the width and pad definitions of .`Tab'
local vcewd = `vcewd'`plus' + ceil((12-`vcewd')/2+1)
}
if `ciwd' < 26 {
// NOTE: see the width and pad definitions of .`Tab'
local ciwd = 2 + `ciwd' + ceil((26-`ciwd')/2)
}
// column 1 2 3 4 5
.`Tab'.titlefmt . . %`vcewd's %`ciwd's .
.`Tab'.titles "" "`obs'" `" `vcetype'"' "`citype'" ""
.`Tab'.titlefmt . . %12s %25s .
}
local ConfInt `"[`=strsubdp("`level'")'% Conf. Interval]"'
.`Tab'.titles "`depvar'" /// 1
"`sum'" /// 2
"Std. Err." /// 3
"`ConfInt'" "" // 4 5
end
program MLineTSop
args c_op c_dv c_n COLON op vn
local n 1
// operator fits on a line by itself
if `:length local op' < 12 {
c_local `c_op'1 `"`op'."'
local vn = abbrev(`"`vn'"',12)
c_local `c_dv' `"`vn'"'
c_local `c_n' `n'
exit
}
c_local `c_op'`n' = substr(`"`op'"',1,12)
local op = substr(`"`op'"',13,.)
while `:length local op' >= 12 {
local ++n
c_local `c_op'`n' = substr(`"`op'"',1,12)
local op = substr(`"`op'"',13,.)
}
if `"`op'"' == "" {
local vn = abbrev(`"`vn'"', 12)
c_local `c_dv' `"`vn'"'
}
else {
local rest `"`op'.`vn'"'
if `:length local rest' <= 12 {
c_local `c_dv' `"`rest'"'
}
else {
local ++n
c_local `c_op'`n' `"`op'."'
local vn = abbrev(`"`vn'"', 12)
c_local `c_dv' `"`vn'"'
}
}
c_local `c_n' `n'
end
program DisplayEqns
_on_colon_parse `0'
local eqlist `"`s(before)'"'
if (`: word count `eqlist'' == 0) exit
local 0 `s(after)'
syntax name(name=Tab) [, ///
First ///
EForm(passthru) ///
ERRormat(name) ///
* ///
]
local coleq : coleq e(b), quote
local coleq : list clean coleq
local colna : colna e(b)
local neq : word count `coleq'
// index of first element
local ucoleq : list uniq coleq
local start : list posof "`:word 1 of `eqlist''" in coleq
// loop through the sumficients, displaying those that belong to the
// specified equations
local i `start'
local oldeq // start fresh
while `i' <= `neq' {
local eq : word `i' of `coleq'
local qeq `""`eq'""'
// exit if the current equation is not in the list
local break = (!`:list eq in eqlist' & !`:list qeq in eqlist')
if (`break') continue, break
local na : word `i' of `colna'
if `"`eq'"' != `"`oldeq'"' {
.`Tab'.sep
if "`first'" == "" & `"`eq'"' != "_" {
local abeq = abbrev(`"`eq'"',12)
// columns 1 2 3 4 5
.`Tab'.strcolor result . . . .
.`Tab'.strfmt %-12s . . . .
.`Tab'.row `"`abeq'"' "" "" "" ""
.`Tab'.strcolor text . . . .
.`Tab'.strfmt %12s . . . .
}
local oldeq `"`eq'"'
}
gettoken op vn : na, parse(".")
if "`vn'" != "" & ".`oldvn'" != "`vn'" {
local vn = abbrev(substr("`vn'",2,.),12)
// columns 1 2 3 4 5
.`Tab'.row `"`vn'"' "" "" "" ""
local oldvn `vn'
}
else if "`vn'" == "" {
local oldvn
}
if "`errormat'" != "" {
local erropt error(`=`errormat'[1,`i']')
}
Row `Tab' `"`qeq'"' "`na'", `options' `eform' `erropt'
local ++i
}
end
program Row
syntax anything [, ///
Level(cilevel) ///
ERRor(integer 0) ///
df(real 0) ///
z(name) ///
]
local 0 `anything'
args Tab eq na
local eq : list clean eq
tempname b se ll ul
if `"`eq'"' != "_" {
scalar `b' = [`eq']_b[`na']
scalar `se' = [`eq']_se[`na']
}
else {
scalar `b' = _b[`na']
scalar `se' = _se[`na']
}
if `se' == 0 & `"`e(census)'"' == "1" {
scalar `ll' = .
scalar `ul' = .
}
else {
if `se' == 0 {
scalar `se' = .
}
scalar `ll' = `b' - `se'*`z'
scalar `ul' = `b' + `se'*`z'
}
gettoken op vn : na, parse(".")
if "`vn'" != "" {
if `:length local op' == 1 {
local op `op'1
}
local na `"`op'."'
while `:length local na' > 12 {
.`Tab'.strfmt %11s . . . .
local n1 = substr("`na'",1,10)
.`Tab'.row "`n1'" "" "" "" ""
local na = substr("`na'",11,.)
}
.`Tab'.strfmt %12s . . . .
}
else local na = abbrev("`na'",12)
local error1 " (no observations)"
local error2 " (stratum with 1 PSU detected)"
local error3 " (sum of weights equals zero)"
local error4 " (denominator estimate equals zero)"
local error5 " (dropped)"
if `error' {
.`Tab'.row "`na'" "`error`error''" "" "" ""
}
else if `b'== 0 & `se' >= . {
.`Tab'.row "`na'" "`error5'" "" "" ""
}
else {
.`Tab'.row "`na'" `b' `se' `ll' `ul'
}
end
program GetEDiparm
args c_diparm
if `"`e(diparm)'`e(diparm1)'"' != "" {
if `"`e(diparm)'"' != "" {
local i 0
local ediparmi `"`e(diparm)'"'
}
else if `"`e(diparm1)'"' != "" {
local i 1
local ediparmi `"`e(diparm1)'"'
}
}
while `"`ediparmi'"' != "" {
local diparm `diparm' diparm(`ediparmi')
local ++i
local ediparmi `"`e(diparm`i')'"'
}
c_local `c_diparm' `diparm'
end
program Chk4Scalars
syntax namelist
local nonscalars `: r(macros)' `: r(matrices)'
local badmac : list nonscalars & namelist
if "`badmac'" != "" {
gettoken name : badmac
di as err "type mismatch: e(`name') is not a scalar"
exit 109
}
end
program Chk4PosInt
args ename
if `"`e(`ename')'"' != "" {
capture confirm integer number `e(`ename')'
if !c(rc) {
if `e(`ename')' > 0 {
c_local `ename' `e(`ename')'
}
}
}
end
program Chk4NNInt
args ename
if `"`e(`ename')'"' != "" {
capture confirm integer number `e(`ename')'
if !c(rc) {
if `e(`ename')' >= 0 {
c_local `ename' `e(`ename')'
}
}
}
end
program Chk4Int
args ename
if `"`e(`ename')'"' != "" {
capture confirm integer number `e(`ename')'
if !c(rc) {
c_local `ename' `e(`ename')'
}
}
end
exit
NOTES:
-_sum_table- looks at the following scalars to determine which equations are
put in the table of results, and how they are put there:
e(k_eq) -- total number of equations, missing value implies 1
e(k_extra) -- extra equations
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -