First, load the empty country-years to fill with the count data.
# load packageslibrary(tidyverse)library(lubridate)# load data set of country-years to fillcountry_year <-read_csv("output/empty-country-years.csv") %>%glimpse()
Second, load the dissent events data and count the events for each country-year.
# load the dissent events and count for each country yeardissent_events <-read_csv("output/idea-dissent-events.csv") %>%mutate(year =year(date)) %>%select(idea_code = where_idea, year) %>%group_by(idea_code, year) %>%summarize(n_dissent_events =n()) %>%glimpse()
Third, load all events and count the events for each country-year.
# load all events and count for each country yearall_events <-read_csv("output/idea-all-events.csv") %>%separate(EVENTDAT, c("date", "time"), sep =" ", fill ="right") %>%mutate(year =year(mdy(date))) %>%select(idea_code = PLACE, year) %>%group_by(idea_code, year) %>%summarize(n_events =n()) %>%glimpse()