rm(list=ls())

# Load packages ------------------------------------------------------------
source("02_code/_load_packages.R")

# Load functions to format tables ------------------------------------------
source("02_code/_format_tables_functions.R")

# Load function to generate sample descriptives table ----------------------------------
source("02_code/_generate_sample_desc_table.R")

# Load function to generate balance table ----------------------------------
source("02_code/_generate_balance_table.R")

# Load functions for randomization inference -------------------------------
source("02_code/_RI_functions.R")

# Set to TRUE to build use data from scratch from raw data
build_data <- FALSE

if(build_data){
  # Create data -------------------------------------------------------------
  
  # Read in raw data and code variables for analyses
  source("02_code/00_build_data/01_code_variables.R")
  
  # Generate null distribution matrix for randomization inference
  source("02_code/00_build_data/02_generate_null_distribution.R")
  
} else{
  # Load already built data set with coded variables and null distribution matrix
  load("01_use_data/TASS_data.RData")
  load("01_use_data/00_null_distribution/null_distribution.RData")
}

# Set number of sims for randomization inference ----------------------------

sims <- 10000

# Generate covariate vectors for analyses -----------------------------------
covariates_with <- c("age_centered", 
                     "college_degree_centered", 
                     "married_centered", 
                     "employed_centered", 
                     "household_income_centered", 
                     "south_centered", 
                     "northeast_centered", 
                     "midwest_centered", 
                     "metro_centered",
                     "gender_important_centered",
                     "white_centered", 
                     "black_centered", 
                     "hispanic_centered")

covariates_without_gender <- covariates_with[covariates_with != "gender_important_centered"]
covariates_without_white <- covariates_with[covariates_with != "white_centered"]

# Produce figures main text ------------------------------------------------

# Figure 1
source("02_code/01_analysis/00_main_text/00_figure1.R")

# Figure 2
source("02_code/01_analysis/00_main_text/01_figure2.R")

# Produce figures and tables appendix --------------------------------------

# Table A1
source("02_code/01_analysis/01_appendix/00_tableA1.R")

# Figure A2
source("02_code/01_analysis/01_appendix/01_figureA2.R")

# Table A2
source("02_code/01_analysis/01_appendix/02_tableA2.R")

# Table A3
source("02_code/01_analysis/01_appendix/03_tableA3.R")

# Table A4
source("02_code/01_analysis/01_appendix/04_tableA4.R")

# Table A5
source("02_code/01_analysis/01_appendix/05_tableA5.R")

# Table A6
source("02_code/01_analysis/01_appendix/06_tableA6.R")

# Table A7
source("02_code/01_analysis/01_appendix/07_tableA7.R")
