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
What is the evolution of the GDP per capita in the US and China?
library(wbstats)
wb_search("gdp.*capita") |>
View()
gdp <- wb_data(country = "countries_only",
return_wide = TRUE,
indicator = c("NY.GDP.PCAP.CD")) |>
mutate(date = as.numeric(date)) %>% as_tibble()
gdp %>%
filter(country %in% c("United States", "China")) |>
ggplot(aes(x = date, y = NY.GDP.PCAP.CD, 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.
What is the fiscal income of the Top1% of the population in France, China, US, Germany, Great Britain, and Russia?
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
How many inhabitants (%) do live in poverty (1.9$/day) in Madagascar, Congo, and Rwanda?
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-2022-Database.xlsx",
"SDR-Data.xlsx")
sdg4 <- read_xlsx("SDR-Data.xlsx", sheet = 4) #evolution
sdg5 <- read_xlsx("SDR-Data.xlsx", sheet = 5) #each indicator
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") #find at user profile
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 == "Spain") %>%
ggplot(aes(x = V17, y = V20)) +
geom_point() +
geom_text(aes(label = Partyabb), nudge_y = 0.05)
Cooperation
download.file("https://correlatesofwar.org/wp-content/uploads/COW_Trade_4.0.zip",
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/wp-content/uploads/MID-5-Data-and-Supporting-Materials.zip", "MID5.zip")
unzip("MID5.zip")
midi <- read_csv("MIDI 5.0.csv")
head(midi, 10)
download.file("https://correlatesofwar.org/wp-content/uploads/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 = 47,
left = 12, right = 25,
bottom = 40),
zoom = 5,
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/wp-content/uploads/NMC_Documentation-6.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 = cinc, col = stateabb)) +
geom_line()
Other: More 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)