### Master file (executes all code)
# "Satisfaction with Democracy: When Government by the People brings Electoral Losers and Winners Together"
# Code Lucas Leemann and Isabelle Stadelmann-Steffen
# First version: April 2021
# Final version: April 2021


### Call libraries
library(extrafont)  # CRAN v0.17 # CRAN v0.17
library(haven)      # CRAN v2.3.1
library(xtable)     # CRAN v1.8-4
library(foreign)    # CRAN v0.8-72
library(lme4)       # CRAN v1.1-23
library(brms)       # CRAN v2.10.0
library(haven)      # CRAN v2.3.1  
library(readxl)     # CRAN v1.3.1
library(arm)        # CRAN v1.10-1
library(interplot)  # CRAN v0.2.2
library(sjPlot)     # CRAN v2.8.1
library(effects)    # CRAN v4.1-4
library(ordinal)    # CRAN v2019.4-25
library(texreg)     # CRAN v1.36.23
library(plyr)       # CRAN v1.8.6
library(dplyr)      # [github::tidyverse/dplyr] v0.8.99.9003
library(lmtest)     # CRAN v0.9-38
library(stargazer)  # CRAN v5.2.2
library(extrafont)  # CRAN v0.17
library(fontcm)     # CRAN v1.1
library(tidyverse)  # CRAN v1.3.0
library(ggplot2)    # CRAN v3.3.2
library(reshape2)   # CRAN v1.4.4
library(sjlabelled) # CRAN v1.1.6
library(ggpubr)     # CRAN v0.4.0




# if you want to enable CM fonts
font_install('fontcm')


### Generate sub-nation Direct Democracy Index for all four countries
source("Code/1__DD_index_allCountries.R")


### Combine individual level data with context data
source("Code/2__Combine L1 and L2 data.R")


### Run various models and create table and plots
source("Code/3__Empirical Application_6.R")


### Run additional analyses for appendix (validation)
source("Code/4_Validation subnational satisfaction_Fig4.R")


