【发布时间】:2020-05-04 20:15:12
【问题描述】:
我在面板数据库中运行 plm 回归时遇到了一些问题。基本上,我必须从我的基础中取出一年,还要从某个零变量中取出所有观察值。我尝试使用 AER 包中的数据集制作一个可重现的示例。
require (AER)
library (AER)
require(plm)
library("plm")
data("Grunfeld", package = "AER")
View(Grunfeld)
#Here I randomize some observations of the third variable (capital) as zero, to reproduce my dataset
for (i in 1:220) {
x <- rnorm(10,0,1)
if (mean(x) >=0) {
Grunfeld[i,3] <- 0
}
}
View(Grunfeld)
panel <- Grunfeld
#First Method
#This is how I was originally manipulating my data and running my regression
panel <- Grunfeld
dd <-pdata.frame(panel, index = c('firm', 'year'))
dd <- dd[dd$year!=1935, ]
dd <- dd[dd$capital !=0, ]
ols_model_2 <- plm(log(value) ~ (capital), data=dd)
summary(ols_model_2)
#However, I couuldn't plot the variables of the datasets in graphs, because they weren't vectors. So I tried another way:
#Second Method
panel <- panel[panel$year!= 1935, ]
panel <- panel[panel$capital != 0,]
ols_model <- plm(log(value) ~ log(capital), data=panel, index = c('firm','year'))
summary(ols_model)
#But this gave extremely different results for the ols regression!
据我了解,这两种方法都应该在 OLS 回归中产生相同的输出。现在恐怕我的整个分析都是错误的,因为我是按照第一种方式做的。谁能解释我发生了什么? 提前致谢!
【问题讨论】: