我想在R中手动计算一个Heckman选择模型.我的问题是标准误差是有偏差的.有没有办法手动纠正这些?
在sampleSelection模型的我的(样本)代码下面(正确的SE)和手动代码(正确的估计,错误的SE)
require(sampleSelection)
data( Mroz87 )
Mroz87$kids <- ( Mroz87$kids5 + Mroz87$kids618 > 0 )
Run Code Online (Sandbox Code Playgroud)
heckman <- selection(selection = lfp ~ age + I(age^2) + faminc + kids + educ, outcome = wage ~ exper + I(exper^2) + educ + city,
data = Mroz87, method = "2step")
summary(heckman)
Run Code Online (Sandbox Code Playgroud)
seleqn1 <- glm(lfp ~ age + I(age^2) + faminc + kids + educ, family=binomial(link="probit"), data=Mroz87)
summary(seleqn1)
# Calculate inverse Mills ratio by hand ##
Mroz87$IMR <- dnorm(seleqn1$linear.predictors)/pnorm(seleqn1$linear.predictors)
# Outcome equation correcting for selection ## ==> correct estimates, wrong SEs
outeqn1 <- lm(wage ~ exper + I(exper^2) + educ + city + IMR, data=Mroz87, subset=(lfp==1))
summary(outeqn1)
Run Code Online (Sandbox Code Playgroud)
myprobit <- probit(lfp ~ age + I(age^2) + faminc + kids + educ - 1, x = TRUE,
iterlim = 30, data=Mroz87)
imrData <- invMillsRatio(myprobit) # same as yours in this particular case
Mroz87$IMR1 <- imrData$IMR1
outeqn1 <- lm(wage ~ -1 + exper + I(exper^2) + educ + city + IMR1,
data=Mroz87, subset=(lfp==1))
Run Code Online (Sandbox Code Playgroud)
最主要的是你使用拦截模型而不是无拦截。