library(ggplot2)
library(plm)
library(plotly)
Figure Trend
just uses the preferred model = model 3 with 4 lags
Package Imports:
Model Imports
load("output/models.Rdata")
The Trend Estimate
Formula: \[ effect_{t} = \hat\beta + \sum_{j=1}^p \hat\gamma_j * effect_{t-j} \]
<- coef(model3)["dem"]
dem_shortrun <- (coef(model3)[2])
lag1 <- (coef(model3)[3])
lag2 <- (coef(model3)[4])
lag3 <- (coef(model3)[5]) lag4
<- dem_shortrun
effect1 <- (effect1 * lag1) + dem_shortrun
effect2 <- (effect2 * lag1) + (effect1 * lag2) + dem_shortrun
effect3 <- (effect3 * lag1) + (effect2 * lag2) + (effect1 * lag3) + dem_shortrun
effect4
<- c(effect1,effect2, effect3, effect4) effects
for (i in 5:30) {
<- (effects[i-1] * lag1) + (effects[i-2] * lag2) + (effects[i-3] * lag3) + (effects[i-4] * lag4) + dem_shortrun
eff <- c(effects, eff)
effects }
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
<- summary(model3)$coefficients[1, 2] #1 = dem coeffiecient, 2 = Std Error SE_estimate
<- SE_estimate
SE1 <- (SE1 * lag1) + SE_estimate
SE2 <- (SE2 * lag1) + (SE1 * lag2) + SE_estimate
SE3 <- (SE3 * lag1) + (SE2 * lag2) + (SE1 * lag3) + SE_estimate
SE4
<- c(SE1, SE2, SE3, SE4) SEs
for (i in 5:30) {
<- (SEs[i-1] * lag1) + (SEs[i-2] * lag2) + (SEs[i-3] * lag3) + (SEs[i-4] * lag4) + SEs[1]
SEi <- append(SEs, SEi)
SEs }
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)
<- vector()
upper <- vector() lower
for (i in 1:30) {
<- append(upper, effects[i] + (1.96 * SEs[i]))
upper <- append(lower, effects[i] - (1.96 * SEs[i]))
lower }
Plot
Create a dataframe with the trend estimate, upper and lower confidence intervals, useful for comparing with the Data from ANRR
<- data.frame(effects, upper, lower)
trend trend
Plot the trend estimate and the confidence intervals using ggplot()
<- ggplot(trend, aes(x = 1:30, y = effects)) +
fig 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)