# Untitled

unknown
plain_text
a month ago
4.7 kB
1
Indexable
Never
```---
title: "Data Assignment 1"
subtitle: "States, Regimes and Institutions"
author: "Pablo Pardavila Romero"
format: pdf
editor: visual
---

1.  **We want to check the growth of democratic regimes after WWI (1900-20) and the collapse of the Soviet Union (1986-1994). Generate graphics that show the evolution of the number of democracies by year using `e_boix_regime` (Boix, Miller and Rosato's measurement of democracy).**

```{r}
#| echo: FALSE
#| message: false
#| warning: false
#| results: hide
library(tidyverse)

#First of all, it is necessary to know what the variable is measuring. According to the codebook e_boix_regime is a ``dichotomous democracy measure based on contestation and participation. Countries coded democratic have (1) political leaders that are chosen through free and fair elections and (2) a minimal level of suffrage."

#My first intuition is to do a graph like this. But, because of the nature
#of the data, it comes up with just an average of the variable for 1800-2015.
```

```{r}
#| echo: false

#| message: false
#| warning: false
#| results: hide

#For that reason it is first necessary to filter the data, (first for the post WWI
#period and then for the collapse of the USSR) ONLY
#for democracies (i.e., e_boix_regime == 1)

#Post WWI (1900-1920)
democracy_counts_1900_1920 <- vdem |>
filter(year >= 1900, year <= 1920, e_boix_regime == 1) |>
group_by(year) |>
summarise(num_democracies = n())

ggplot(data = democracy_counts_1900_1920, aes(x = year, y = num_democracies)) +
geom_line() +
labs(x = "Year", y = "No. of democracies",
title = "Evolution of No. of democracies (1900-1920)")

#Collapse USSR (1986-1994)

#| fig-width: 7
#| fig-height: 5
democracy_counts_1986_1994 <- vdem |>
filter(year >= 1986, year <= 1994, e_boix_regime == 1) |>
group_by(year) |>
summarise(num_democracies = n())

ggplot(data = democracy_counts_1986_1994, aes(x = year, y = num_democracies)) +
geom_line() +
labs(x = "Year", y = "No. of democracies",
title = "Evolution of No. of democracies (1900-1920)")
```

2.  **Check the regression coefficient between log of GDPp (`e_migdppcln`) and V-Dem polyarchy (`v2x_polyarchy`) by periods of 20 years starting in 1860-79. Represent graphically the temporal evolution of the coefficient (do not include any control, or the lag of the dependent variable, this is the sheer correlation). Do the same but with region of the world (`e_regionpol_6C`) instead of time periods. Interpret the results.**

`coef(lm(e_migdppcln ~ v2x_polyarchy)` (regression 1.1) and `coef(lm(v2x_polyarchy ~ e_migdppcln)` (regression 1.2)

```{r}
#| echo: false

#To generate a regression coefficient it is first necessary to create a new
#variable with 20-year-periods from 1860 to 1879 for both variables.
vdem <- vdem |>
mutate(period = cut(year, breaks = seq(1859, max(year), by = 20), labels = FALSE))

#Once we have the variable, we can run a regression for each of those periods:
reg11 <- vdem |>
group_by(period) |>
summarise(
coefficient = coef(lm(e_migdppcln ~ v2x_polyarchy))[2],
period_start = min(year),
period_end = max(year)
)

reg12 <- vdem |>
group_by(period) |>
summarise(
coefficient = coef(lm(v2x_polyarchy ~ e_migdppcln))[2],
period_start = min(year),
period_end = max(year)
)

print(reg11)
print(reg12)
```

Graphically:

```{r}
#| echo: false
ggplot(data = reg11, aes(x = period_start, y = coefficient)) +
geom_line() +
labs(
x = "Start Year of Period",
y = "Coefficient",
title = "Evolution of Coefficients Over Time (Regression 1.1)",
subtitle = "y = GDPpc (log), x = Polyarchy"
)

ggplot(data = reg12, aes(x = period_start, y = coefficient)) +
geom_line() +
labs(
x = "Start Year of Period",
y = "Coefficient",
title = "Evolution of Coefficients Over Time (Regression 1.2)",
subtitle = "y = Polyarchy, x = GDPpc (log)"
)
```

`lm(e_migdppcln ~ v2x_polyarchy)` (regression 2.1) by region

```{r}
#| echo: false
reg21 <- vdem |>
group_by(e_regionpol_6C) |>
do(model = lm(e_migdppcln ~ v2x_polyarchy, data = .)) |>
summarise(
region = e_regionpol_6C,
coefficient = coef(model)[2],
r_squared = summary(model)\$r.squared
)

print(reg21)
```

Graphically

```{r}
#| echo: false

region_names <- c("E. Eur/C. Asia", "L. America", "M. East", "Sub-Sah. Africa", "Eur/Amer", "Asia & Pacific")

ggplot(reg21, aes(x = factor(region, levels = 1:6, labels = region_names), y = coefficient)) +
geom_bar(stat = "identity") +
labs(x = "Region", y = "Coefficient") +
ggtitle("Corr. Coefficient (reg21) by Region")```