Untitled

 avatar
user_1300604
plain_text
a year ago
4.2 kB
5
Indexable
Data and packages

{r}
#| message: false
library(dplyr)
library(ggplot2)
library(readr)
library(tidyverse)

{r}
vdem <-  `V-Dem-CY-Full+Others-v11` <- readRDS("~/Documents/SOCIAL SCIENCES UC3M/States, Regimes and Institutions/ASSIGNMENT 1/Country_Year_V-Dem_Full+others_R_v11/V-Dem-CY-Full+Others-v11.rds")

{r}
exercise1 <- subset(vdem, year >= 1919 & year <= 1939 & e_regiongeo %in% c(1, 2, 3, 4))


exercise1_stableautocracies <- exercise1 %>%
  group_by(country_name) %>%
  filter(all(e_boix_regime == 0))

countriesstableautocracies <- exercise1_stableautocracies %>%
  distinct(country_name)

countries__stableautocracies <- unique(exercise1_stableautocracies$country_name)
print(countries__stableautocracies)

countries__stableautocracies

{r}
exercise1_stabledemocracies <- exercise1 %>%
  group_by(country_name) %>%
  filter(all(e_boix_regime == 1))

countriesstabledemocracies <- exercise1_stabledemocracies %>%
  distinct(country_name)

countries__stabledemocracies <- unique(countriesstabledemocracies$country_name)
print(countries__stabledemocracies)

{r}
demotoautocracy <- exercise1 %>%
  group_by(country_name) %>%
  filter(any(e_boix_regime == 1) & any(e_boix_regime == 0))

countries__demotoautocracy <- unique(demotoautocracy$country_name)

print(countries__demotoautocracy)

{r}
exercise1 <- exercise1 %>%
  mutate(new_variable = ifelse(country_name %in% c("Russia","Albania", "Bulgaria", "Romania", "Hungary"), 0,
                               ifelse(country_name %in% c("Sweden", "Switzerland", "France", "Netherlands", "Iceland", "Finland", "Belgium", "United Kingdom", "Belgium", "Czech Republic", "Luxembourg", "Norway"), 1,
                                      ifelse(country_name %in% c("Lithuania", "Poland", "Serbia", "Latvia", "Ireland", "Germany", "Spain", "Portugal", "Italy", "Estonia", "Austria", "Greece"), 2, NA))))

{r}
exercise1 <- exercise1 %>%
  mutate(new_variable = case_when(
    new_variable == 0 ~ "Stable Autocracy",
    new_variable == 1 ~ "Stable Democracy",
    new_variable == 2 ~ "Transicions",
    TRUE ~ "NA"
  ))

exercise1 <- exercise1 %>%
  mutate(new_variable = case_when(
    new_variable == 0 ~ "Stable",
    new_variable == 1 ~ "Stable Democracy",
    new_variable == 2 ~ "Transiciones",
    TRUE ~ "NA" 
  ))


{r}

groups012 <- exercise1 %>%
  group_by(country_name) %>%
  summarise(
    democracies = ifelse(
      any(e_boix_regime == 0) && any(e_boix_regime == 1), 
      "Democracy that collapsed", 
      ifelse(all(e_boix_regime == 1), "Stable Democracy", "Stable Autocracy"))
  )

table_groups012 <- groups012 %>%
  select(country_name, democracies)

print(table_groups012, n = Inf)

{r}
exercise1_demo <- exercise1 %>%
  group_by(country_name) %>%
  summarise(
    years_democratic = sum(e_boix_regime == 1)
  )


exercise1_demo_table <- exercise1_demo %>%
  select(country_name, years_democratic)


print(exercise1_demo_table)

{r}

yearofbreakdown <- exercise1 %>%
  group_by(country_name) %>%
  summarise(
    yearofbreakdown = ifelse(any(diff(e_boix_regime) == -1), min(year[diff(e_boix_regime) == -1]), NA)
  )
summary(yearofbreakdown)

tableyearofbreakdown <- yearofbreakdown %>%
  filter(!is.na(yearofbreakdown)) %>%
  select(country_name, yearofbreakdown)


print(tableyearofbreakdown, n = Inf)

{r}
exercise1_2 <- subset(vdem, year >= 1860 & year <= 1913 & e_regiongeo %in% c(1, 2, 3, 4))


yearsofdemocracy <- exercise1_2 %>%
  group_by(country_name) %>%
  summarise(
    yearsofdemocracy = sum(!is.na(e_boix_regime) & e_boix_regime == 1)
  )

tables18601913 <- yearsofdemocracy %>%
  select(country_name, yearsofdemocracy)


print(tables18601913, n = Inf)

{r}
poly_1900_1913 <- exercise1_2 %>%
  group_by(country_name) %>%
  summarise(
    mean_poly = mean(v2x_polyarchy)
  )


tablepoly_1900_1913 <- poly_1900_1913 %>%
  select(country_name, mean_poly)


print(tablepoly_1900_1913, n = Inf)

{r}
finaltable <- full_join(
  groups012,
  exercise1_demo_table,
  by = "country_name"
) %>%
  full_join(
    tableyearofbreakdown,
    by = "country_name"
  ) %>%
  full_join(
    tables18601913,
    by = "country_name"
  ) %>%
  full_join(
    tablepoly_1900_1913,
    by = "country_name"
  )

finaltable