####################################
# ALL ANALYSES
# 
# Part of replication files for:
# Dill, Janina, Howlett, Marnie, & Müller-Crepon, Carl (2025).
# Do Ukrainians Still Prefer Self-Defense Against Russia At Any Cost? 
# Journal of Peace Research, forthcoming.
#
# run as: nohup Rscript REPLICATE_ALL.R >replicate_all.log>&1 &
####################################

# Clean up before starting
rm(list = ls())

# Libraries
print(paste0(Sys.time(), ": Check and install libraries"))
source("code/libraries.R")

# Globals
print(paste0(Sys.time(), ": Globals"))
source("code/globals.R")

# Load Data
print(paste0(Sys.time(), ": Load data"))
source("code/data_load.R")

# Descriptives
print(paste0(Sys.time(), ": Make maps (Figure A1)"))
source("code/descriptives.R")

print(paste0(Sys.time(), ": Sample Characteristics (Tables A3-A5, Figure A2"))
source("code/sample_characteristics.R")

# Main analysis
print(paste0(Sys.time(), ": Main analysis"))
source("code/analysis_main.R")

# Heterogeneity
print(paste0(Sys.time(), ": Heterogeneity analysis"))
source("code/het_effects.R")

# Robustness checks
print(paste0(Sys.time(), ": Robustness checks"))
source("code/robchecks.R")

# Within Locations
print(paste0(Sys.time(), ": Within Locations"))
source("code/within_location.R")

# Ordering analysis
print(paste0(Sys.time(), ": Ranking analysis"))
source("code/ranking.R")


print(paste0(Sys.time(), ": FINISHED ANALYSIS"))