📄 adjust.ado
字号:
if "`etype'" == "" & `ngen' == 2 {
di in red "`gen2' not allowed since se or stdf not specified"
exit 198
}
ret local ngen "`ngen'"
ret local gen1 "`gen1'"
ret local gen2 "`gen2'"
end
* CheckOpt is passed many of the options and sorts them out to determine what
* will be estimated and what the labels will be. It checks for invalid
* combinations of options and reports an error if found. If the -pr- option
* is specified then CheckOpt determines if it is supported for the estimation
* command and will pass back the name of the subroutine that will compute
* probabilities given xb values. The estimate label, error label, and conf.
* inter. label are also returned. The estimation type "xb" or "pr" or "exp"
* is passed back as well as the error type "stdp", "stdf", or "".
program CheckOpt, rclass
args xb pr exp se stdf ci lab selab cilab ec lev elink
/* Take care of the -xb-, -pr-, and -exp- options */
if "`exp'" != "" { /* -exp- was specified */
if "`xb'" != "" | "`pr'" != "" {
di in red "only one of xb, pr, or exp may be specified"
exit 198
}
ret local esttype "exp"
ret local prprog "PrEXP"
}
else if "`pr'" != "" { /* -pr- was specified --- check if allowed */
if "`xb'" != "" {
di in red "only one of xb, pr, or exp may be specified"
exit 198
}
#delimit ;
if "`ec'" == "blogit" | "`ec'" == "clogit" |
"`ec'" == "glogit" | "`ec'" == "logistic" |
"`ec'" == "logit" | "`ec'" == "svylogit" |
"`ec'" == "xtlogit" { ;
ret local prprog "PrLogit" ;
} ;
else if "`ec'" == "biprobit" | "`ec'" == "bprobit" |
"`ec'" == "dprobit" | "`ec'" == "gprobit" |
"`ec'" == "probit" | "`ec'" == "svyprobit" |
"`ec'" == "xtprobit" { ;
ret local prprog "PrProbit" ;
} ;
else if "`ec'"=="binreg" {;
if "`elink'"=="Identity" {;
ret local prprog "PrIdent" ;
};
else if "`elink'"=="Log" {;
ret local prprog "PrEXP";
};
else if "`elink'"=="Logit" {;
ret local prprog "PrLogit";
};
else if "`elink'"=="Log complement" {;
ret local prprog "PrClog";
};
else {;
di as err
"pr option not allowed after binreg with `elink' link";
};
};
else { ;
di in red "pr option not allowed after `ec' command" ;
exit 198 ;
} ;
#delimit cr
ret local esttype "pr"
}
else { /* if not -pr- or -exp- then has to be -xb- */
ret local esttype "xb"
ret local prprog "*" /* this comments out prprog command */
}
/* Take care of the -se- and -stdf- options --- default is null */
if "`se'" != "" { /* -se- option specified */
if "`stdf'" != "" {
di in red "only one of `se' and `stdf' may be specified"
exit 198
}
if "`return(esttype)'" != "xb" {
di in red "se option only allowed with xb option"
exit 198
}
ret local errtype "stdp"
}
else if "`stdf'" != "" { /* -stdf- option specified */
if "`return(esttype)'" != "xb" {
di in red "stdf option only allowed with xb option"
exit 198
}
tempvar tmp
/* This _predict to see if stdf option is valid */
qui capture _predict `tmp' in 1, stdf
if _rc {
di in red "stdf invalid with `ec' command"
exit 198
}
ret local errtype "stdf"
}
/* Take care of labels */
if `"`lab'"' != "" { /* user specified -label- */
ret local label `"`lab'"'
}
else { /* use default -label- */
if "`return(esttype)'" == "xb" {
ret local label "Linear Prediction"
}
else if "`return(esttype)'" == "pr" {
ret local label "Probability"
}
else if "`return(esttype)'" == "exp" {
ret local label "exp(xb)"
}
}
if `"`selab'"' != "" { /* user specified -selabel- */
if "`return(errtype)'" == "" {
di in red /*
*/ "cannot specify selabel() without se or stdf option"
exit 198
}
ret local selabel `"`selab'"'
}
else { /* use default -selabel- */
if "`return(errtype)'" == "stdp" {
ret local selabel "Standard Error"
}
else if "`return(errtype)'" == "stdf" {
ret local selabel "Standard Error (forecast)"
}
}
if "`ci'" != "" { /* confidence intervals requested */
if `"`cilab'"' != "" { /* user specified -cilabel- */
ret local cilabel `"`=strsubdp("`lev'")'% `cilab'"'
}
else { /* use default -cilabel- */
if "`return(errtype)'" == "stdf" {
ret local cilabel `"`=strsubdp("`lev'")'% Prediction Interval"'
}
else { ret local cilabel `"`=strsubdp("`lev'")'% Confidence Interval"' }
}
}
else { /* no confidence intervals requested */
if `"`cilab'"' != "" {
di in red /*
*/ "cannot specify cilabel() without the ci option"
exit 198
}
}
end
* CheckVar checks that every element of vlist is in blist -- error if not.
* It also checks that there are no repeats in vlist.
program CheckVar /* <vlist> <blist> */
args vlist blist
/* check for repeats in vlist */
Repeats `vlist'
if "`r(replist)'" != "" {
di in red "`r(replist)': specified twice in the varlist"
exit 198
}
/* check vlist is in blist */
Subtract "`vlist'" "`blist'"
if "`r(list)'" != "" {
di in red "`r(list)' -- not used in last estimation"
exit 198
}
end
* DispWrap displays the <first> message followed by a list of the
* <vars> = <vals>. It keeps the output within the <width> of the display
* and each new line is indented <tab> amount. If there are no <vals> then
* just <vars> are output. If there are fewer <vals> then <vars> then the
* last <vars> are output without <vals>.
program DispWrap /* <width> <tab> <first> <vars> [<vals>] */
args width tab first vars vals
local nvar : word count `vars'
local used = length("`first'")
di in gr "`first'" _c
local i 1
while `i' <= `nvar' {
local avar : word `i' of `vars'
local avar = abbrev("`avar'",12)
local aval : word `i' of `vals'
local aval : display `aval'
local chunk = 1 + length("`avar'")
if "`aval'" != "" {
local chunk = `chunk' + 3 + length("`aval'")
}
if `i' != `nvar' { local chunk = `chunk' + 1 }
if (`used'+`chunk') > `width' {
di ""
di _dup(`tab') " " _c
local used = `tab' + `chunk'
}
else { local used = `used' + `chunk' }
di in gr " `avar'" _c
if "`aval'" != "" { di in gr " = `aval'" _c }
if `i' != `nvar' { di in gr "," _c }
local i = `i' + 1
}
di ""
end
* DoTable collapses the data based on the <byvars>. It works with xb <xbvar>
* and either stdf or stdp <evar>. As needed it then transforms (using the
* <prg> subroutine -- if <prg> is * then no transform) the result to what the
* user requested <type> and <etype>. <ci> tells if conf. intervals have been
* requested. <cilab>, <lab>, and <elab> are used as labels for the confidence
* intervals, prediction, and error. Extra tabdisp options are passed in
* <tabopts>. The program displays the created table.
program DoTable
args key byvars xbvar evar lab elab type etype ci cilab lev prg /*
*/ vert tabopts fmt replace
if "`replace'" == "" {
preserve
}
else { /* We are to replace data with table -- need non-tempvars */
capture confirm new var `type'
if _rc == 0 {
rename `xbvar' `type'
local xbvar "`type'"
}
else {
rename `xbvar' _`type'
local xbvar "_`type'"
}
if "`etype'" != "" {
capture confirm new var `etype'
if _rc == 0 {
rename `evar' `etype'
local evar "`etype'"
}
else {
rename `evar' _`etype'
local evar "_`etype'"
}
}
}
local nby : word count `byvars'
/* collapse to one observation per cell of the table */
sort `byvars'
qui by `byvars' : keep if _n==1
/* Take care of confidence interval if requested */
if "`ci'" != "" {
if "`replace'" != "" { /* create non-tempvars for CI */
capture confirm new var lb ub
if _rc == 0 {
local lb "lb"
local ub "ub"
}
else {
local lb "_lb"
local ub "_ub"
}
}
else { /* create tempvars for CI */
tempvar lb ub
}
if e(df_r) >= . { /* use invnorm() for conf. int. */
gen `lb' = `xbvar' - invnorm((100+`lev')/200) * `evar'
gen `ub' = `xbvar' + invnorm((100+`lev')/200) * `evar'
}
else { /* use invt() for conf. int. */
gen `lb' = `xbvar' - invt(e(df_r),`lev'/100) * `evar'
gen `ub' = `xbvar' + invt(e(df_r),`lev'/100) * `evar'
}
/* if pr then transform bounds */
`prg' `lb'
`prg' `ub'
* For -binreg- with log complement link function, switch the `lb' and `ub'
if "`prg'"=="PrClog" {
tempvar a
qui gen `a'=`lb'
qui replace `lb'=`ub'
qui replace `ub'=`a'
}
if `nby' == 1 { /* Put CI side by side for simple table */
tempvar cilb ciub
qui gen str1 `cilb' = ""
qui gen str1 `ciub' = ""
local i 1
while `i' <= _N {
local lbs : di `fmt' `lb'[`i']
local ubs : di `fmt' `ub'[`i']
qui replace `cilb' = "[" + trim("`lbs'") /*
*/ in `i' if `lb'<. & `ub'<.
qui replace `ciub' = trim("`ubs'") + "]" /*
*/ in `i' if `lb'<. & `ub'<.
local i = `i' + 1
}
local short3a "lb"
local short3b "ub"
label var `cilb' "`short3a'"
label var `ciub' "`short3b'"
local cell "`cilb' `ciub'"
}
else if "`vert'" == "" { /* no stacking of CIs */
tempvar cis
qui gen str1 `cis' = ""
local i 1
while `i' <= _N {
local lbs : di `fmt' `lb'[`i']
local ubs : di `fmt' `ub'[`i']
qui replace `cis' = "[" + trim("`lbs'") + "," /*
*/ + trim("`ubs'") + "]" in `i' /*
*/ if `lb'<. & `ub'<.
local i = `i' + 1
}
local cell "`cis'"
}
else { /* CIs are to be stacked */
tempvar cilb ciub
qui gen str1 `cilb' = ""
qui gen str1 `ciub' = ""
local i 1
while `i' <= _N {
local lbs : di `fmt' `lb'[`i']
local ubs : di `fmt' `ub'[`i']
qui replace `cilb' = "[" + trim("`lbs'")+"," /*
*/ in `i' if `lb'<. & `ub'<.
qui replace `ciub' = trim("`ubs'") + "]" /*
*/ in `i' if `lb'<. & `ub'<.
local i = `i' + 1
}
local cell "`cilb' `ciub'"
}
}
/* take care of prediction --- get into display format */
`prg' `xbvar' /* transform xbvar if -pr- or -exp- */
tempvar sxb
qui gen str1 `sxb' = ""
local i 1
while `i' <= _N {
local tmps : di `fmt' `xbvar'[`i']
qui replace `sxb' = trim("`tmps'") in `i' if `xbvar'<.
local i = `i' + 1
}
if "`type'" == "xb" { local short1 "xb" }
else if "`type'" == "pr" { local short1 "pr" }
else if "`type'" == "exp" { local short1 "exp(xb)" }
label var `sxb' "`short1'"
/* take care of error --- get into display format */
if "`etype'" != "" {
tempvar sevar
qui gen str1 `sevar' = ""
local i 1
while `i' <= _N {
local tmps : di `fmt' `evar'[`i']
qui replace `sevar' = "("+trim("`tmps'")+")" in `i' /*
*/ if `evar'<.
local i = `i' + 1
}
if "`etype'" == "stdp" { local short2 "stdp" }
else if "`etype'" == "stdf" { local short2 "stdf" }
label var `sevar' "`short2'"
}
/* finish building the cell variable list */
local cell "`sxb' `sevar' `cell'"
/* now we create the table */
tokenize "`byvars'"
if `nby' > 3 {
tabdisp `1' `2' `3', c(`cell') by(`4' `5' `6' `7') `tabopts'
}
else {
tabdisp `1' `2' `3', c(`cell') `tabopts'
}
/* add key to bottom of table */
if "`key'" != "nokey" {
if `nby' > 1 {
di in gr " Key: `lab'"
if "`etype'" != "" { di in gr " (`elab')" }
if "`ci'" != "" { di in gr " [`cilab']" }
}
else {
local spot = length("`short1'")
if "`etype'" != "" {
local tmpsp = length("`short2'")
if `tmpsp' > `spot' {
local spot `tmpsp'
}
}
if "`ci'" != "" {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -