Introduction to Our World in Data using R: What is the relation between internet usage and democracy?
Setup
#install.packages("owidR")
#install.packages("plotly")
suppressWarnings(suppressMessages({
library(owidR)
library(dplyr)
library(ggplot2)
library(plm)
library(texreg)
library(ggrepel)
library(stargazer)
library(ExPanDaR)
library(plotly)
}))
options(repr.plot.width = 7, repr.plot.height = 4)
Search data
owid_search("internet")
owid_search("democrac")
Import data
# Use the chart_id and rename the column to a shorter name
internet <- owid("share-of-individuals-using-the-internet", rename = "internet_use")
internet
democracy <- owid("political-regime-updated2016-distinction-democracies-and-full-democracies",
rename = "polity") %>%
filter(year %in% 1960:2020)
democracy
owid_source(internet)
owid_source(democracy)
Plot evolution of the world
owid_plot(internet, filter = "World") +
labs(title = "Share of the World Population using Internet") +
scale_y_continuous(limits = c(0, 50))
#owid_plot(democracy, filter = "World")
Plot cross-country differences
owid_map(internet, year = 2017, palette = "YlGn") +
labs(title = "Share of Population Using Internet in 2017")
owid_map(democracy, palette = "YlGn") +
labs(title = "Political Regime (Polity IV)")
Plot evolution of selected countries
owid_plot(internet, summarise = FALSE, filter = c("United Kingdom", "Spain", "Russia", "Egypt", "Nigeria")) +
labs(title = "Share of Population with Using Internet") +
scale_y_continuous(limits = c(0, 100), labels = scales::label_number(suffix = "%")) # The labels argument allows you to make it clear that the value is a percentage
Panel regression
Importing control variables
gdp <- owid("gdp-per-capita-worldbank", rename = "gdp")
gov_exp <- owid("total-gov-expenditure-gdp-wdi", rename = "gov_exp")
age_dep <- owid("age-dependency-ratio-of-working-age-population", rename = "age_dep")
unemployment <- owid("unemployment-rate", rename = "unemp")
Merge datasets
data <- internet %>%
left_join(democracy) %>%
left_join(gdp) %>%
left_join(gov_exp) %>%
left_join(age_dep) %>%
left_join(unemployment)
Correlation: Internet and democracy
data %>%
filter(year == 2015) %>%
ggplot(aes(internet_use, polity)) +
geom_point(colour = "#57677D") +
geom_smooth(method = "lm", colour = "#DC5E78") +
labs(title = "Internet Use and Polity IV Score in 2015", x = "Internet Use", y = "Polity IV") +
theme_owid()
Country fixed effects models
fe_model <- plm(polity ~ internet_use, data,
effect = c("individual"), index = "entity")
fe_model_2 <- plm(polity ~ internet_use + gdp + gov_exp + age_dep + unemp, data,
effect = c("individual"), index = "entity")
stargazer(fe_model, fe_model_2, type="text")