📄 xtlogit.ado
字号:
*! version 2.8.11 24jun2005
program define xtlogit, eclass byable(onecall) prop(or)
global XT_VV : display "version " string(_caller()) ", missing:"
version 6.0, missing
if _by() {
local myby by `_byvars'`_byrc0':
}
$XT_VV `myby' _vce_parserun xtlogit, panel wtypes(iw fw pw): `0'
if "`s(exit)'" != "" {
exit
}
syntax [varlist(ts)] [if] [in] [iweight fweight pweight] [, ///
RE FE PA INTPoints(int 12) Quad(int 12) *]
/* version 6 so local macros restricted to 7 characters */
if `intpoin' != 12 {
if `quad' != 12 {
di as err "intpoints() and quad() may not be specified together"
exit(198)
}
if "`pa'" !="" || "`fe'"!=""{
di as err "option intpoints() not allowed"
exit 198
}
local options `re' `fe' `pa' `options' quad(`intpoin')
}
else {
if "`pa'" !="" || "`fe'"!="" {
if `quad' != 12 {
di as err "option quad() not allowed"
exit 198
}
local options `re' `fe' `pa' `options'
}
else {
local options `re' `fe' `pa' `options' quad(`quad')
}
}
if replay() {
if "`e(cmd)'" != "xtlogit" & "`e(cmd2)'" != "xtlogit" {
error 301
}
if _by() { error 190 }
Display `0'
exit `e(rc)'
}
if (_caller() < 9.0) {
$XT_VV `myby' xtlogit_8 `varlist' `if' `in' ///
[`weight'`exp'], `options'
}
else {
`myby' Estimate `varlist' `if' `in' [`weight'`exp'], ///
`options'
}
cap mac drop XT_VV
end
program define Estimate, eclass byable(recall) sort
#delimit ;
syntax [varlist(ts)] [if] [in] [iweight fweight pweight]
[, I(varname) RE FE PA noCONstant noSKIP OR
OFFset(varname numeric) FROM(string) Quad(int 12)
noREFINE Level(passthru) noLOg noDISplay
INTMethod(string) * ] ;
#delimit cr
if "`intmeth'" != "" {
if "`fe'" != "" | "`pa'" != "" {
di as err "intmethod() not valid with options fe or pa"
exit(198)
}
local len = length("`intmeth'")
if "`intmeth'" != substr("ghermite",1,max(2,`len')) & ///
"`intmeth'" != substr("aghermite",1,max(3,`len')) {
di as err "intmethod() must be either ghermite or aghermite"
exit(198)
}
if "`intmeth'" == substr("ghermite",1, max(2,`len')) {
local stdquad stdquad
}
}
if length("`fe'`re'`pa'") > 2 {
di in red "Choose only one of fe, re, and pa"
exit 198
}
marksample touse
markout `touse' `offset'
xt_iis `i'
local ivar "`s(ivar)'"
markout `touse' `ivar', strok
/*
Population Averaged model
*/
if "`pa'" != "" {
if "`offset'" != "" {
local offarg "offset(`offset')"
}
if "`from'" != "" {
local farg "from(`from')"
}
if "`i'"!="" {
local i "i(`i')"
}
if "`or'"!="" {
local eform "eform"
}
xtgee `varlist' if `touse' [`weight'`exp'], /*
*/ fam(binomial) rc0 `farg' `level' /*
*/ link(logit) `i' `options' `log' `offarg' /*
*/ `constan' `eform' `display'
est local predict xtlogit_pa_p
if e(rc) == 0 | e(rc) == 430 {
est local estat_cmd "" // reset from xtgee
est local cmd2 "xtlogit"
}
error e(rc)
exit
}
/*
parsing for random effects and fixed effects
*/
if "`weight'" == "fweight" | "`weight'" == "pweight" {
noi di in red "`weight' not allowed"
exit 101
}
if "`skip'" == "" | "`from'" != "" {
local skip "skip"
}
else local skip
mlopts mlopt rest, `options'
if `"`rest'"'!="" {
di in red `"`rest' invalid"'
exit 198
}
if `quad' < 4 | `quad' > 195 {
di in red /*
*/ "number of quadrature points must be between 4 and 195"
exit 198
}
/* parsing complete */
/*
Fixed effects
*/
if "`fe'" != "" {
if "`offset'" != "" {
local offarg "offset(`offset')"
}
local nvar : word count `varlist'
if `nvar' <= 1 {
error 102
}
local dep : word 1 of `varlist'
local depname `dep'
local depstr : subinstr local depname "." "_"
local ind : subinstr local varlist "`dep'" ""
local indname `ind'
_find_tsops `varlist'
if `r(tsops)' {
qui tsset
tsrevar `dep'
local dep `r(varlist)'
tsrevar `ind'
local ind `r(varlist)'
}
local oldind `ind'
/* Need to do my own _rmcoll so don't get a ... dropped
do to collinearity error with a tempvar representing
a time-series-operated variable */
qui _rmcoll `ind' if `touse' [`weight'`exp']
local ind `r(varlist)'
local dropped : list oldind - ind
foreach x of local dropped {
local j : list posof "`x'" in oldind
local x2 : word `j' of `indname'
noi di as txt "note: `x2' dropped due to collinearity"
}
$XT_VV clogit `dep' `ind' if `touse' [`weight'`exp'] , /*
*/ group(`ivar') `options' `offarg' `log' nodisplay
quietly {
tempvar T touse
gen byte `touse' = e(sample)
sort `touse' `ivar'
by `touse' `ivar': gen int `T' = _N if `touse'
summarize `T' if `touse' & `ivar'~=`ivar'[_n-1], detail
}
tempname b v
mat `b' = e(b)
mat `v' = e(V)
local stripe : colfullnames `b'
local stripe : subinstr local stripe "`dep'" "`depstr'", all
foreach x of local ind {
local j : list posof "`x'" in oldind
local x2 : word `j' of `indname'
local stripe : subinstr local stripe "`x'" "`x2'"
}
mat colnames `b' = `stripe'
mat colnames `v' = `stripe'
mat rownames `v' = `stripe'
est post `b' `v', depname(`depname') noclear
est local depvar "`depname'"
est scalar N_g = r(N)
est scalar g_min = r(min)
est scalar g_avg = r(mean)
est scalar g_max = r(max)
est local predict xtlogit_fe_p
est local ivar "`ivar'"
est local title "Conditional fixed-effects logistic regression"
est local cmd2 "xtlogit"
if "`display'" == "" {
DispTbl, `level' `or'
DispLR
}
exit
}
/*
Random effects
*/
if "`weight'" == "aweight" | "`weight'" == "pweight" {
noi di in red "`weight' not allowed in random-effects case"
exit 101
}
if "`offset'" != "" {
local oarg "offset(`offset')"
}
if "`stdquad'" =="" {
tempvar shat hh
generate double `shat' = 1
generate double `hh' = 0
global XTL_shat `shat' /*set global with shat variable for adapquad*/
global XTL_hh `hh' /*set global with hh variable for adapquad */
global XTL_noadap
}
tempvar qavar qwvar
qui gen double `qavar' = .
qui gen double `qwvar' = .
global XTL_quad `quad'
global XTL_qavar `qavar'
global XTL_qwvar `qwvar'
if "`stdquad'"!="" {
global XTL_noadap noadap
}
quietly {
count if `touse'
local nobs = r(N)
if `quad' > r(N) {
noi di in red "number of quadrature points " /*
*/ "must be less than or equal to " /*
*/ "number of obs"
exit 198
}
tokenize `varlist'
local dep "`1'"
local depname `dep'
local depstr : subinstr local depname "." "_"
mac shift
local ind "`*'"
local indname `ind'
_find_tsops `dep' `ind'
if `r(tsops)' {
qui tsset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -