我试图找出为什么来自 ivreg 估计 {AER} 的拟合值与手动执行的 2 阶段最小二乘法(以及适当的简化形式方程)不同...... ivreg 和 ivreg.fit 的帮助说明它调用lm() 重复。我提供了 {AER} 包中计算出的拟合值的示例。

rm(list = ls())
require('AER') # install.packages('AER')
## data and example adapted from the AER package
data("CigarettesSW")
CigarettesSW$rprice <- with(CigarettesSW, price/cpi)
CigarettesSW$rincome <- with(CigarettesSW, income/population/cpi)
CigarettesSW$tdiff <- with(CigarettesSW, (taxs - tax)/cpi)

## Estimation by IV: log(rprice) is endogenous, tdiff is IV for log(rprice):
fm <- ivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff,
            data = CigarettesSW)
##
##
# Reduced form for log(rprice)
rf.rprice <- lm(log(rprice) ~ log(rincome) + tdiff,
                data = CigarettesSW)
# Reduced form for log(packs)
rf.lpacks <- lm(log(packs) ~ log(rincome) + tdiff,
                data = CigarettesSW)
# "Manual" 2SLS estimation of the "fm" equation
m2sls <- lm(log(packs) ~ rf.rprice$fitted.values + log(rincome),
            data = CigarettesSW)
# Coefficients of "m2sls" are matched to "fm" object:
summary(m2sls)
summary(fm)
#
# It is my understanding, that fitted values from ivreg-fitted object "fm",
# manually performed 2SLS (in "m2sls") and from the reduced form rf.lpacks
# should be the same:
#
head(fm$fitted.values, 10)
head(m2sls$fitted.values, 10)
head(rf.lpacks$fitted.values, 10)
#
# However, fitted values from ivreg are different.

最有可能的是,我遗漏了一些明显的东西,但无论如何我都被卡住了。将不胜感激任何意见。

最佳答案

predict() 对象的 fitted()ivreg 方法简单地计算 x %*% b,其中 x 是原始回归矩阵,b 是系数向量(由 IV 估计)。因此:

x <- model.matrix(~ log(rprice) + log(rincome), data = CigarettesSW)
b <- coef(m2sls)

然后您手动计算的拟合值是:
head(drop(x %*% b))
##        1        2        3        4        5        6
## 4.750353 4.751864 4.720216 4.778866 4.919258 4.596331

这与 ivreg 的计算完全匹配:
head(fitted(fm))
##        1        2        3        4        5        6
## 4.750353 4.751864 4.720216 4.778866 4.919258 4.596331

关于r - 来自 ivreg {AER} 对象的拟合值与手动 2SLS 结果不匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31874146/

10-12 17:24
查看更多