Use the Global Terrorism Database contained in GTD.csv
to estimate a model where the number of terrorist attacks in a country-year is explained by GDP per capita and VDEMâ€™s polyarchy score (v2x_polyarchy). WDI
and the vdem
packages (https://github.com/xmarquez/vdem) are your friends. Include a random intercept term by country, and allow the mean of country random intercepts to vary by year. Produce a publication quality table of your results. Is there more variation between countries or between years?
library(tidyverse)
library(WDI)
library(vdem)
library(lme4)
library(texreg)
## load GTD
gtd <- read.csv('~/Dropbox/Datasets/GTD/GTD.csv')
## get GDP
wb <- WDI(indicator = c('NY.GDP.PCAP.KD'), start = 1970, end = 2014) %>%
rename(gdp = NY.GDP.PCAP.KD) %>%
select(-iso2c)
## get polyarchy
vdem <- extract_vdem(name_pattern = 'v2x_polyarchy', include_uncertainty = F) %>%
select(country = vdem_country_name, year, polyarchy = v2x_polyarchy) %>%
filter(year %in% 1970:2014)
## collapse GTD and combine data
gtd <- gtd %>% group_by(country_txt, iyear) %>%
summarize(attacks = n()) %>% # calculate attacks per year
rename(country = country_txt, year = iyear) %>% # rename columns for joining
filter(country != '') %>% # drop attacks without a country
left_join(wb) %>% # join gdp
left_join(vdem) %>% # join polyarchy
mutate_at(vars(gdp, polyarchy), scale) %>% # scale gdp and polyarchy
na.omit() # drop incomplete observations
## fit model
mod <- glmer(attacks ~ gdp + polyarchy + (1 | year / country), data = gtd, family = poisson(link = 'log'))
## present table
htmlreg(mod, stars = .05, custom.coef.names = c('Intercept', 'GDP<sub>PC</sub>',
'Polyarchy'))
Model 1 | ||
---|---|---|
Intercept | 2.02^{*} | |
(0.05) | ||
GDP_{PC} | -0.06 | |
(0.04) | ||
Polyarchy | 0.17^{*} | |
(0.04) | ||
AIC | 21607.07 | |
BIC | 21636.45 | |
Log Likelihood | -10798.54 | |
Num. obs. | 2634 | |
Num. groups: country:year | 2634 | |
Num. groups: year | 44 | |
Var: country:year (Intercept) | 3.15 | |
Var: year (Intercept) | 0.05 | |
^{*}p < 0.05 |
The variance of the year random intercept is 0.05 while the variance of the country random intercept is 3.15, so there is much more variation across countries than across years.