Datasets

Install packages

For this class we need to install the following initial packages:

library(tidyverse)
library(readxl)
library(countrycode)
library(devtools)
library(haven)
library(ggmap)
library(unvotes)

Economic development / well-being

World Bank - World Development Indicators

library(wbstats)
wb_search("gdp") %>% 
  View()
gdp <- wb(country = "countries_only", 
          return_wide = TRUE,
          indicator = c("NY.GDP.PCAP.CN")) %>% 
  mutate(date = as.numeric(date)) %>% as_tibble()

gdp %>%
  filter(country %in% c("Poland", "Switzerland")) %>%
  ggplot(aes(x = date, y = NY.GDP.PCAP.CN, col = country)) +
  geom_line()

Penn World Tables

maddison <- read_dta("https://www.rug.nl/ggdc/historicaldevelopment/maddison/data/mpd2018.dta")
maddison

Inequality

In this website you can find exercises with the All Ginis dataset.

library(devtools)
install_github("WIDworld/wid-r-tool")
library(wid)
?download_wid
wid <- download_wid(
  indicators = "sfiinc", #select indicator
  areas = c("FR", "CN", "US", "DE", "GB", "RU"), #select countries
  perc = "p99p100", #select percentile
  ) %>% as_tibble()

wid %>%
  ggplot(aes(x = year, y = value, col = country)) +
  geom_point(alpha = 0.2) +
  geom_smooth(se = FALSE)

PovcalNet

library(povcalnetR)
pov <- povcalnet(country = c("MDG", "COG", "RWA"), 
                 povline = 1.9) #select poverty line
pov %>%
  ggplot(aes(x = year, y = povertygap, col = countryname)) +
  geom_line()

Human Development

In this website you will find a teaching module to understand and use the HDI.

Sustainable development goals

download.file("https://dashboards.sdgindex.org/static/downloads/files/SDR%202021%20-%20Database.xlsx",
              "SDR2020Database.xlsx")
sdg4 <- read_xlsx("SDR2020Database.xlsx", sheet = 4) #what is it
sdg5 <- read_xlsx("SDR2020Database.xlsx", sheet = 5) #what is it

glimpse(sdg4)
glimpse(sdg5) #NAs

Democracy

devtools::install_github("vdeminstitute/vdemdata")
library(vdemdata)

plot_indicator("v2x_libdem", 
               "Bolivia", 
               min_year = 1975, max_year = 2020)

Governance

install_github("ropengov/rqog")
library(rqog)

qog_basic <- read_qog(which_data = "basic") %>%
  tibble()

Multilevel governance

download.file("https://www.arjanschakel.nl/images/RAI/RAI_region-2021.xlsx", "RAI.xlsx")
rai_reg <- read_xlsx("RAI.xlsx")
rai_reg %>%
  group_by(region_name1) %>%
  filter(RAI == max(RAI)) %>%
  group_by(region_name1, RAI) %>%
  filter(year == max(year)) %>%
  arrange(desc(RAI)) %>%
  ungroup() %>%
  transmute(country_name, region_name1, year, 
            across(c(RAI, selfrule, sharedrule), ~round(.,1))) 

Political parties

Text analysis

library(manifestoR)
mp_setapikey("manifesto_apikey.txt") #busca al perfil d'usuari
cpm <- mp_maindataset()
cpm %>%
  mutate(edate = as.Date(edate, "%d/%m/%Y")) %>%
  filter(countryname == "Sweden") %>% 
  filter(edate == last(edate)) %>%
  arrange(desc(date)) %>%
  select(partyname, edate, per107)

Expert surveys

load("Global Party Survey by Party SPSS V2_1_Apr_2020.rdata")

table %>% 
  filter(Country == "Afghanistan") %>% 
  ggplot(aes(x = V17, y = V20)) +
  geom_point() +
  geom_text(aes(label = Partyabb), nudge_y = 0.05)

Cooperation

download.file("https://correlatesofwar.org/data-sets/bilateral-trade/cow_trade_4.0/at_download/file",
              destfile = "COWTrade.zip")
unzip("COWTrade.zip")
trade <- read_csv("COW_Trade_4.0/Dyadic_COW_4.0.csv")
trade %>% 
  filter(ccode1 == 2, ccode2 == 20) %>% 
  ggplot(aes(x = year)) +
  geom_line(aes(y = smoothflow1), col = "red") +
  geom_line(aes(y = smoothflow2), col = "blue")

Conflict

Game of Thrones

got <- read.csv("https://github.com/chrisalbon/war_of_the_five_kings_dataset/raw/master/5kings_battles_v1.csv") %>% 
  tibble()
got %>% View

Uppsala Conflict Data Programme

download.file("https://ucdp.uu.se/downloads/ucdpprio/ucdp-prio-acd-211-RData.zip",
              destfile = "UCDP.zip")
unzip("UCDP.zip")
load("ucdp-prio-acd-211.rdata")
tibble(UcdpPrioConflict_v21_1)

Correlates of War

download.file("https://correlatesofwar.org/data-sets/MIDs/mid-5-data-and-supporting-materials.zip/@@download/file/MID%205%20Data%20and%20Supporting%20Materials.zip", "MID5.zip")
unzip("MID5.zip")
midi <- read_csv("MIDI 5.0.csv")
head(midi, 10)
download.file("https://correlatesofwar.org/data-sets/MIDLOC/midloc_2-1.zip/@@download/file/MIDLOC_2.1.zip", "MIDLOC_2.1.zip")
unzip("MIDLOC_2.1.zip")
midloci <- read_csv("MIDLOCI_2.1.csv") 
head(midloci)

midijoin <- midi %>%
  inner_join(midloci, by = c("incidnum", "dispnum")) %>%
  select(dispnum, incidnum, location = midloc2_location, measuringpoint = midloc2_measuringpoint,
         lon = midloc2_xlongitude, lat = midloc2_ylatitude,
         styear, endyear, duration, tbi, fatalpre, fatality, hostlev, numa) %>%
  mutate(fatality = case_when(fatality == 0 ~ "None",
                              fatality == 1 ~ "1-25",
                              fatality == 2 ~ "26-100",
                              fatality == 3 ~ "101-250",
                              fatality == 4 ~ "251-500",
                              fatality == 5 ~ "501-999",
                              fatality == 6 ~ "More than 999",
                              TRUE ~ "Missing"),
         hostlev = case_when(hostlev == 1 ~ "No militarized action",
                             hostlev == 2 ~ "Threat to use force",
                             hostlev == 3 ~ "Display of force",
                             hostlev == 4 ~ "Use of force",
                             hostlev == 4 ~ "War"))

midi_map <- get_stamenmap(bbox = c(top = 75,
                                    left = -170, right = 170,
                                    bottom = -58),
                                    zoom = 2, 
                                    maptype = "toner-lite")

midi_map %>% 
  ggmap(base_layer = ggplot(aes(x = lon, y = lat,
                                col = hostlev, size = tbi), 
  data = filter(midijoin, dispnum == 3551))) + 
  geom_point(alpha = 0.4) 

National Material Capabilities

download.file("https://correlatesofwar.org/data-sets/national-material-capabilities/nmc_documentation-6-0.zip/@@download/file/NMC_Documentation%206.0.zip", "NMC6.zip")
unzip("NMC6.zip")
unzip("NMC-60-abridged.zip")
nmc <- read_csv("NMC-60-abridged.csv")
nmc %>% 
  filter(stateabb %in% c("USA", "CHN")) %>%
  ggplot(aes(x = year, y = upop, col = stateabb)) +
  geom_line()

Other: UN Votes

library(unvotes)
un_votes #vote
un_roll_calls #description
un_roll_call_issues #topic

United States: Was there any difference in favourable UNGA voting between Carter and Reagan administrations?

us_un <- un_roll_calls %>% 
  inner_join(un_votes) %>% 
  select(-c(country, descr, short)) %>%
  filter(country_code == "US", vote != "abstain", 
         between(date, as.Date("1977-01-20"),
                 as.Date("1989-01-20"))) %>% 
  mutate(president = if_else(date < as.Date("1980-01-20"),"Carter", "Reagan")) %>% 
    droplevels()
table(us_un[,9:10])

Israel: Does Israel vote differently in Middle East-related issues?

israel_un <- un_votes %>%
  inner_join(un_roll_call_issues) %>%
  filter(country == "Israel", vote != "abstain") %>%
  mutate(me = if_else(short_name == "me", "Middle East", "Other")) %>%
  select(me, vote) %>%
  droplevels()
table(israel_un)

USA - USSR: ¿Do the U.S. vote differently if the word USSR appears in the title of the resolution?

us_ussr_un <- un_roll_calls %>%
  mutate(ussr = str_detect(descr, "USSR")) %>%
  inner_join(un_votes) %>%
  filter(country_code == "US", vote != "abstain") %>%
  select(ussr, vote) %>%
  droplevels()
table(us_ussr_un)
Previous