# load packages
library(tidyverse)
library(cmdstanr)
library(countrycode)
library(tidybayes)
# load events data
counts <- read.csv("output/idea-counts.csv") %>%
arrange(ccode, year) %>%
mutate(observation_index = 1:n()) %>%
glimpse()Rows: 2,775
Columns: 6
$ year <int> 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998…
$ ccode <int> 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 20, 20,…
$ idea_code <chr> "USA", "USA", "USA", "USA", "USA", "USA", "USA", "US…
$ n_dissent_events <int> 118, 109, 124, 138, 127, 117, 123, 130, 147, 121, 14…
$ n_events <int> 135537, 140735, 151180, 177717, 194368, 195981, 2056…
$ observation_index <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1…
# create data set with lengths of time-series for each country
s <- counts %>%
group_by(ccode) %>%
summarize(size = n())
# setup data for stan
N <- nrow(counts)
J <- nrow(s)
s <- s$size
stan_data <- list(N = N,
J = J,
s = s,
n_dissent_events = counts$n_dissent_events,
n_events = counts$n_events)