我正在尝试在多个时间段的差异上做一个“经典”的差异。我想做的模型是:
y = a + b1x1 + b2_treat + b3_period + b_4(treat*period) + u (eq.1)
所以基本上我正在测试不同的设置,只是为了确保我以正确的方式指定我的模型,使用不同的包。我想使用 fixst-package,所以我尝试将估计值与标准 lm()-package 的估计值进行比较。然而,结果不同——系数和标准错误。
我的问题是:
- lm_mod、lm_mod2 或 feols_mod 回归是否正确指定(如 eq.1 中所示)?
如果没有,如果有人能告诉我如何在 lm() 和 feols() 中获得相同的结果,我将不胜感激!
# libraries
library(fixest)
library(modelsummary)
library(tidyverse)
# load data
data(base_did)
# make df for lm_mod with 5 as the reference-period
base_ref_5 <- base_did %>%
mutate(period = as.factor(period)) %>%
mutate(period = relevel(period, ref = 5))
# Notice that i use base_ref_5 for the lm model and base_did for the feol_mod.
lm_mod <- lm(y ~ x1 + treat*period, base_ref_5)
lm_mod2 <- lm(y ~ x1 + treat + period + treat*period, base_ref_5)
feols_mod <- feols(y ~ x1 + i(period, treat, ref = 5), base_did)
# compare models
models <- list("lm" = lm_mod,
"lm2" = lm_mod2,
"feols" = feols_mod)
msummary(models, stars = T)
**EDIT:**
the reason why I created base_ref_5 was so that both regressions would have period 5 as the reference period, if that was unclear.
**EDIT 2**:
added a third model (lm_mod2) which is much closer, but there is still a difference.