Figure Trend

just uses the preferred model = model 3 with 4 lags

Package Imports:

library(ggplot2)
library(plm)
library(plotly)

Model Imports

load("output/models.Rdata")

The Trend Estimate

Formula: \[ effect_{t} = \hat\beta + \sum_{j=1}^p \hat\gamma_j * effect_{t-j} \]

dem_shortrun <- coef(model3)["dem"]
lag1 <- (coef(model3)[2])
lag2 <- (coef(model3)[3])
lag3 <- (coef(model3)[4])
lag4 <- (coef(model3)[5])
effect1 <- dem_shortrun
effect2 <- (effect1 * lag1) + dem_shortrun
effect3 <- (effect2 * lag1) + (effect1 * lag2) + dem_shortrun
effect4 <- (effect3 * lag1) + (effect2 * lag2) + (effect1 * lag3) + dem_shortrun

effects <- c(effect1,effect2, effect3, effect4)
for (i in 5:30) {
  eff <- (effects[i-1] * lag1) + (effects[i-2] * lag2) + (effects[i-3] * lag3) + (effects[i-4] * lag4) + dem_shortrun
  effects <- c(effects, eff)
}

Standard Error

Extract The given Standard Error from the model

Repeat the same process as above to get the standard error for point in time t

SE_estimate <- summary(model3)$coefficients[1, 2] #1 = dem coeffiecient, 2 =  Std Error
SE1 <- SE_estimate
SE2 <- (SE1 * lag1) + SE_estimate
SE3 <- (SE2 * lag1) + (SE1 * lag2) + SE_estimate
SE4 <- (SE3 * lag1) + (SE2 * lag2) + (SE1 * lag3) + SE_estimate

SEs <- c(SE1, SE2, SE3, SE4)
for (i in 5:30) {
  SEi <- (SEs[i-1] * lag1) + (SEs[i-2] * lag2) + (SEs[i-3] * lag3) + (SEs[i-4] * lag4) + SEs[1]
  SEs <- append(SEs, SEi)
}

Confidence Intervals

Calculate the upper and lower confidence intervals for each point in time t using:

  • the standard error for each point in time t
  • the critical value for a 95% confidence interval (1.96)
upper <- vector()
lower <- vector()
for (i in 1:30) {
  upper <- append(upper, effects[i] + (1.96 * SEs[i]))
  lower <- append(lower, effects[i] - (1.96 * SEs[i]))
}

Plot

Create a dataframe with the trend estimate, upper and lower confidence intervals, useful for comparing with the Data from ANRR

trend <- data.frame(effects, upper, lower)
trend

Plot the trend estimate and the confidence intervals using ggplot()

fig <- ggplot(trend, aes(x = 1:30, y = effects)) +
  geom_line() + #trend estimate
  geom_line(aes(y = upper), linetype = "dashed") + #upper confidence interval
  geom_line(aes(y = lower), linetype = "dashed") + #lower confidence interval
  geom_hline(yintercept = seq(0,30,10), color="gray") + # horizontal lines 
  labs(
    x = "Years since Democratization",  #x axis label
    y = "Change in GDP per Capita Log Points") +  #y axis label
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) + # disable the grid
  theme_classic() #for boring style like in paper

Save the plot and preview it

ggsave("output/FigureTrend.png",fig, width = 8, height = 5, units = "in")
ggplotly(fig)