Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.0 kB
3
Indexable
---
title: "Data Assignment 1"
author: "Jesús Martín Godoy"
format: pdf
editor: visual
---

# Activity 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}
library(ggplot2)
library(dplyr)
library(tidyverse)

vdem <- read.csv("~/Downloads/Country_Year_V-Dem_Full+others_CSV_v11.1/V-Dem-CY-Full+Others-v11.1.csv")

# Filtrar y agrupar los datos para contar el número de democracias por año
democracy_counts <- vdem |>
  filter(e_boix_regime == 1) |>
  group_by(year) |>
  summarise(num_democracies = n())

# Crear la gráfica
ggplot(data = democracy_counts, aes(x = year, y = num_democracies)) +
  geom_line() +
  labs(x = "Año", y = "Número de Democracias", title = "Evolución del Número de Democracias en el Mundo")
```

```{r}
library(ggplot2)
library(dplyr)

# Filtrar los datos para el período 1900-1920
democracy_counts_1900_1920 <- vdem |>
  filter(year >= 1900, year <= 1920, e_boix_regime == 1) |>
  group_by(year) |>
  summarise(num_democracies = n())

# Crear la gráfica
ggplot(data = democracy_counts_1900_1920, aes(x = year, y = num_democracies)) +
  geom_line() +
  labs(x = "Año", y = "Número de Democracias", title = "Evolución del Número de Democracias (1900-1920)")
```

```{r}
# Filtrar los datos para el período 1986-1994
democracy_counts_1986_1994 <- vdem |>
  filter(year >= 1986, year <= 1994, e_boix_regime == 1) |>
  group_by(year) |>
  summarise(num_democracies = n())

# Crear la gráfica
ggplot(data = democracy_counts_1986_1994, aes(x = year, y = num_democracies)) +
  geom_line() +
  labs(x = "Año", y = "Número de Democracias", title = "Evolución del Número de Democracias (1986-1994)")
```

# Activity 2

Check the regression coefficient between log of GDPp (e_migdppcln) and V-Dem 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.

```{r}
# Crear grupos de 20 años a partir de 1860-79
vdem <- vdem |>
  mutate(period = cut(year, breaks = seq(1859, max(year), by = 20), labels = FALSE))

# Realizar la regresión lineal para cada período
regression_results <- vdem |>
  group_by(period) |>
  summarise(
    coefficient = coef(lm(e_migdppcln ~ v2x_polyarchy))[2],
    period_start = min(year),
    period_end = max(year)
  )

# Imprimir los resultados
print(regression_results)
```

```{r}
ggplot(data = regression_results, aes(x = period_start, y = coefficient)) +
  geom_line() +
  labs(x = "Año de Inicio del Período", y = "Coeficiente de Correlación") +
  ggtitle("Evolución Temporal del Coeficiente de Correlación entre PIB per cápita y Poliarquía")
```

```{r}
library(dplyr)

# Agrupar por región y realizar regresiones lineales en cada grupo
regression_results_region <- 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
  )

# Imprimir los resultados
print(regression_results_region)

```

```{r}
library(ggplot2)

# Asignar nombres a las regiones
region_names <- c("E. Europe/C. Asia", "Latin America", "Middle East", "Sub-Saharan Africa", "Europe/America", "Asia & Pacific")

# Crear un gráfico de barras del coeficiente por región con nombres personalizados
ggplot(data = regression_results_region, aes(x = factor(region, levels = 1:6, labels = region_names), y = coefficient)) +
  geom_bar(stat = "identity") +
  labs(x = "Región", y = "Coeficiente de Correlación") +
  ggtitle("Coeficiente de Correlación entre PIB per cápita y Poliarquía por Región")


```

# General comments and interpretation