jmbejara / comp-econ-sp18

Main Course Repository for Computational Methods in Economics (Econ 21410, Spring 2018)
16 stars 23 forks source link

When do you need the effect keywork in plm() ? #71

Closed Jacob-Bishop closed 6 years ago

Jacob-Bishop commented 6 years ago

The keyword is described here: https://cran.r-project.org/web/packages/plm/plm.pdf

jmbejara commented 6 years ago

I believe that the effect keyword defaults to individual (entity effects). In my translation notebook, I show an example of this being the case. At the end, you'll see me run the fixed effects regression with entity effects and time effects in two different ways:

%%R -i df
reg = plm(lscrap ~ d88 + d89 + union + grant + grant_1, df, index=c('fcode', 'year'), model='within')
summary(reg)

This results in a "one-way" model. This actually does have time effects, because we added them manually as year dummies:

Oneway (individual) effect Within Model

Call:
plm(formula = lscrap ~ d88 + d89 + union + grant + grant_1, data = df, 
    model = "within", index = c("fcode", "year"))

Balanced Panel: n=54, T=3, N=162

Residuals :
   Min. 1st Qu.  Median 3rd Qu.    Max. 
-2.2900 -0.1120 -0.0178  0.1440  1.4300 

Coefficients :
         Estimate Std. Error t-value Pr(>|t|)  
d88     -0.080216   0.109475 -0.7327  0.46537  
d89     -0.247203   0.133218 -1.8556  0.06634 .
grant   -0.252315   0.150629 -1.6751  0.09692 .
grant_1 -0.421590   0.210200 -2.0057  0.04749 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    32.25
Residual Sum of Squares: 25.766
R-Squared:      0.20105
Adj. R-Squared: -0.23684
F-statistic: 6.54259 on 4 and 104 DF, p-value: 9.7741e-05

I run this again using the effect keyword:

%%R -i df
# This works so that we don't have to manually put in time dummies
reg = plm(lscrap ~ union + grant + grant_1, df, index=c('fcode', 'year'), model='within', effect='twoways')
summary(reg)

It's the same, but now it's calling it a two-way model

Twoways effects Within Model

Call:
plm(formula = lscrap ~ union + grant + grant_1, data = df, effect = "twoways", 
    model = "within", index = c("fcode", "year"))

Balanced Panel: n=54, T=3, N=162

Residuals :
   Min. 1st Qu.  Median 3rd Qu.    Max. 
-2.2900 -0.1120 -0.0178  0.1440  1.4300 

Coefficients :
        Estimate Std. Error t-value Pr(>|t|)  
grant   -0.25231    0.15063 -1.6751  0.09692 .
grant_1 -0.42159    0.21020 -2.0057  0.04749 *
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Total Sum of Squares:    26.871
Residual Sum of Squares: 25.766
R-Squared:      0.041111
Adj. R-Squared: -0.48443
F-statistic: 2.22942 on 2 and 104 DF, p-value: 0.11271