📄 avplot.ado
字号:
*! version 3.4.2 07mar2005
program define avplot, rclass
version 6
if _caller() < 8 {
avplot_7 `0'
return add
exit
}
_isfit cons
syntax varname [, * ]
_get_gropts , graphopts(`options') getallowed(RLOPts plot addplot)
local options `"`s(graphopts)'"'
local rlopts `"`s(rlopts)'"'
local plot `"`s(plot)'"'
local addplot `"`s(addplot)'"'
_check4gropts rlopts, opt(`rlopts')
local v `varlist'
local wgt "[`e(wtype)' `e(wexp)']"
tempvar touse resid lest evx hat
/* determine if v in original varlist */
if "`e(depvar)'"=="`1'" {
di in red "cannot include dependent variable"
exit 398
}
local lhs "`e(depvar)'"
if "`e(vcetype)'"=="Robust" {
local robust="robust"
}
_getrhs rhs
gen byte `touse' = e(sample)
if "`e(clustvar)'"~="" {
tempname myest
local cluster="cluster(`e(clustvar)')"
estimates hold `myest'
qui regress `lhs' `rhs' if `touse', `robust'
local ddof= e(df_r)
estimates unhold `myest'
}
else {
local ddof= e(df_r)
}
tokenize `rhs'
local i 1
while "``i''"!="" & "`inorig'"=="" {
if "``i''"=="`v'" {
local inorig "true"
local `i' " " /* zap it */
}
local i=`i'+1
}
quietly {
_predict `resid' if `touse', resid
}
if "`inorig'"=="" { /* not originally in */
capture assert `v'!=. if `touse'
if _rc {
di in red "`v' has missing values" _n /*
*/ "you must reestimate including `v'"
exit 398
}
estimate hold `lest'
capture {
regress `v' `rhs' `wgt' if `touse', ///
`robust' `cluster'
_predict `evx' if `touse', resid
regress `resid' `evx' `wgt' if `touse', ///
`robust' `cluster'
ret scalar coef = _b[`evx']
_predict `hat' if `touse'
regress `lhs' `v' `rhs' `wgt' if `touse', ///
`robust' `cluster'
ret scalar se = _se[`v']
}
local rc=_rc
}
else { /* originally in */
drop `resid'
if _b[`v']==0 {
di in gr "(`v' was dropped from model)"
exit 399
}
estimate hold `lest'
capture {
regress `lhs' `*' `wgt' if `touse', ///
`robust' `cluster'
_predict double `resid' if `touse', resid
regress `v' `*' `wgt' if `touse', ///
`robust' `cluster'
_predict double `evx' if `touse', resid
regress `resid' `evx' `wgt' if `touse', ///
`robust' `cluster'
ret scalar coef = _b[`evx']
local seevx=_se[`evx']
_predict double `hat' if `touse'
regress `lhs' `rhs' `wgt' if `touse', ///
`robust' `cluster'
ret scalar se = _se[`v']
}
local rc=_rc
}
estimate unhold `lest'
if `rc' { error `rc' }
/* double save in S_# */
global S_1 = return(coef)
global S_2 = return(se)
version 2.1
local t = round(return(coef)/return(se),.01)
local coef=return(coef)
local se=return(se)
version 6
if "`robust'"=="robust" {
local note "coef = `coef', (robust) se = `se', t = `t'"
}
else {
local note "coef = `coef', se = `se', t = `t'"
}
label var `resid' "e( `lhs' | X )"
local yttl : var label `resid'
label var `evx' "e( `v' | X )"
local xttl : var label `evx'
if `"`plot'`addplot'"' == "" {
local legend legend(nodraw)
}
version 8: graph twoway ///
(scatter `resid' `evx' ///
if `touse', ///
sort ///
ytitle(`"`yttl'"') ///
xtitle(`"`xttl'"') ///
note(`"`note'"') ///
`legend' ///
`options' ///
) ///
(line `hat' `evx', ///
sort ///
lstyle(refline) ///
`rlopts' ///
) ///
|| `plot' || `addplot' ///
// blank
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -