使用具有一阶差分的 plm 时的观察次数

Number of observations when using plm with first differences

在 运行 使用 plm 和类似于以下数据集的面板数据进行回归后,我遇到了一个简单的问题:

dataset <- data.frame(id = rep(c(1,2,3,4,5), 2),
                      time = rep(c(0,1), each = 5),
                      group = rep(c(0,1,0,0,1), 2),
                      Y = runif(10,0,1))
model <-plm(Y ~ time*group, method = 'fd', effect = 'twoways', data = dataset,
            index = c('id', 'time'))
summary(model)

stargazer(model)

如您所见,模型summarystargazer显示的table都会说我的观察数是10。但是,这样不是更正确吗说 N = 5,因为我在第一个差异之后带走了时间元素?

关于观察次数,你是对的。但是,您的代码并没有按照您的意愿执行(第一个差分模型)。

如果你想要一阶微分模型,将参数 method 切换为 model(并删除参数 effect,因为它对一阶微分模型没有意义):

model <-plm(Y ~ time*group, model = 'fd', data = dataset,
            index = c('id', 'time'))
summary(model)

## Oneway (individual) effect First-Difference Model
## 
## Call:
## plm(formula = Y ~ time * group, data = dataset, model = "fd", 
##     index = c("id", "time"))
## 
## Balanced Panel: n = 5, T = 2, N = 10
## Observations used in estimation: 5
## 
## Residuals:
##       Min.    1st Qu.     Median    3rd Qu.       Max. 
## -0.3067240 -0.0012185  0.0012185  0.1367080  0.1700160 
## [...]

在汇总输出中,您可以看到原始数据中的观察数 (N=10) 和 FD 模型中使用的观察数 (5)。