在此处输入图像描述我设计了一个带有虚拟变量的 twfe 模型,以便在 diff 中进行 diff。为了引入新的自变量,我需要再引入两个虚拟变量(北/南和海/湖自治市)。如果我在代码中添加它们然后总结结果,我看不到这些系数的估计值。
不能引入多个假人吗?对于其他变量,例如人口统计数量,我没有任何问题。
代码下方:
## read the data
library(readxl)
data <- read_excel("~/link")
## load packages
library(dplyr) ## for wrangling the data
library(plm) ## for the regression
library(lmtest) ## for robust standard errors
## coerce MUNICIPALITY and YEAR variables to factor
data <- data %>%
mutate_at(c("MUNICIPALITY", "YEAR"), as.factor)
## run the regression
model_beds <- plm(formula = beds ~ DID + balneare, data = data, effect = "twoways",
model = "within", index = c("MUNICIPALITY", "YEAR"))
## summarize the results of the regression
summary(model_beds)
输出=
Call:
plm(formula = hotelbeds ~ DID + sea, data = data, effect = "twoways",
model = "within", index = c("MUNICIPALITY", "YEAR"))
Balanced Panel: n = 78, T = 18, N = 1404
Residuals:
Min. 1st Qu. Median 3rd Qu. Max.
-1229.853 -64.005 -11.272 71.209 1728.606
Coefficients:
Estimate Std. Error t-value Pr(>|t|)
DID 55.471 23.342 2.3765 0.01762 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Total Sum of Squares: 73147000
Residual Sum of Squares: 72833000
R-Squared: 0.0042991
Adj. R-Squared: -0.068019
F-statistic: 5.64753 on 1 and 1308 DF, p-value: 0.017623
如何解决此问题并引入多个虚拟变量?
数据结构如下: