【发布时间】:2022-01-02 19:06:52
【问题描述】:
我正在尝试使用 R 中的 plm 包构建固定效应回归。我正在使用具有年份和国家固定效应的国家级面板数据。 我的问题涉及 2 个解释变量。一个是两个变量的交互项,一个是其中一个变量的平方项。
模型基本上是: y = x1 + x1^2+ x3 + x1*x3+ ...+xn ,所有变量都是对数形式
模型的核心是包含平方项,但是当我运行回归时,由于“奇点”,它总是被排除在外,因为 x1 和 x1^2 显然是相关的。 意味着回归有效,我得到了我的变量的估计值,而不是 x1^2 和 x1*x2。 我该如何规避这种情况?
library(plm)
fe_reg<- plm(log(y) ~ log(x1)+log(x2)+log(x2^2)+log(x1*x2)+dummy,
data = df,
index = c("country", "year"),
model = "within",
effect = "twoways")
summary(fe_reg)
´´´
#I have tried defining the interaction and squared terms as vectors, which helped with the #interaction term but not the squared term.
df1.pd<- df1 %>% mutate_at(c('x1'), ~(scale(.) %>% as.vector))
df1.pd<- df1 %>% mutate_at(c('x2'), ~(scale(.) %>% as.vector))
´´´
I am pretty new to R, so apologies if this not a very well structured question.
【问题讨论】:
标签: r regression plm