📄 linktest.ado
字号:
*! version 3.2.1 22sep2004
program define linktest, rclass
* touched by kth -- double saves in S_# and r()
version 6, missing
/* double save in S_# and r() */
global S_1 . /* t of hat squared */
global S_2 . /* dof */
if _caller()<6 {
syntax [aw fw pw] [if] [in] [, *]
marksample touse
local weight `"[`weight'`exp']"'
}
else {
syntax [if] [in] [, *]
local weight `"[`e(wtype)'`e(wexp)']"'
tempvar touse
if `"`if'`in'"' != "" {
mark `touse' `weight' `if' `in'
}
else qui gen byte `touse' = e(sample)
}
if `"`e(cmd)'"'=="" {
error 301
}
local cmd `"`e(cmd)'"'
local lhs `"`e(depvar)'"'
if `"`e(cmd2)'"'=="stcox" {
local cmd stcox
local lhs
local options `options' nohr
}
if `"`e(cmd2)'"'=="streg" {
local cmd streg
local lhs
}
if substr(`"`cmd'"',1,2)=="sw" {
local cmd = substr(`"`cmd'"',3,.)
if `"`cmd'"'=="logis" { local cmd "logistic" }
else if `"`cmd'"'=="oprbt" { local cmd "oprobit" }
else if `"`cmd'"'=="pois" { local cmd "poisson" }
else if `"`cmd'"'=="weib" { local cmd "weibull" }
}
if `"`cmd'"'=="blogit" | `"`cmd'"'=="bprobit" | `"`cmd'"'=="corc" | /*
*/ `"`cmd'"'=="glogit" | `"`cmd'"'=="gprobit" | /*
*/ `"`cmd'"'=="rreg" | `"`cmd'"'=="mlogit" | /*
*/ "`cmd'" == "zip" | "`cmd'" == "zinb" | /*
*/ "`cmd'" == "biprobit" | substr("`cmd'",1,2) == "xt" | /*
*/ `"`cmd'"'=="sureg" | /*
*/ `"`cmd'"'=="reg3" | "`cmd'" == "heckprob" {
di in red `"not possible after `cmd'"'
exit 131
}
if `"`cmd'"'!="stcox" && `"`cmd'"'!="streg" {
capture confirm var `lhs'
if _rc {
di in red `"dependent variable `lhs' not found"'
exit 111
}
}
confirm new var _hat _hatsq
tempvar hat hat2 base
quietly {
_predict `hat' if `touse', xb
count if `touse' & `hat'< . & `e(depvar)'< .
if r(N)<3 {
noisily error 2001
}
}
if `"`cmd'"'=="regress" | `"`cmd'"'=="anova" | `"`cmd'"'=="stepwise" {
local nxtcmd "regress"
}
else if `"`cmd'"'=="logistic" {
local nxtcmd "logit"
}
else if `"`cmd'"'=="mlogit" {
di in red `"not possible with `cmd'"'
exit 399
}
else if `"`cmd'"'=="cnsreg" | `"`cmd'"'=="eivreg" {
local nxtcmd "regress"
local options
}
else local nxtcmd `cmd'
quietly gen `hat2'=`hat'^2
estimates hold `base'
capture {
rename `hat' _hat
rename `hat2' _hatsq
noisily `nxtcmd' `lhs' _hat _hatsq `weight' if `touse', /*
*/ `options'
/* double save in S_# and r() */
ret scalar t = _b[_hatsq]/_se[_hatsq]
ret scalar df = e(df_r)
global S_1 `"`return(t)'"'
global S_2 `"`return(df)'"'
* replaced this -- new syntax _result(5) and S_E_tdf both now saved in e(df_r)
* global S_2 "$S_E_tdf"
* if "$S_2"=="" {
* global S_2 = _result(5)
* }
}
local rc=_rc
estimates unhold `base'
capture drop _hat
capture drop _hatsq
exit `rc'
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -