2026-03-06
data(jtrain)
pdata_jt <- pdata.frame(jtrain, index = c("fcode", "year"))
res_fe141 <- plm(lscrap ~ d88 + d89 + grant + grant_1,
data = pdata_jt, model = "within",
na.action = na.omit)
summary(res_fe141)$coefficients## Estimate Std. Error t-value Pr(>|t|)
## d88 -0.08021567 0.1094751 -0.7327297 0.46537158
## d89 -0.24720279 0.1332183 -1.8556220 0.06633916
## grant -0.25231487 0.1506290 -1.6750751 0.09692392
## grant_1 -0.42158951 0.2102000 -2.0056593 0.04748974
educ(時間不変)は推定不可 \(\Rightarrow\) educ × 年ダミー
の交差項を使用data(wagepan)
pdata_wp <- pdata.frame(wagepan, index = c("nr", "year"))
res_fe142 <- plm(lwage ~ married + union + exper + expersq +
d81 + d82 + d83 + d84 + d85 + d86 + d87 +
I(educ * d81) + I(educ * d82) + I(educ * d83) +
I(educ * d84) + I(educ * d85) + I(educ * d86) +
I(educ * d87),
data = pdata_wp, model = "within")
# 交差項の係数のみ表示
coef(res_fe142)[grep("educ", names(coef(res_fe142)))]## I(educ * d81) I(educ * d82) I(educ * d83) I(educ * d84) I(educ * d85)
## 0.004990619 0.001650951 -0.002662147 -0.009825689 -0.009214474
## I(educ * d86) I(educ * d87)
## -0.012138164 -0.015789160
| 特徴 | FE (固定効果) | FD (1階差分) |
|---|---|---|
| \(T=2\) のとき | 同一 | 同一 |
| \(T \geq 3\) のとき | 異なる推定量 | 異なる推定量 |
| \(u_{it}\) が系列無相関 | 効率的 | 非効率 |
| \(u_{it}\) がランダムウォーク | 非効率 | 効率的 |
| 測定誤差に対する感度 | 高い | 高い |
sales(売上の対数)と
employ(従業員数の対数)を追加res_fe143 <- plm(lscrap ~ d88 + d89 + grant + grant_1 +
lsales + lemploy,
data = pdata_jt, model = "within",
na.action = na.omit)
summary(res_fe143)$coefficients[c("grant", "grant_1"), ]## Estimate Std. Error t-value Pr(>|t|)
## grant -0.2967542 0.1570861 -1.889119 0.06206040
## grant_1 -0.5355783 0.2242060 -2.388778 0.01896951
# Pooled OLS(参考)
res_pols <- plm(lwage ~ educ + black + hisp + exper + expersq +
married + union +
d81 + d82 + d83 + d84 + d85 + d86 + d87,
data = pdata_wp, model = "pooling")
# 変量効果 (RE)
res_re <- plm(lwage ~ educ + black + hisp + exper + expersq +
married + union +
d81 + d82 + d83 + d84 + d85 + d86 + d87,
data = pdata_wp, model = "random")
# 固定効果 (FE)
res_fe <- plm(lwage ~ expersq + married + union +
d81 + d82 + d83 + d84 + d85 + d86 + d87,
data = pdata_wp, model = "within")# 時間変動変数の係数比較
vars <- c("expersq", "married", "union")
rbind(
POLS = coef(res_pols)[vars],
RE = coef(res_re)[vars],
FE = coef(res_fe)[vars]
)## expersq married union
## POLS -0.002411703 0.10825295 0.18246128
## RE -0.004723943 0.06398602 0.10613443
## FE -0.005185498 0.04668036 0.08000186
married の係数: POLS(0.108) \(>\) RE(0.064) \(>\) FE(0.047)
union の係数: POLS(0.182) \(>\) RE(0.106) \(>\) FE(0.080)
educ, black, hispan
は時間不変のため推定不可educ)\(\Rightarrow\)
FEでは推定不可\[H_0: \text{Cov}(x_{itj}, a_i) = 0 \quad \forall j\]
# Hausman検定(同じ変数セットでFEとREを推定)
res_re_h <- plm(lwage ~ expersq + married + union +
d81 + d82 + d83 + d84 + d85 + d86 + d87,
data = pdata_wp, model = "random")
res_fe_h <- plm(lwage ~ expersq + married + union +
d81 + d82 + d83 + d84 + d85 + d86 + d87,
data = pdata_wp, model = "within")
phtest(res_fe_h, res_re_h)##
## Hausman Test
##
## data: lwage ~ expersq + married + union + d81 + d82 + d83 + d84 + d85 + ...
## chisq = 37.01, df = 10, p-value = 5.637e-05
## alternative hypothesis: one model is inconsistent
# 時間変動変数の個体平均を計算
wagepan$mean_expersq <- ave(wagepan$expersq, wagepan$nr)
wagepan$mean_married <- ave(wagepan$married, wagepan$nr)
wagepan$mean_union <- ave(wagepan$union, wagepan$nr)
pdata_wp2 <- pdata.frame(wagepan, index = c("nr", "year"))
res_cre <- plm(lwage ~ expersq + married + union +
mean_expersq + mean_married + mean_union +
d81 + d82 + d83 + d84 + d85 + d86 + d87,
data = pdata_wp2, model = "random")
# 時間平均変数の係数(γの推定値)
coef(res_cre)[c("mean_expersq", "mean_married", "mean_union")]## mean_expersq mean_married mean_union
## 0.003212666 0.161764098 0.161241547
# 時間平均変数の結合有意性検定(Wald検定)
library(car)
linearHypothesis(res_cre,
c("mean_expersq = 0",
"mean_married = 0",
"mean_union = 0"))##
## Linear hypothesis test:
## mean_expersq = 0
## mean_married = 0
## mean_union = 0
##
## Model 1: restricted model
## Model 2: lwage ~ expersq + married + union + mean_expersq + mean_married +
## mean_union + d81 + d82 + d83 + d84 + d85 + d86 + d87
##
## Res.Df Df Chisq Pr(>Chisq)
## 1 4349
## 2 4346 3 35.992 7.516e-08 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
\[y_{it} = \eta_1 + \alpha_2 d2_t + \cdots + \alpha_T dT_t + \beta w_{it} + \mathbf{x}_{it}\boldsymbol{\psi} + a_i + u_{it}\]
| 手法 | \(a_i\) と \(x_{it}\) の相関 | 時間不変変数 | 効率性 |
|---|---|---|---|
| Pooled OLS | 不可 | 推定可 | 低 |
| 固定効果 (FE) | 許容 | 推定不可 | 中 |
| 1階差分 (FD) | 許容 | 推定不可 | 中 |
| 変量効果 (RE) | 不可(仮定) | 推定可 | 高 |
| 相関変量効果 (CRE) | 許容 | 推定可 | 中 |