繁体   English   中英

包括 plm 中固定效应 model 中的非线性

[英]including non linearity in fixed effects model in plm

我正在尝试使用 R 中的 plm package 构建固定效应回归。 我正在使用具有年份和国家固定效应的国家级面板数据。 我的问题涉及 2 个解释变量。 一个是两个变量的交互项,一个是其中一个变量的平方项。

model 基本上是:y = x1 + x1^2+ x3 + x1*x3+...+xn,所有变量都是对数形式

model 的核心是包含平方项,但是当我运行回归时,由于“奇点”,它总是被排除在外,因为 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.

您刚刚找到了对数 function 的一个属性:

日志(x^2) = 2 * 日志(x)

然后,很明显,log(x) 与 2*log(x) 共线,并且从估计中删除了两个共线变量之一。

因此,您要估计的 model 无法通过线性回归方法进行估计。 您可能希望采用与登录或原始变量不同的数据转换。

另请参阅下面的可重现示例。 例如,可以通过来自 package plm的 function detect.lindep检测线性相关性(也参见下文)。 从估计中删除系数也暗示 model 估计矩阵中的共线列。 有时,仅在估计函数中涉及的数据转换之后才会出现线性相关性,请参阅示例部分中的帮助页面?detect.lindep中的内部转换示例)。

library(plm)
data("Grunfeld")
pGrun <- pdata.frame(Grunfeld)
pGrun$lvalue  <- log(pGrun$value)   # log(x)
pGrun$lvalue2 <- log(pGrun$value^2) # log(x^2) == 2 * log(x)

mod  <- plm(inv ~ lvalue + lvalue2 + capital, data = pGrun, model = "within")
summary(mod)
#> Oneway (individual) effect Within Model
#> 
#> Call:
#> plm(formula = inv ~ lvalue + lvalue2 + capital, data = pGrun, 
#>     model = "within")
#> 
#> Balanced Panel: n = 10, T = 20, N = 200
#> 
#> Residuals:
#>       Min.    1st Qu.     Median    3rd Qu.       Max. 
#> -186.62916  -20.56311   -0.17669   20.66673  300.87714 
#> 
#> Coefficients: (1 dropped because of singularities)
#>          Estimate Std. Error t-value Pr(>|t|)    
#> lvalue  30.979345  17.592730  1.7609  0.07988 .  
#> capital  0.360764   0.020078 17.9678  < 2e-16 ***
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> Total Sum of Squares:    2244400
#> Residual Sum of Squares: 751290
#> R-Squared:      0.66525
#> Adj. R-Squared: 0.64567
#> F-statistic: 186.81 on 2 and 188 DF, p-value: < 2.22e-16

detect.lindep(mod) # run on the model 
#> [1] "Suspicious column number(s): 1, 2"
#> [1] "Suspicious column name(s):   lvalue, lvalue2"
detect.lindep(pGrun) # run on the data
#> [1] "Suspicious column number(s): 6, 7"
#> [1] "Suspicious column name(s):   lvalue, lvalue2"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM