[英]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.