8.2 Solutions

8.2.1 Exercise 1

Create a new file called assignment8.R in your PUBL0055 folder and write all the solutions in it.

In RStudio, go to the menu and select File > New File > R Script

Make sure to clear the environment and set the working directory.

rm(list = ls())
setwd("~/PUBL0055")

Go to the menu and select File > Save and name it assignment8.R

Next, we load all the packages we need for these exercises.

library(foreign)
library(plm)

8.2.2 Exercise 2

  • Load the Comparative Political Dataset CPDS_1960-2013_stata.dta from your PUBL0055 folder or from the datasets repository:

    cpds <- read.dta("CPDS_1960-2013_stata.dta")
Variable Description
vturn Voter turnout in election
judrev Judicial review (existence of an independent body which decides whether laws conform to the constitution).
Coded 0 = no, 1 = yes.
ud Net union membership as a proportion wage and salary earners in employment (union density)
unemp Unemployment rate, percentage of civilian labour force.
unemp_pmp Cash expenditure for unemployment benefits as a percentage of GDP (public and mandatory private).
realgdpgr Growth of real GDP, percent change from previous year.
debt Gross general government debt (financial liabilities) as a percentage of GDP.
socexp_t_pmp Total public and mandatory private social expenditure as a percentage of GDP.

8.2.3 Exercise 3

Estimate a model for the electoral fractionalization of the party system as coded by the rae_ele variable in the dataset using all the variables listed above.

  • Estimate a fixed effect model and test for country and time fixed effects.
  • Run the necessary tests to check whether country and time fixed effects are present.

Let’s examine the dependent variable rae_ele.

summary(cpds$rae_ele)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
 0.4915  0.6751  0.7436  0.7326  0.8076  0.9283       7 

If we want to visualize the distribution of the rae_ele, we can plot a histogram

hist(cpds$rae_ele, 
     xlab = "Electoral Fractionalization Index (rae_ele)",
     main = "Electoral Fractionalization")

Let’s run panel data regression with country fixed effects.

country_effects <- plm(
  rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + realgdpgr + debt + socexp_t_pmp,
  data = cpds,
  index = c("country", "year"), 
  effect = "individual"
)  

summary(country_effects)
Oneway (individual) effect Within Model

Call:
plm(formula = rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + 
    realgdpgr + debt + socexp_t_pmp, data = cpds, effect = "individual", 
    index = c("country", "year"))

Unbalanced Panel: n = 35, T = 4-32, N = 768

Residuals:
      Min.    1st Qu.     Median    3rd Qu.       Max. 
-0.1215664 -0.0170840 -0.0016936  0.0165061  0.1293962 

Coefficients:
                         Estimate  Std. Error t-value  Pr(>|t|)    
vturn                 -2.0891e-03  2.8088e-04 -7.4376 2.904e-13 ***
judrevJudicial review -3.9645e-02  1.2933e-02 -3.0655  0.002253 ** 
ud                    -7.5212e-04  2.8101e-04 -2.6765  0.007608 ** 
unemp                  3.8075e-03  7.1698e-04  5.3105 1.456e-07 ***
unemp_pmp             -5.8664e-03  3.3172e-03 -1.7685  0.077402 .  
realgdpgr              4.3781e-05  4.6664e-04  0.0938  0.925277    
debt                  -8.4289e-05  8.9307e-05 -0.9438  0.345579    
socexp_t_pmp          -2.0604e-03  7.5389e-04 -2.7330  0.006430 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    0.83227
Residual Sum of Squares: 0.7102
R-Squared:      0.14668
Adj. R-Squared: 0.097246
F-statistic: 15.5778 on 8 and 725 DF, p-value: < 2.22e-16

When controlling for country fixed effects, our model tells us that voter turnout, judicial review, labor union membership, unemployment, and total social expenditure are all statistically significant factors. But before we go any further, let’s just verify the presence of country fixed effects using plmtest().

plmtest(country_effects, effect="individual")

    Lagrange Multiplier Test - (Honda) for unbalanced panels

data:  rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + realgdpgr +  ...
normal = 67.944, p-value < 2.2e-16
alternative hypothesis: significant effects

Since the p-value is less than 0.05, we can continue with our analysis.

Let’s look at our statistically significant variables and find out what their coefficients mean in relative terms. We’ll start with judicial independenc or judrev. Judicial review or judrev is a factor variable coded as 1 for the existence of an independent body and 0 otherwise. We can calculate the relative effect of its coefficient as follows:

-3.9645e-02 / diff(range(cpds$rae_ele, na.rm = TRUE))
[1] -0.09077421

That tells us that there is a decline of 0.040 in electoral fractionalization index in countries with an independent judicial body which amounts to a decrease by 9.08%.

We would like to know the relative effect of other coefficients as well. But instead of calculating them one by one we can simply calculate them all at once:

coefficients(country_effects) / diff(range(cpds$rae_ele, na.rm = TRUE))
                vturn judrevJudicial review                    ud 
        -0.0047832999         -0.0907752600         -0.0017221059 
                unemp             unemp_pmp             realgdpgr 
         0.0087180116         -0.0134320501          0.0001002442 
                 debt          socexp_t_pmp 
        -0.0001929955         -0.0047175664 

Now we can easily interpret the results for every statistically significant factor. Looking at the relative percentages, we can say that none of the other statistically significant factors are having a huge effect on our dependent variable.

For example, a one percent increase in voter turnout reduces electoral fractionalization by merely -0.002, as does one percent increase in social spending. This amounts to a relative decline of about half a percent (0.48%). Unemployment is the only factor with a statistically significant and positive correlation with our dependent variable. A one percent increase in unemployment increases electoral fractionalization by 0.004, a relative increase of less than a percent (0.87%).

None of the other factors (unemployment benefits, government debt and GDP growth) have any statistically significant effect on electoral fractionalization.

Now, let’s run a time fixed effect model to estimate any effects that vary across time but are constant across countries.

time_effects <- plm(
  rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + realgdpgr + debt + socexp_t_pmp,
  data = cpds,
  index = c("country", "year"), 
  effect = "time"
)  
plmtest(time_effects, effect="time")
    Lagrange Multiplier Test - time effects (Honda) for unbalanced panels

data:  rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + realgdpgr +  ...
normal = -1.3643, p-value = 0.9138
alternative hypothesis: significant effects

The plmtest() is comes back insignificant. We do not need to interpret the time fixed effects model and we can stick with the unit (country) fixed effects. However, we will go on and interpret the effects here to practice interpretation.

With fixed time effects, judicial review again is statistically significant, however its effect isn’t nearly as large as it was in the country fixed effects model. In the time fixed effects model, countries with an independent judicial body experience a decline of 0.029 on the electoral fractionalization index which amounts to 6.67%. Government debt has a negative effect although the marginal effect is negligible. An increase in one point in government debt as a percent of the GDP, has an estimated effect of decreasing electoral fractionalization by one-twentieth of one percent (0.05%). Unemployment is positively correlated with our dependent variable. For each increase in unemployment benefits by one percent of the GDP, electoral fractionalization rises by 0.016 or an increase of 3.64%.

8.2.4 Exercise 4

Estimate a twoway model and compare to the previous country and time fixed effect models.

Let’s run a twoway fixed effect model that controls for both country and time fixed effects.

twoway_effects <- plm(
  rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + realgdpgr + debt + socexp_t_pmp,
  data = cpds,
  index = c("country", "year"), 
  effect = "twoway"
)  

summary(twoway_effects)
Twoways effects Within Model

Call:
plm(formula = rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + 
    realgdpgr + debt + socexp_t_pmp, data = cpds, effect = "twoway", 
    index = c("country", "year"))

Unbalanced Panel: n = 35, T = 4-32, N = 768

Residuals:
     Min.   1st Qu.    Median   3rd Qu.      Max. 
-0.098120 -0.017668 -0.001083  0.015371  0.111525 

Coefficients:
                         Estimate  Std. Error t-value  Pr(>|t|)    
vturn                 -1.4588e-03  2.7207e-04 -5.3619 1.122e-07 ***
judrevJudicial review -5.6636e-02  1.2445e-02 -4.5509 6.307e-06 ***
ud                    -6.8797e-04  2.8491e-04 -2.4147  0.016007 *  
unemp                  3.5554e-03  6.8669e-04  5.1776 2.947e-07 ***
unemp_pmp              8.9455e-04  3.4704e-03  0.2578  0.796662    
realgdpgr             -1.4839e-03  5.7279e-04 -2.5906  0.009781 ** 
debt                  -2.4835e-04  8.4592e-05 -2.9358  0.003437 ** 
socexp_t_pmp          -5.3631e-03  8.4541e-04 -6.3438 4.044e-10 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Total Sum of Squares:    0.7043
Residual Sum of Squares: 0.5786
R-Squared:      0.17847
Adj. R-Squared: 0.092057
F-statistic: 18.8459 on 8 and 694 DF, p-value: < 2.22e-16
coefficients(twoway_effects) / diff(range(cpds$rae_ele, na.rm = TRUE))
                vturn judrevJudicial review                    ud 
         -0.003340257          -0.129678436          -0.001575240 
                unemp             unemp_pmp             realgdpgr 
          0.008140687           0.002048229          -0.003397621 
                 debt          socexp_t_pmp 
         -0.000568639          -0.012279748 

Judicial review once again is not only statistically significant but has a rather substantial effect on electoral fractionalization. Countries with an independent judicial body experience a decline of 0.057. This effect amounts to a decline of 12.97%. Voter turnout has a statistically significant negative effect on electoral fractionalization with a percentage inrease estimated to decrease electoral fractionalization by 0.001 or 0.33%. Similarly, a rise in real GDP growth by one percent is estimated to decrease electoral fractionalization by 0.001 (0.34%). When interpreting the effects of voter turnout and GDP growth it is important to keep in mind that a year-over-year increase of one percent in GDP growth is rather substantial, whereas it is not uncommon to see voter turnout fluctuating by several percentage points from one election to another.

A one percent increase in union membership has an estimated effect of decreasing our dependent variable by 0.001 (0.16%), while a one percent increase in unemployment increases it by 0.004 or 0.81%. Social expenditure also has a statistically significant effect with a one percent increase driving electoral fractionalization down by 0.005 or 1.23%, which is still relatively small.

We can now compare the three models we’ve estimated side-by-side.

screenreg(list(country_effects, time_effects, twoway_effects),
          custom.model.names = c("Country Fixed Effects", 
                                 "Time Fixed Effects", 
                                 "Twoway Fixed Effects"))

======================================================================================
                       Country Fixed Effects  Time Fixed Effects  Twoway Fixed Effects
--------------------------------------------------------------------------------------
vturn                   -0.00 ***              -0.00               -0.00 ***          
                        (0.00)                 (0.00)              (0.00)             
judrevJudicial review   -0.04 **               -0.03 ***           -0.06 ***          
                        (0.01)                 (0.01)              (0.01)             
ud                      -0.00 **                0.00 *             -0.00 *            
                        (0.00)                 (0.00)              (0.00)             
unemp                    0.00 ***               0.00                0.00 ***          
                        (0.00)                 (0.00)              (0.00)             
unemp_pmp               -0.01                   0.02 ***            0.00              
                        (0.00)                 (0.00)              (0.00)             
realgdpgr                0.00                   0.00 **            -0.00 **           
                        (0.00)                 (0.00)              (0.00)             
debt                    -0.00                  -0.00 *             -0.00 **           
                        (0.00)                 (0.00)              (0.00)             
socexp_t_pmp            -0.00 **                0.01 ***           -0.01 ***          
                        (0.00)                 (0.00)              (0.00)             
--------------------------------------------------------------------------------------
R^2                      0.15                   0.23                0.18              
Adj. R^2                 0.10                   0.18                0.09              
Num. obs.              768                    768                 768                 
======================================================================================
*** p < 0.001, ** p < 0.01, * p < 0.05

By comparing the models we can see that Judicial review is statistically significant in every model and is negatively correlated with electoral fractionalization. Real GDP growth and social spending are positively correlated in the time effects model but have a negative correlation in the twoway fixed effect model. A one point increase in GDP growth is estimated to increase electoral fractionalization by 0.004 (0.94%) in the time fixed effect model and decrease it by 0.001 (0.34%) in the twoway fixed effect model. Similarly, a one percent increase in social spending is estimated to increase electoral fractionalization by 0.006 (1.26%) in the time fixed effect model and decrease it by 0.005 (1.23%) in the twoway fixed effect model.

The effect of voter turnout in country fixed effect model is twice its effect in the twoway fixed effect model, and it is not statistically significant in the time fixed effects model. A one percent increase in voter turnout is estimated to decrease electoral fractionalization by 0.002 with country fixed effects, compared to 0.001 in the towway fixed effects model.

Unemployment effects in a country fixed effects model are similar to the effects in twoway fixed effect models and they are not statistically significant in model where we only control for time fixed effects. When unemployment increases by 1 percent it has an estimated effect of an increase of 0.004 in our dependent variable in both country fixed effects and twoway effects models, which amounts to a percentage increase of just under 1 percent.

8.2.5 Exercise 5

Test for serial correlation and cross sectional dependence in the twoway model. We can test serial correlation with the Breusch-Godfrey test to see if there is any temporal dependence in our model.

pbgtest(twoway_effects)

    Breusch-Godfrey/Wooldridge test for serial correlation in panel
    models

data:  rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + realgdpgr +     debt + socexp_t_pmp
chisq = 311.87, df = 4, p-value < 2.2e-16
alternative hypothesis: serial correlation in idiosyncratic errors

The Breusch-Godfrey test tells us that our model does indeed suffer from autocorrelated standard errors.

Next, we run the Pesaran cross-sectional dependence test to check for spatial dependence in our model.

pcdtest(twoway_effects)

    Pesaran CD test for cross-sectional dependence in panels

data:  rae_ele ~ vturn + judrev + ud + unemp + unemp_pmp + realgdpgr +     debt + socexp_t_pmp
z = -3.8849, p-value = 0.0001024
alternative hypothesis: cross-sectional dependence

The Pesaran CD test confirms the presence of cross-sectional dependence in our model.

8.2.6 Exercise 6

If either serial correlation or cross sectional dependence is present, use the methods discussed in the seminar to obtain heteroskedastic and autocorrelation consistent standard errors.

From the Breusch-Godfrey test we know that we have serial correlation in the error term of our model so we need to adjust the standard errors. We can use the "allerano" method to obtain heteroskedasticity and autocorrelation (HAC) consistent standard errors. We first obtain a HAC robust covariance matrix from vcovHC() by specifying method = "arellano" and pass it along to coeftest() for adjusting the standard errors.

twoway_hac <- coeftest(
  twoway_effects, vcov = vcovHC(twoway_effects, method = "arellano", type = "HC3")
)

twoway_hac

t test of coefficients:

                         Estimate  Std. Error t value  Pr(>|t|)    
vturn                 -0.00145883  0.00067683 -2.1554 0.0314745 *  
judrevJudicial review -0.05663615  0.04175377 -1.3564 0.1754028    
ud                    -0.00068797  0.00078204 -0.8797 0.3793147    
unemp                  0.00355539  0.00114190  3.1136 0.0019244 ** 
unemp_pmp              0.00089455  0.00753789  0.1187 0.9055681    
realgdpgr             -0.00148389  0.00053781 -2.7591 0.0059485 ** 
debt                  -0.00024835  0.00014049 -1.7678 0.0775399 .  
socexp_t_pmp          -0.00536309  0.00150857 -3.5551 0.0004035 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Since the Pesaran CD test told us that we have cross-sectional dependence in our model, we need to adjust for spatial dependence as well. Fortunately, the Driscoll and Kraay’s (1998) SCC method gives us heteroskedasticity and autocorrelation consistent errors that are also robust to cross-sectional dependence.

twoway_scc <- coeftest(
  twoway_effects, 
  vcov = vcovSCC(twoway_effects, type="HC3", cluster = "group")
)

twoway_scc

t test of coefficients:

                         Estimate  Std. Error t value  Pr(>|t|)    
vturn                 -0.00145883  0.00052318 -2.7884  0.005442 ** 
judrevJudicial review -0.05663615  0.04165998 -1.3595  0.174434    
ud                    -0.00068797  0.00081061 -0.8487  0.396332    
unemp                  0.00355539  0.00112006  3.1743  0.001568 ** 
unemp_pmp              0.00089455  0.00667793  0.1340  0.893476    
realgdpgr             -0.00148389  0.00045927 -3.2310  0.001292 ** 
debt                  -0.00024835  0.00012329 -2.0143  0.044361 *  
socexp_t_pmp          -0.00536309  0.00107777 -4.9761 8.191e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

8.2.7 Exercise 7

Compare the HAC and spatially robust standard errors with the twoway model estimated earlier.

The twoway fixed effect model with heteroskedastic and autocorrelation consistent (HAC) standard errors and with SCC corrected standard errors are presented in a side-by-side comparison below.

screenreg(
  list(twoway_effects, twoway_hac, twoway_scc),
  custom.model.names = c("Twoway", "Twoway (HAC)", "Twoway (SCC)")
)

=============================================================
                       Twoway      Twoway (HAC)  Twoway (SCC)
-------------------------------------------------------------
vturn                   -0.00 ***  -0.00 *       -0.00 **    
                        (0.00)     (0.00)        (0.00)      
judrevJudicial review   -0.06 ***  -0.06         -0.06       
                        (0.01)     (0.04)        (0.04)      
ud                      -0.00 *    -0.00         -0.00       
                        (0.00)     (0.00)        (0.00)      
unemp                    0.00 ***   0.00 **       0.00 **    
                        (0.00)     (0.00)        (0.00)      
unemp_pmp                0.00       0.00          0.00       
                        (0.00)     (0.01)        (0.01)      
realgdpgr               -0.00 **   -0.00 **      -0.00 **    
                        (0.00)     (0.00)        (0.00)      
debt                    -0.00 **   -0.00         -0.00 *     
                        (0.00)     (0.00)        (0.00)      
socexp_t_pmp            -0.01 ***  -0.01 ***     -0.01 ***   
                        (0.00)     (0.00)        (0.00)      
-------------------------------------------------------------
R^2                      0.18                                
Adj. R^2                 0.09                                
Num. obs.              768                                   
=============================================================
*** p < 0.001, ** p < 0.01, * p < 0.05

The “Twoway” model suffers from heteroskedasticity, autocorrelation and cross-sectional dependence while the “Twoway (HAC)” model suffers only from cross-sectional dependence. The “Twoway (SCC)” model corrects for heteroskedastic and autocorrelation consistent (HAC) standard errors that are also robust to cross-sectional dependence and is the correct model out of the three models we compared above.

8.2.8 Exercise 8

Display the results in publication-ready tables and discuss the substantively significant findings.

We’ll present all the models of interest in a publication-ready table using screenreg().

screenreg(list(country_effects, twoway_effects, twoway_hac, twoway_scc),
          custom.model.names = c("Country Effects", 
                                 "Twoway Effects", 
                                 "Twoway (HAC)", 
                                 "Twoway (SCC)"))

==================================================================================
                       Country Effects  Twoway Effects  Twoway (HAC)  Twoway (SCC)
----------------------------------------------------------------------------------
vturn                   -0.00 ***        -0.00 ***      -0.00 *       -0.00 **    
                        (0.00)           (0.00)         (0.00)        (0.00)      
judrevJudicial review   -0.04 **         -0.06 ***      -0.06         -0.06       
                        (0.01)           (0.01)         (0.04)        (0.04)      
ud                      -0.00 **         -0.00 *        -0.00         -0.00       
                        (0.00)           (0.00)         (0.00)        (0.00)      
unemp                    0.00 ***         0.00 ***       0.00 **       0.00 **    
                        (0.00)           (0.00)         (0.00)        (0.00)      
unemp_pmp               -0.01             0.00           0.00          0.00       
                        (0.00)           (0.00)         (0.01)        (0.01)      
realgdpgr                0.00            -0.00 **       -0.00 **      -0.00 **    
                        (0.00)           (0.00)         (0.00)        (0.00)      
debt                    -0.00            -0.00 **       -0.00         -0.00 *     
                        (0.00)           (0.00)         (0.00)        (0.00)      
socexp_t_pmp            -0.00 **         -0.01 ***      -0.01 ***     -0.01 ***   
                        (0.00)           (0.00)         (0.00)        (0.00)      
----------------------------------------------------------------------------------
R^2                      0.15             0.18                                    
Adj. R^2                 0.10             0.09                                    
Num. obs.              768              768                                       
==================================================================================
*** p < 0.001, ** p < 0.01, * p < 0.05

NOTE: In the screenreg() output, the coefficients are rounded to 2 decimal places by default thus making it seem as if many of them were zero. You can change the number of decimal places displayed, but it is more important to understand that even small coefficients don’t necessarily mean that their effects are small and certainly does not mean that the variable is not statistically significant. When interpreting your results, always keep in mind the scale and range of your independent and dependent variables.

The country effects model was the first model we estimated. However, since our data has time fixed effects as well, we estimated a twoway fixed effects model that controls for both country and time fixed effects. After correcting for heteroskedasticity and temporal and spatial correlation, our final model was the “Twoway (SCC)”.

twoway_scc

t test of coefficients:

                         Estimate  Std. Error t value  Pr(>|t|)    
vturn                 -0.00145883  0.00052318 -2.7884  0.005442 ** 
judrevJudicial review -0.05663615  0.04165998 -1.3595  0.174434    
ud                    -0.00068797  0.00081061 -0.8487  0.396332    
unemp                  0.00355539  0.00112006  3.1743  0.001568 ** 
unemp_pmp              0.00089455  0.00667793  0.1340  0.893476    
realgdpgr             -0.00148389  0.00045927 -3.2310  0.001292 ** 
debt                  -0.00024835  0.00012329 -2.0143  0.044361 *  
socexp_t_pmp          -0.00536309  0.00107777 -4.9761 8.191e-07 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Since twoway_scc is not a model object but just a matrix of coefficients that we obtained from coeftest(), we cannot use the coefficients() function here. Instead we can simply extract the coefficients from the first column of the matrix to get the relative effects of each variable.

twoway_scc[,1] / diff(range(cpds$rae_ele, na.rm = TRUE))
                vturn judrevJudicial review                    ud 
         -0.003340257          -0.129678436          -0.001575240 
                unemp             unemp_pmp             realgdpgr 
          0.008140687           0.002048229          -0.003397621 
                 debt          socexp_t_pmp 
         -0.000568639          -0.012279748 

In the “Twoway (SCC)” model, voter turnout, unemployment, GDP growth, government debt and social expenditure are all statistically significant. A one percent increase in voter turnout is estimated to decrease electoral fractionalization by one-third of a percent (0.33%) and so is one percent increase in GDP growth. Unemployment rate is the only variable with a positive effect where one percent increase has the estimated effect of increasing electoral fractionalization by 0.81%. A one percent increase in government debt has a negative effect of 0.06% on electoral fractionalization. Finally, social expenditure is estimated to decrease electoral fractionalization by 0.005 (1.23%) in the twoway SCC model.

The remaining factors, namely, judicial review, union membership, and unemployment benefits do not have a statistically significant effect on electoral fractionalization.