Fixed Effects Models

Regression

Regression Formulae:

\[ y_{ct} = \beta D_t + \sum_{j=1}^p \gamma_j y_{ct-j} + \alpha_c + \delta_t + \epsilon_{ct} \]

Formula:

  • \(y_{ct}\) = log GDP per capita in country c at time t = column y
  • \(D_{ct}\) = Dichotomous measure of democracy = column: dem
  • p lags of log GDP for control
  • \(\alpha\) = country fixed effects
  • \(\delta\) = time fixed effects
  • \(e\) = error

Estimator: Within Estimator

Replication

Imports

library(plm)
library(tidyverse)

Load the Data

Dataset avaibable online at: https://economics.mit.edu/people/faculty/daron-acemoglu/data-archive

  • Download as .rar Archive File (not openable on MacOS)
  • Unpack with The Unarchiver (free)
  • Open the .dta file with R
DDCGdata <- haven::read_dta("data/DDCGdata.dta")

df <- DDCGdata %>%
  dplyr::select(1:30)
  
rm(DDCGdata)
head(df)

Creating Lags of Gdp

df <- df %>%
  dplyr::group_by(country_name) %>%
  dplyr::mutate(
    lag1 = lag(y, 1),
    lag2 = lag(y, 2),
    lag3 = lag(y, 3),
    lag4 = lag(y, 4),
    lag5 = lag(y, 5),
    lag6 = lag(y, 6),
    lag7 = lag(y, 7),
    lag8 = lag(y, 8)
  )

Making it in a panel dataset

pdf = pdata.frame(df, index=c("country_name", "year"))

Estimating the Dynamic Linear Model

Model 1 = 1 Lag

model1 <- plm(
  y ~ dem + lag1, #the equation with country fixed effects
  model="within", #The fixed effects within estimator
  data = pdf, 
  effect = "twoways"
  )
summary(model1)
Twoways effects Within Model

Call:
plm(formula = y ~ dem + lag1, data = pdf, effect = "twoways", 
    model = "within")

Unbalanced Panel: n = 175, T = 9-50, N = 6790

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-65.02556  -2.08935   0.18715   2.46114  62.53569 

Coefficients:
      Estimate Std. Error  t-value  Pr(>|t|)    
dem  0.9729199  0.2397441   4.0582 5.004e-05 ***
lag1 0.9726609  0.0025371 383.3771 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    4810200
Residual Sum of Squares: 203390
R-Squared:      0.95772
Adj. R-Squared: 0.95627
F-statistic: 74338.7 on 2 and 6564 DF, p-value: < 2.22e-16

Model 2 = 2 Lags

model2 <- plm(
  y ~ dem + lag1 + lag2 , #the equation with country fixed effects
  model="within", #The fixed effects within estimator
  data = pdf, 
  effect = "twoways"
  )
summary(model2)
Twoways effects Within Model

Call:
plm(formula = y ~ dem + lag1 + lag2, data = pdf, effect = "twoways", 
    model = "within")

Unbalanced Panel: n = 175, T = 8-49, N = 6642

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-62.86438  -1.90942   0.15516   2.23071  59.01248 

Coefficients:
      Estimate Std. Error  t-value  Pr(>|t|)    
dem   0.650609   0.229213   2.8385  0.004548 ** 
lag1  1.266318   0.011588 109.2794 < 2.2e-16 ***
lag2 -0.299513   0.011522 -25.9959 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    4595100
Residual Sum of Squares: 175250
R-Squared:      0.96186
Adj. R-Squared: 0.96052
F-statistic: 53938.3 on 3 and 6416 DF, p-value: < 2.22e-16

Model 3 = 4 Lags

model3 <- plm(
  y ~ dem + lag1 + lag2 + lag3 + lag4, #the equation with country fixed effects
  model="within", #The fixed effects within estimator
  data = pdf, 
  effect = "twoways"
  )
summary(model3)
Twoways effects Within Model

Call:
plm(formula = y ~ dem + lag1 + lag2 + lag3 + lag4, data = pdf, 
    effect = "twoways", model = "within")

Unbalanced Panel: n = 175, T = 6-47, N = 6336

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-63.95467  -1.84198   0.14589   2.14199  59.88866 

Coefficients:
      Estimate Std. Error  t-value  Pr(>|t|)    
dem   0.786553   0.228341   3.4446 0.0005757 ***
lag1  1.238106   0.012546  98.6829 < 2.2e-16 ***
lag2 -0.206543   0.019819 -10.4215 < 2.2e-16 ***
lag3 -0.026095   0.019220  -1.3577 0.1746170    
lag4 -0.042501   0.011797  -3.6025 0.0003176 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    4164500
Residual Sum of Squares: 154460
R-Squared:      0.96291
Adj. R-Squared: 0.96154
F-statistic: 31725.2 on 5 and 6110 DF, p-value: < 2.22e-16

Model 4 = 8 Lags

model4 <- plm(
  y ~ dem + lag1 + lag2 + lag3 +lag4 +lag5 +lag6+ lag7 +lag8, #the equation with country fixed effects
  model="within", #The fixed effects within estimator
  data = pdf, 
  effect = "twoways"
  )
summary(model4)
Twoways effects Within Model

Call:
plm(formula = y ~ dem + lag1 + lag2 + lag3 + lag4 + lag5 + lag6 + 
    lag7 + lag8, data = pdf, effect = "twoways", model = "within")

Unbalanced Panel: n = 175, T = 2-43, N = 5688

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-64.16826  -1.74149   0.15926   2.11117  59.76890 

Coefficients:
       Estimate Std. Error  t-value  Pr(>|t|)    
dem   0.8871243  0.2390289   3.7114 0.0002082 ***
lag1  1.2334933  0.0131433  93.8495 < 2.2e-16 ***
lag2 -0.2136260  0.0206486 -10.3458 < 2.2e-16 ***
lag3 -0.0214706  0.0205086  -1.0469 0.2951892    
lag4 -0.0387811  0.0202442  -1.9157 0.0554595 .  
lag5 -0.0186976  0.0199722  -0.9362 0.3492194    
lag6  0.0105445  0.0195214   0.5402 0.5891143    
lag7  0.0154950  0.0187536   0.8262 0.4087028    
lag8 -0.0072668  0.0116695  -0.6227 0.5334986    
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    3210900
Residual Sum of Squares: 129290
R-Squared:      0.95973
Adj. R-Squared: 0.95807
F-statistic: 14465 on 9 and 5462 DF, p-value: < 2.22e-16

Save the Models to a file

save(model1, model2, model3, model4, file = "output/models.RData")