📄 adjust.ado
字号:
local tmpsp = length("[`short3a' , `short3b']")
if `tmpsp' > `spot' {
local spot `tmpsp'
}
}
local spot = `spot' + 14
di in gr " Key: `short1'" _col(`spot') "= `lab'"
if "`etype'" != "" {
di in gr " `short2'" _col(`spot') /*
*/ "= `elab'"
}
if "`ci'" != "" {
di in gr " [`short3a' , `short3b']" /*
*/ _col(`spot') "= [`cilab']"
}
}
}
if "`replace'" != "" {
label var `xbvar' "`lab'"
if "`etype'" != "" { label var `evar' "`elab'" }
if "`ci'" != "" {
label var `lb' "l.b. of `cilab'"
label var `ub' "u.b. of `cilab'"
}
qui compress
}
end
* GetbName gets the names off of the b vector deleting the _cons name and
* any other troublesome names (like _se for tobit). The names from -[m]anova-
* are handled differently. If the second argument is present then we restrict
* ourselves to that equation. We return the names in r(names).
program GetbName /* <cmdname> <eqname or null> */ , rclass
args cmdname eqname
if "`cmdname'" == "anova" {
local bnames "`e(varnames)'"
}
else if "`cmdname'" == "manova" {
local bnames "`e(indepvars)'"
}
else {
tempname b
matrix `b' = e(b)
if "`eqname'" != "" {
matrix `b' = `b'[1...,`"`eqname':"']
}
local bnames : colnames(`b')
/* remove troublesome names from beta vector */
Subtract "`bnames'" "_cons _se"
Substub "`r(list)'" "_cut" /* remove _cut# */
tsrevar `r(list)' , list /* remove time-series operators */
local bnames "`r(varlist)'"
}
ret local names "`bnames'"
end
* Header displays preliminary information before the table is displayed
program Header
args genvars asis by covars covals thevals depv eqname cmd
/*
genvars --- names of generated variables
asis --- names of variables left as is
by --- names of the by variables
covars --- names of the covariates that were set
covals --- values covars were set to or the word "mean"
thevals --- values covars were set to
depv --- name of dependent variable or empty
eqname --- name of equation or empty
cmd --- estimation command name
*/
local nby : word count `by'
local ncov : word count `covars'
local ngen : word count `genvars'
local nasis : word count `asis'
local width : set display linesize /* allowed width for header */
local tab 24 /* length of header second line indenting */
local smtab 5 /* a small tab */
di _n in smcl in gr "{hline `width'}"
/* Display the dependent variable name or equation name (if any) */
if "`depv'" != "" {
di in gr " Dependent variable: " abbrev("`depv'",12) /*
*/ _dup(`smtab') " " _c
}
else {
if "`eqname'" != "" {
di in gr _dup(15) " " _c
}
else {
di in gr _dup(16) " " _c
}
}
if "`eqname'" != "" {
di in gr "Equation: `eqname'" _dup(`smtab') " " "Command: `cmd'"
}
else {
di in gr "Command: `cmd'"
}
/* Display generated variables (if any) */
if `ngen' == 1 {
DispWrap "`width'" "`tab'" " Created variable:" /*
*/ "`genvars'"
}
else if `ngen' > 1 {
DispWrap "`width'" "`tab'" " Created variables:" /*
*/ "`genvars'"
}
/* Display as is variables (if any) */
if `nasis' == 1 {
DispWrap "`width'" "`tab'" " Variable left as is:" "`asis'"
}
else if `nasis' > 1 {
DispWrap "`width'" "`tab'" " Variables left as is:" "`asis'"
}
/* split covars and thevals into those set to mean and other */
local i 1
while `i' <= `ncov' {
local tmpval : word `i' of `covals'
local tmpthe : word `i' of `thevals'
local tmpvar : word `i' of `covars'
if "`tmpval'" == "mean" {
local mvars "`mvars' `tmpvar'"
local mvals "`mvals' `tmpthe'"
}
else {
local ovars "`ovars' `tmpvar'"
local ovals "`ovals' `tmpthe'"
}
local i = `i' + 1
}
local nmvars : word count `mvars'
local novars : word count `ovars'
/* Display the covariates and values they were set to */
if `nmvars' == 1 {
DispWrap "`width'" "`tab'" " Covariate set to mean:" /*
*/ "`mvars'" "`mvals'"
}
else if `nmvars' > 1 {
DispWrap "`width'" "`tab'" " Covariates set to mean:" /*
*/ "`mvars'" "`mvals'"
}
if `novars' == 1 {
DispWrap "`width'" "`tab'" " Covariate set to value:" /*
*/ "`ovars'" "`ovals'"
}
else if `novars' > 1 {
DispWrap "`width'" "`tab'" "Covariates set to value:" /*
*/ "`ovars'" "`ovals'"
}
di in smcl in gr "{hline `width'}"
end
* ParseVar parses the var[= #][var[= #]...] syntax and returns the variable
* names in s(vnames) and the values (or the word "mean") in s(values). It
* will handle the * and - expansions.
program ParseVar /* <varlist> */ , sclass
tokenize "`*'", parse(" =-*")
local i 1
while "``i''" != "" {
if "``i''" == "=" | "``i''" == "-" | "``i''" == "*" {
di in red "``i'' used improperly in varlist"
exit 198
}
local j = `i' + 1
if "``j''" == "*" { /* * expansions */
local k = `j' + 1
if "``k''" == "-" { /* * expansion with - */
local m = `k' + 1
unab tmpvar : ``i''``j''``k''``m''
local varlist "`varlist' `tmpvar'"
local temp : word count `tmpvar'
local h 1
while `h' <= `temp' {
local vallist "`vallist' mean"
local h = `h' + 1
}
local i = `i' + 4
}
else { /* * expansion without - */
unab tmpvar : ``i''``j''
local varlist "`varlist' `tmpvar'"
local temp : word count `tmpvar'
local h 1
while `h' <= `temp' {
local vallist "`vallist' mean"
local h = `h' + 1
}
local i = `i' + 2
}
}
else if "``j''" == "-" { /* - expansion */
local k = `j' + 1
unab tmpvar : ``i''``j''``k''
local varlist "`varlist' `tmpvar'"
local temp : word count `tmpvar'
local h 1
while `h' <= `temp' {
local vallist "`vallist' mean"
local h = `h' + 1
}
local i = `i' + 3
}
else { /* no * or - expansion */
unab tmpvar : ``i''
local varlist "`varlist' `tmpvar'"
if "``j''" == "=" { /* var=# syntax */
local k = `j' + 1
if "``k''" == "-" { /* negative sign */
local neg "-"
local k = `k' + 1
local i = `i' + 1
}
else { /* no negative sign */
local neg
}
capture noi confirm number `neg'``k''
if _rc != 0 {
di in red /*
*/ "only numbers allowed in var = # form of varlist"
exit _rc
}
local vallist "`vallist' `neg'``k''"
local i = `i' + 3
}
else { /* no *, -, or = */
local vallist "`vallist' mean"
local i = `i' + 1
}
}
}
sret local vnames "`varlist'"
sret local values "`vallist'"
end
* Repeats checks for repeated terms in <vlist> and returns a list of the
* repeated terms in r(replist)
program Repeats /* <vlist> */ , rclass
local vlen : word count `*'
local i 1
while `i' < `vlen' {
local j = `i' + 1
while `j' <= `vlen' {
if "``i''" == "``j''" {
local reps "`reps' ``i''"
local j = `vlen'
}
local j = `j' + 1
}
local i = `i' + 1
}
ret local replist "`reps'"
end
* SetCovs sets the <vars> to equal the values in <vals> or their mean
* if <vals> says "mean". It returns the vals (with the means replaced
* by actual values) in r(values)
program SetCovs /* <vars> <vals> */ , rclass
args covars covals
local ncov : word count `covars'
local i 1
tempvar tmpmean
gen `tmpmean' = 0
while `i' <= `ncov' {
local covari : word `i' of `covars'
local covali : word `i' of `covals'
if "`covali'" == "mean" {
qui replace `tmpmean' = sum(`covari')/_N
/* divide by _N ok because dropped missing values */
qui replace `covari' = `tmpmean'[_N]
local amean = `tmpmean'[_N]
local coval2 "`coval2' `amean'"
}
else {
qui replace `covari' = `covali'
local coval2 "`coval2' `covali'"
}
local i = `i' + 1
}
ret local values "`coval2'"
end
* SplitIt splits the command into two parts corresponding to the non-standard
* varlist part (returned in s(part1)) and the remaining part that is allowed
* to have the [if exp] [in range], options stuff (returned in s(part2)).
program SplitIt, sclass
tokenize "`*'", parse(" ,")
local i 1
while "``i''"!="," & "``i''"!="if" & "``i''"!="in" & "``i''"!="" {
local com "`com' ``i''"
local i = `i' + 1
}
while "``i''" != "" {
local opt "`opt' ``i''"
local i = `i' + 1
}
sret local part1 "`com'"
sret local part2 "`opt'"
end
* Subtract removes the tokens in elist from flist and returns the
* "cleaned" flist in r(list).
program Subtract /* <flist> <elist> */ , rclass
args flist elist
local nelist : word count `elist'
tokenize `flist'
local i 1
while "``i''" != "" {
local j 1
while `j' <= `nelist' {
local eword : word `j' of `elist'
local j = `j' + 1
if "`eword'" == "``i''" {
local `i' " "
local j = `nelist' + 1
}
}
local i = `i' + 1
}
ret local list `*'
end
* Substub removes any tokens in flist that begin with the tokens in elist
* and returns the "cleaned" flist in r(list).
program Substub /* <flist> <elist> */ , rclass
args flist elist
local nelist : word count `elist'
tokenize "`flist'"
local i 1
while "``i''" != "" {
local j 1
while `j' <= `nelist' {
local eword : word `j' of `elist'
local j = `j' + 1
if "`eword'" == substr("``i''",1,length("`eword'")) {
local `i' " "
local j = `nelist' + 1
}
}
local i = `i' + 1
}
ret local list `*'
end
* PrEXP replaces the variable sent in (first argument) from an xb value to an
* exp(xb) value. Depending on the estimation model this transformation has
* different names (hazard ratio, incidence rate, count, ...).
program PrEXP
qui replace `1' = exp(`1')
end
* PrLogit replaces the variable sent in (first argument) from an xb value to a
* probability according to the logit transformation.
program PrLogit
qui replace `1' = exp(`1')/(1+exp(`1'))
end
* PrProbit replaces the variable sent in (first argument) from an xb value to
* a probability according to the probit transformation.
program PrProbit
qui replace `1' = normprob(`1')
end
* PrClog replaces the variable sent in (first argument) from an xb value to a
* probability according to the log complement transformation
* (used in -binreg- with -hr-).
program PrClog
qui replace `1'=1-exp(`1')
end
*PrIdent replaces the variable sent in (first argument) from an xb value to a
* probability according to the identical transformation
* (used in -binreg- with -rd-).
program PrIdent
/* qui replace `1'=`1' */
exit /* do nothing */
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -