【问题标题】:including non linearity in fixed effects model in plm包括 plm 中固定效应模型中的非线性
【发布时间】: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


    【解决方案1】:

    你刚刚发现了对数函数的两个性质:

    log(x^2) = 2 * log(x)

    log(x*y) = log(x) + log(y)

    那么,很明显,log(x) 与 2*log(x) 共线,并且从估计中删除了两个共线变量之一。 log(x*y) 和 log(x) + log(y) 相同。

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

    另请参阅下面的可重现示例,我刚刚使用了 log(x^2) = 2*log(x)。可以检测线性相关性,例如,通过包plm 中的函数detect.lindep(另见下文)。从估计中删除系数也暗示模型估计矩阵中的共线列。有时,仅在估计函数中涉及的数据转换之后才会出现线性相关性,请参阅示例部分中的帮助页面?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"
    

    【讨论】:

    • log(x*y) 也等价于 log(x) + log(y),也就是 OP 被丢弃的另一个术语。
    • 哦,是的,我错过了那个!谢谢!我编辑了我的答案。
    猜你喜欢
    • 2015-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多