This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Libraries | |
# If vdemdata is not installed run below: | |
#install.packages("devtools") | |
#devtools::install_github("vdeminstitute/vdemdata", force = TRUE) | |
library(tidyverse) | |
library(vdemdata) | |
# Overhead | |
set.seed(1904) | |
theme_set(theme_bw()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Title: Straayer Center Democracy Hackathon | |
## Instructor: Prof. Daniel Weitzel | |
## Email: daniel.weitzel@colostate.edu | |
## Date: 2024-01-29 | |
## Hello and welcome to the Straayer Center Democracy Hackathon! | |
## In today's session you'll learn how to use R to generate insights from data | |
## We'll visualize and transform data with a few lines of code! | |
## Notes for people new to R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Purpose: Make the ParlGov data dyadic | |
## Library | |
library("tidyverse") | |
## Download the most recent ParlGov election data from the website | |
df_parlgov <- read_csv("https://www.parlgov.org/data/parlgov-development_csv-utf-8/view_election.csv") |> | |
filter(election_type == "parliament") | |
## Generate a sender data set with country, election and party IDs. Rename the party ID sender_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##Load libraries | |
library("tidyverse") | |
library("lubridate") | |
## Generate fake data set | |
df <- tibble(country = rep(c("A", "B"), each = 3), | |
year_start = c("15jun1816", "04april1918", "01oct2010", "15jun1917", "04april1918", "01oct2010"), | |
year_end = c("31dec1816", "13may1920", "02oct2010", "31dec1921", "13may1920", "02oct2012"), | |
conflict_id = seq(1, 6, by=1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Load the libraries | |
library("tidyverse") # Used for cleaning the data set | |
library("countrycode") # Used for establishing a unique country identifier in both data sets that allows us to merge | |
## Data sets are available here: | |
## https://www.worldvaluessurvey.org/WVSDocumentationWV7.jsp | |
## https://databank.worldbank.org/source/education-statistics-%5e-all-indicators# | |
## Load the data | |
df_gpai <- read_csv("5f29aa54-f976-4948-9e56-85e30763cb54_Data.csv") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Load the library | |
library("tidyverse") | |
## Generate a fake data set with two countries, six years, and a changing indicator | |
df <- tibble(country = rep(c("A", "B"), each = 6), | |
year = rep(seq(1:6), times = 2), | |
ind = c(1,1,2,1,2,1,1,1,1,1,2,1)) | |
## Make a dummy called 'changed' that is TRUE when 'ind' changed in the last three years and FALSE otherwise | |
## Working with rowMeans calculation, assuming that NA indicates NO change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("tidyverse") | |
df_event <- data.frame(country = c("A", "A", "B"), | |
event = c(1,0,1), | |
min_date = c(1990,1994,1993), | |
max_date = c(1996, 1999, 1997)) | |
df <- data.frame(country = c(rep("A", 20), rep("B", 20)), | |
year = c(rep(seq(1989, 2008, by = 1),2))) |