R的面板数据固定效应问题,我在摘要中看不到所有虚拟变量

时间:2018-08-27 18:18:09

标签: r regression panel plm

我正在使用R运行数据面板回归。 我使用那些data(第2页)。

我想对面板数据使用固定效果。请在下面找到我固定效果的代码

FE_1 <- plm(GDP_per_capita_growth ~ 
           log(GDP_per_capita) + GF_GDP + MA_GDP + 
           start_business + Invest_GDP +
           second_schooling + Pop_growth + 
           log(Inflation_CPI) + Trade + 
           GF_GDP * start_business +
           factor(as.character(time_fixed_effect)) + 
           factor(as.character(regional)) +
           factor(as.character(oil_exporting_countries)),
           data = Temp_1,
           index = c("country",
                     "year"),
           na.action = na.omit,
           model = "within") 

当我为面板数据固定效果运行摘要时,缺少一些变量,例如time_fixed_effect,region和oil_exporting_countries。 下面,我得到的结果。

Coefficients:
                                            Estimate  Std. Error t-value  Pr(>|t|)    
log(GDP_per_capita)                      -1.9676e+01  5.0218e+00 -3.9181 0.0001386 ***
GF_GDP                                    1.2637e+00  1.9705e+00  0.6413 0.5223695    
MA_GDP                                    1.9337e+01  8.3736e+00  2.3093 0.0223807 *  
start_business                           -1.3378e-07  1.0077e-07 -1.3276 0.1864403    
Invest_GDP                                1.5166e-08  1.1173e-08  1.3574 0.1768341    
second_schooling                         -4.9808e-01  5.4186e+00 -0.0919 0.9268910    
Pop_growth                               -1.6174e+00  5.9779e-01 -2.7055 0.0076606 ** 
log(Inflation_CPI)                        1.3861e-01  3.2403e-01  0.4278 0.6694806    
Trade                                     1.8669e-02  1.8617e-02  1.0028 0.3176852    
factor(as.character(time_fixed_effect))1  3.8295e-01  4.4318e-01  0.8641 0.3890017    
GF_GDP:start_business                     5.0494e-07  3.4416e-07  1.4672 0.1445566    
---

我想知道,我应该怎么做才能显示所有虚拟变量。我的代码中是否有错误?

我写了index = c("country", "year"),而不是index = c("year", "country"),,得到了以下结果:

Coefficients:
                                                  Estimate  Std. Error t-value Pr(>|t|)   
log(GDP_per_capita)                            -3.3627e+00  2.0642e+00 -1.6291 0.105013   
GF_GDP                                          1.2334e+00  1.8129e+00  0.6804 0.497127   
MA_GDP                                          5.2312e-01  6.4419e+00  0.0812 0.935366   
start_business                                  1.4314e-08  3.0105e-08  0.4755 0.635022   
Invest_GDP                                     -9.8744e-10  1.5174e-09 -0.6507 0.516025   
second_schooling                                1.0860e+00  1.0806e+00  1.0050 0.316205   
Pop_growth                                     -6.3753e-01  2.2690e-01 -2.8097 0.005494 **
log(Inflation_CPI)                              1.4547e-01  2.5011e-01  0.5816 0.561550   
Trade                                           9.2730e-04  3.8306e-03  0.2421 0.808991   
factor(as.character(regional))2                -1.0668e+00  8.3584e-01 -1.2763 0.203441   
factor(as.character(regional))3                -2.6186e-01  6.6220e-01 -0.3954 0.692972   
factor(as.character(regional))4                 1.4760e-01  7.9347e-01  0.1860 0.852639   
factor(as.character(regional))5                 1.3558e+00  7.2400e-01  1.8727 0.062696 . 
factor(as.character(oil_exporting_countries))1 -1.8890e-01  4.4884e-01 -0.4209 0.674344   
GF_GDP:start_business                          -2.9751e-08  1.3526e-07 -0.2199 0.826157   
---

我不知道为什么会得到这个结果!您能帮我找出原因吗?还请帮助我显示“ time_fixed-effect”变量。

预先感谢您的宝贵帮助。

PS:这是完整的代码

# Rename column names
colnames(my_data)[4] <- "Invest_GDP" # percentage
colnames(my_data)[9] <- "Pr_sector_GDP" # percentage
colnames(my_data)[12] <- "start_business"
colnames(my_data)[16] <- "second_schooling"
colnames(my_data)[18] <- "GDP_per_capita_growth"

# Transform column "inflation" as numeric
my_data$Inflation_CPI <- as.numeric(my_data$Inflation_CPI)
my_data$second_schooling <- as.numeric(my_data$second_schooling)

Temp_1 <-  my_data %>%
  select( 
         -region, 
         -Pr_sector_GDP,
         -Prop_rights,
         -T_freedom,
         -current_invest
  )

1 个答案:

答案 0 :(得分:1)

由于多重共线性而未显示变量-就像@AntoniosK建议那样将它们删除。 plm并不冗长,也不会告诉您,但是如果您使用lm估计相同的模型,则可以更清楚地看到它(我对输出做了一些删节):

> summary(lm(GDP_per_capita_growth ~ 
+                 log(GDP_per_capita) + GF_GDP + MA_GDP + 
+                 start_business + Invest_GDP +
+                 second_schooling + Pop_growth + 
+                 log(Inflation_CPI) + Trade + 
+                 GF_GDP * start_business + factor(country) +
+                 factor(time_fixed_effect) + 
+                 factor(regional) +
+                 factor(oil_exporting_countries),
+             data = Temp_1)) 

Call:
lm(formula = GDP_per_capita_growth ~ log(GDP_per_capita) + GF_GDP + 
    MA_GDP + start_business + Invest_GDP + second_schooling + 
    Pop_growth + log(Inflation_CPI) + Trade + GF_GDP * start_business + 
    factor(country) + factor(time_fixed_effect) + factor(regional) + 
    factor(oil_exporting_countries), data = Temp_1)

Residuals:
   Min     1Q Median     3Q    Max 
-6.263 -1.070  0.000  1.029  7.001 

Coefficients: (5 not defined because of singularities)
                                      Estimate Std. Error t value Pr(>|t|)    
(Intercept)                          2.609e+01  5.791e+00   4.506 1.38e-05 ***
log(GDP_per_capita)                 -1.968e+01  5.022e+00  -3.918 0.000139 ***
GF_GDP                               1.264e+00  1.970e+00   0.641 0.522370    
MA_GDP                               1.934e+01  8.374e+00   2.309 0.022381 *  
start_business                      -1.338e-07  1.008e-07  -1.328 0.186440    
Invest_GDP                           1.517e-08  1.117e-08   1.357 0.176834    
second_schooling                    -4.981e-01  5.419e+00  -0.092 0.926891    
Pop_growth                          -1.617e+00  5.978e-01  -2.706 0.007661 ** 
log(Inflation_CPI)                   1.386e-01  3.240e-01   0.428 0.669481    
Trade                                1.867e-02  1.862e-02   1.003 0.317685    
factor(country)Algeria               2.489e+00  2.448e+00   1.017 0.310886    
... 
factor(country)Vietnam              -4.958e-01  2.338e+00  -0.212 0.832356    
factor(time_fixed_effect)1           3.830e-01  4.432e-01   0.864 0.389002    
factor(regional)2                           NA         NA      NA       NA    
factor(regional)3                           NA         NA      NA       NA    
factor(regional)4                           NA         NA      NA       NA    
factor(regional)5                           NA         NA      NA       NA    
factor(oil_exporting_countries)1            NA         NA      NA       NA    
GF_GDP:start_business                5.049e-07  3.442e-07   1.467 0.144557    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.383 on 141 degrees of freedom
  (1 observation deleted due to missingness)
Multiple R-squared:  0.5391,    Adjusted R-squared:  0.3397 
F-statistic: 2.703 on 61 and 141 DF,  p-value: 6.858e-07

您的第二个plm模型会得到不同的结果,因为它是一个不同的模型 -您告诉它year是您的实体固定效应,因此用年假人而不是国家假人来估计模型!

Again, using `lm`, here's what you are estimating:

> summary(lm(GDP_per_capita_growth ~ 
+                 log(GDP_per_capita) + GF_GDP + MA_GDP + 
+                 start_business + Invest_GDP +
+                 second_schooling + Pop_growth + 
+                 log(Inflation_CPI) + Trade + 
+                 GF_GDP * start_business + factor(year) +
+                 factor(time_fixed_effect) + 
+                 factor(regional) +
+                 factor(oil_exporting_countries),
+             data = Temp_1)) 

Call:
lm(formula = GDP_per_capita_growth ~ log(GDP_per_capita) + GF_GDP + 
    MA_GDP + start_business + Invest_GDP + second_schooling + 
    Pop_growth + log(Inflation_CPI) + Trade + GF_GDP * start_business + 
    factor(year) + factor(time_fixed_effect) + factor(regional) + 
    factor(oil_exporting_countries), data = Temp_1)

Residuals:
    Min      1Q  Median      3Q     Max 
-6.7279 -1.2924 -0.1109  1.2808 10.6906 

Coefficients: (1 not defined because of singularities)
                                   Estimate Std. Error t value Pr(>|t|)    
(Intercept)                       9.032e+00  2.442e+00   3.699 0.000286 ***
log(GDP_per_capita)              -3.363e+00  2.064e+00  -1.629 0.105013    
GF_GDP                            1.233e+00  1.813e+00   0.680 0.497127    
MA_GDP                            5.231e-01  6.442e+00   0.081 0.935366    
start_business                    1.431e-08  3.011e-08   0.475 0.635022    
Invest_GDP                       -9.874e-10  1.517e-09  -0.651 0.516025    
second_schooling                  1.086e+00  1.081e+00   1.005 0.316205    
Pop_growth                       -6.375e-01  2.269e-01  -2.810 0.005494 ** 
log(Inflation_CPI)                1.455e-01  2.501e-01   0.582 0.561550    
Trade                             9.273e-04  3.831e-03   0.242 0.808991    
factor(year)2008 -2010           -9.536e-01  5.308e-01  -1.796 0.074056 .  
factor(year)2011-2013            -1.449e+00  5.336e-01  -2.714 0.007269 ** 
factor(year)2014-2016            -2.261e+00  5.554e-01  -4.071 6.93e-05 ***
factor(time_fixed_effect)1               NA         NA      NA       NA    
factor(regional)2                -1.067e+00  8.358e-01  -1.276 0.203441    
factor(regional)3                -2.619e-01  6.622e-01  -0.395 0.692972    
factor(regional)4                 1.476e-01  7.935e-01   0.186 0.852639    
factor(regional)5                 1.356e+00  7.240e-01   1.873 0.062696 .  
factor(oil_exporting_countries)1 -1.889e-01  4.488e-01  -0.421 0.674344    
GF_GDP:start_business            -2.975e-08  1.353e-07  -0.220 0.826157    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.56 on 184 degrees of freedom
  (1 observation deleted due to missingness)
Multiple R-squared:  0.3063,    Adjusted R-squared:  0.2384 
F-statistic: 4.513 on 18 and 184 DF,  p-value: 4.363e-08

现在,您不清楚要做什么。如果您解释要通过分析实现的目标,这可能会有所帮助。

您想要国家和年份固定效果吗? time_fixed_effect变量到底在做什么?

如果要获得国家和年份的固定效果,则需要参数effect = "twoway"。默认情况下,plm指定effect = "individual",它仅估算实体固定效果模型。

FE_1 <- plm(GDP_per_capita_growth ~ 
                log(GDP_per_capita) + GF_GDP + MA_GDP + 
                start_business + Invest_GDP +
                second_schooling + Pop_growth + 
                log(Inflation_CPI) + Trade + 
                GF_GDP * start_business +
                factor(as.character(regional)) +
                factor(as.character(oil_exporting_countries)),
            data = Temp_1,
            index = c("country", "year"),
            model = "within", effect = "twoway") 
相关问题