options(warn=-1)
options(scipen=999)

pacman::p_load(estimatr, stats, tidyverse, rmarkdown, stargazer, grDevices,  ggplot2, ggpattern, ggstatsplot, ggside, tictoc, doParallel, mltools, data.table, RItools, stringr, fixest)

Useful Functions

se_cont = function(x, na.rm=FALSE) {
  if (na.rm) x <- na.omit(x)
  sqrt(var(x)/length(x))}

se_binary = function(x, na.rm=FALSE) {
  if (na.rm) x <- na.omit(x)
  sqrt(mean(x)*(1-mean(x))/length(x))}

# Adds the level 'missing' to factor variables #
addmissing = function(x){
  if(is.factor(x)) return(factor(x, levels=c(levels(x), "missing")))
  return(x)}

Load Data

# Load the data #
main_data = readRDS("../intermediate_outcomes/data/df_final.rds")
# Edit types of selected variables #
main_data$user = as.integer(factor(main_data$user))
main_data$order = as.integer(as.character(main_data$order))
main_data$type = recode(main_data$type,"base"="Base posts",
                                            "tactics" = "Reasoning posts",
                                            "emotion" = "Emotions posts",
                                            "combo" = "Combo posts")
main_data$share = as.numeric(main_data$share == "Yes")
main_data$accuracy = recode(main_data$accuracy,"end"="Accuracy After","inter"="Accuracy Inter")
main_data$treatment = recode(main_data$treatment,"reminder"="Facts Baseline",
                                                 "control"="No-course Baseline",
                                                 "tactics" = "Reasoning",
                                                 "emotion" = "Emotions",
                                                 "combo" = "Combo")
main_data$treatment = factor(main_data$treatment, levels = c("No-course Baseline","Facts Baseline","Reasoning","Emotions","Combo"))
main_data$accuracy_score = as.numeric(recode(main_data$perceived_accuracy,"Not at all accurate"="-3",
                                            "Not very accurate" = "-1",
                                            "Somewhat accurate" = "1",
                                            "Very accurate" = "3"))
main_data = main_data[with(main_data, order(user, order)), ]
# Define discernment score variables #
main_data$disc_score = ifelse(main_data$type=="Base posts" & main_data$share==1,1,
                        ifelse(main_data$type!="Base posts" & main_data$share==1,-1,0))
main_data$acc_disc_score = (as.numeric(main_data$type=="Base posts") - as.numeric(main_data$type!="Base posts")) * main_data$accuracy_score  

# Create post-survey and followup indicators #
main_data$post = TRUE
main_data$followup = !is.na(main_data$priming)
# Subset to relevant variables #
main_data_join = subset(main_data,select=c(user,fact,order,type,share,perceived_accuracy,pre_post,yes_first,accuracy,treatment,
                                       att_check_pre,att_check_post,phone_num,delivery,gender,age,education,marital,
                                       employment,location,religion,religiosity,social_media_bin,social_media_hours,social_media_share,
                                       post,followup,att_check_followup))
# Load the pre-survey data #
pre_data = readRDS("../intermediate_outcomes/data/df_pre_only.rds")
# Edit the types of selected variables #
pre_data$user = as.integer(pre_data$user) + max(main_data$user)
pre_data$order = as.integer(as.character(pre_data$order))
pre_data$type = recode(pre_data$type,"base"="Base posts",
                                            "tactics" = "Reasoning posts",
                                            "emotion" = "Emotions posts",
                                            "combo" = "Combo posts")
pre_data$share = as.numeric(pre_data$share == "Yes")
pre_data$accuracy = recode(pre_data$accuracy,"end"="Accuracy After","inter"="Accuracy Inter")
pre_data$treatment = recode(pre_data$treatment,"control_alternative"="Facts Baseline",
                                                 "control_delayed"="No-course Baseline",
                                                 "tactics" = "Reasoning",
                                                 "emotion" = "Emotions",
                                                 "combo" = "Combo")
pre_data$treatment = factor(pre_data$treatment, levels = c("No-course Baseline","Facts Baseline","Reasoning","Emotions","Combo"))
pre_data = pre_data[with(pre_data, order(user, order)), ]
# Create post-survey and followup indicators #
pre_data$post = FALSE
pre_data$followup = FALSE
pre_data$att_check_followup = NA
# Subset to relevant variables #
pre_data_join = subset(pre_data,select=c(user,fact,order,type,share,perceived_accuracy,pre_post,yes_first,accuracy,treatment,
                                       att_check_pre,att_check_post,phone_num,delivery,gender,age,education,marital,
                                       employment,location,religion,religiosity,social_media_bin,social_media_hours,social_media_share,
                                       post,followup,att_check_followup))
full_data = rbind(pre_data_join,main_data_join)

# Complete social media activity variables: questions were not showed if the person selected that they don't use social media #
full_data$social_media_hours = ifelse(is.na(full_data$social_media_hours),"0",full_data$social_media_hours)
full_data$social_media_share = ifelse(is.na(full_data$social_media_share),"0-20%",full_data$social_media_share)

# Create vectors with names of all covariates to use later #
all_covs = c("age","gender","education","marital","employment","location","religion","religiosity","social_media_bin","social_media_hours","social_media_share")
all_covs_with_user <- c("user",all_covs)
categorical_covs = c("gender","education","marital","employment","location","religion","religiosity","social_media_bin","social_media_share")

# Edit types of remaining covariates and subset to a single row per user #
data_covs = data.frame(lapply(full_data[full_data$order==1,all_covs_with_user], as.factor))
data_covs$age = as.numeric(as.character(data_covs$age))
data_covs$social_media_hours = as.numeric(as.character(data_covs$social_media_hours))

# 10/17 EDITS: match by user id
data_covs = merge(data_covs, aggregate(share~user, full_data[full_data$pre_post=="pre",],mean), by="user") %>% rename(share_pre_all = share)
data_covs = merge(data_covs, aggregate(share~user,full_data[full_data$pre_post=="pre" & full_data$type == "Base posts",],mean), by="user") %>% rename(share_pre_base = share)
data_covs = merge(data_covs, aggregate(share~user,full_data[full_data$pre_post=="pre" & full_data$type != "Base posts",],mean), by="user") %>% rename(share_pre_misinfo = share)
data_covs = merge(data_covs, full_data[full_data$order == 1, c("user", "treatment", "post", "followup")], by = "user")

# # Create pre-survey sharing outcomes #
# data_covs$share_pre_all = aggregate(share~user,full_data[full_data$pre_post=="pre",],mean)[,2]
# data_covs$share_pre_base = aggregate(share~user,full_data[full_data$pre_post=="pre" & full_data$type == "Base posts",],mean)[,2]
# data_covs$share_pre_misinfo = aggregate(share~user,full_data[full_data$pre_post=="pre" & full_data$type != "Base posts",],mean)[,2]
# # Add the rest of the variables excluded from the covariates vector # 
# data_covs$treatment = full_data[full_data$order==1,"treatment"]
# data_covs$post = full_data[full_data$order==1,"post"]
# data_covs$followup = full_data[full_data$order==1,"followup"]

# Re-adjust categories of categorical variables #
data_covs$education = ifelse(data_covs$education %in% c("Less than a high school diploma",
                             "High school degree or equivalent"),"High school or less",
                      ifelse(data_covs$education %in% c("Some college, no degree","Associate degree (e.g. AA, AS)"),
                             "Some college",
                      ifelse(data_covs$education %in% c("Master\'s degree (e.g. MA, MS, MEd)",
                                                        "Doctorate or professional degree (e.g. MD, DDS, PhD)"),
                             "Graduate degree","Bachelor\'s degree")))
data_covs$education = factor(data_covs$education,levels=c("High school or less",
                                                          "Some college","Bachelor\'s degree",
                                                          "Graduate degree"))

data_covs$employment = ifelse(data_covs$employment %in% c("Unemployed not currently looking for work",
                             "Unemployed and currently looking for work","Homemaker","Unable to work","Retired"),"Unemployed",
                      ifelse(data_covs$employment %in% c("Employed part time (up to 29 hours per week)",
                            "Employed full time (30 or more hours per week)","Self-employed"),"Employed","Student"))

data_covs$employment = factor(data_covs$employment,levels=c("Employed","Unemployed","Student"))

data_covs$religiosity = ifelse(data_covs$religiosity %in% c("Less than once a month",
                                  "One to three times per month",
                                  "Once a week",
                                  "More than once a week but less than daily",
                                  "Daily"),"Attends","Does not attend")

data_covs$religiosity = factor(data_covs$religiosity,levels=c("Attends","Does not attend"))

# Add new variables to names vector and create vector with display names #
all_covs = c(all_covs,"share_pre_all","share_pre_base","share_pre_misinfo")
all_covs_fancy = c(""," ","Educational Attainment","  ","Employment Status","Location","   ",
                  "    ","     ","      ","Prop. of content shared", "Pre-survey Sharing",
                   "Pre-survey Sharing","Pre-survey Sharing")

# Create vectors with names and display names of covariates by type to use later #
covariates_continuous = c("age","social_media_hours","share_pre_all","share_pre_base","share_pre_misinfo")
                          
covariates_continuous_fancy = c("Age","Hrs/day on social media",
                                "All posts",
                                "Non-misinformation posts",
                                "Misinformation posts")

covariates_binary = c("gender_Man",
                    paste("education",c("High school or less","Some college","Bachelor\'s degree","Graduate degree"),sep="_"),
                    "marital_Married, or in a domestic partnership",
                    paste("employment",c("Unemployed","Employed","Student"),sep="_"),
                    paste("location",c("Mostly urban","Suburban","Mostly rural"),sep="_"),
                    "religion_Christian",
                    "religiosity_Attends",
                    "social_media_bin_Yes",
                    paste("social_media_share",c("0-20%","20-40%","40-60%","60-80%","80-100%"),sep="_"))


covariates_binary_fancy = c("Man",
                            "High school or less",
                            "Some college",
                            "Bachelor\'s degree",
                            "Graduate degree",
                            "Married",
                            "Unemployed",
                            "Employed",
                            "Student",
                            "Mostly urban","Suburban","Mostly rural",
                            "Christian",
                            "Attends religious services",
                            "Uses social media",
                            "0-20%","20-40%","40-60%","60-80%","80-100%")

covariates_all = c("age",covariates_binary[!startsWith(covariates_binary,"social_media_share")],"social_media_hours",
                   covariates_binary[startsWith(covariates_binary,"social_media_share")],
                   covariates_continuous[3:length(covariates_continuous)])
covariates_all_fancy = c("Age",covariates_binary_fancy[!endsWith(covariates_binary_fancy,"%")],"Hrs/day on social media",
                         covariates_binary_fancy[endsWith(covariates_binary_fancy,"%")],
                         covariates_continuous_fancy[3:length(covariates_continuous_fancy)])

# Add missing category to factors #
data_covs = as.data.frame(lapply(data_covs, addmissing))
data_covs = data_covs %>%
mutate_if(is.factor, ~replace_na(., "missing"))
data_covs = droplevels(data_covs)

# One-hot encoding the factor covariates #
setDT(data_covs)
data_covs = one_hot(data_covs, cols = c(categorical_covs))
setDF(data_covs)
data_covs = subset(data_covs, select=c(covariates_binary,covariates_continuous,
                                       "treatment","post","followup"))

# Create vector with number of covariates per group and group names for display purposes #
cov_groups_num = c()
for (cov in all_covs){
    cov_groups_num = c(cov_groups_num,sum(startsWith(colnames(data_covs),cov)))}
cov_groups = rep(all_covs_fancy,cov_groups_num)
# Adjust column and covariate names as required by the functions we use #
colnames(data_covs) = str_replace_all(colnames(data_covs)," ","_")
colnames(data_covs) = str_replace_all(colnames(data_covs),"-","_")
colnames(data_covs) = str_replace_all(colnames(data_covs),",","")
colnames(data_covs) = str_replace_all(colnames(data_covs),"\\.","")
colnames(data_covs) = str_replace_all(colnames(data_covs),"\\(","")
colnames(data_covs) = str_replace_all(colnames(data_covs),"\\)","")
colnames(data_covs) = str_replace_all(colnames(data_covs),"'s","")
colnames(data_covs) = str_replace_all(colnames(data_covs),"%","")

cov_form = str_replace_all(covariates_all," ","_")
cov_form = str_replace_all(cov_form,"-","_")
cov_form = str_replace_all(cov_form,",","")
cov_form = str_replace_all(cov_form,"\\.","")
cov_form = str_replace_all(cov_form,"\\(","")
cov_form = str_replace_all(cov_form,"\\)","")
cov_form = str_replace_all(cov_form,"'s","")
cov_form = str_replace_all(cov_form,"%","")

covariates_binary = str_replace_all(covariates_binary," ","_")
covariates_binary = str_replace_all(covariates_binary,"-","_")
covariates_binary = str_replace_all(covariates_binary,",","")
covariates_binary = str_replace_all(covariates_binary,"\\.","")
covariates_binary = str_replace_all(covariates_binary,"\\(","")
covariates_binary = str_replace_all(covariates_binary,"\\)","")
covariates_binary = str_replace_all(covariates_binary,"'s","")
covariates_binary = str_replace_all(covariates_binary,"%","")
generate_variable_mapping_followup <- function(treatments, post_domains, tactics, covariates) {
  mapping <- list()

  # Basic variables
  basic_vars <- c("post_is_misinfo" = "1[Misinfo]",
                  "post" = "1[Followup-treatment]",
                  "post:post_is_misinfo" = "1[Followup-treatment] x 1[Misinfo]",
                  "(Intercept)" = "Facts Baseline") # intercept only used as Facts Baseline
  
  # Covariates
  cov_vars <- c("age" = "Age", 
    "gender_Man" = "Man",
    "education_High_school_or_less" = "High school or less",
    "education_Some_college" = "Some college",
    "education_Bachelor_degree" = "Bachelor\'s degree",
    "education_Graduate_degree" = "Graduate degree",
    "marital_Married_or_in_a_domestic_partnership" = "Married",
    "employment_Unemployed" = "Unemployed",
    "employment_Employed" = "Employed",
    "employment_Student" = "Student",
    "location_Mostly_urban" = "Mostly urban",
    "location_Suburban" = "Suburban",
    "location_Mostly_rural" = "Mostly rural",
    "religion_Christian" = "Christian",
    "religiosity_Attends" = "Attends religious services",
    "social_media_bin_Yes" = "Uses social media",
    "social_media_share_0_20" = "Social Media Share: 0-20%",
    "social_media_share_20_40" = "Social Media Share: 20-40%",
    "social_media_share_40_60" = "Social Media Share: 40-60%",
    "social_media_share_60_80" = "Social Media Share: 60-80%",
    "social_media_share_80_100" = "Social Media Share: 80-100%",
    "social_media_hours" = "Hours spent on Social Media",
    "misinfo_pre_cov" = "Avg. Sharing of Misinfo posts at pre-treatment", 
    "base_rate_pre_cov" = "Avg. Sharing of Non-misinfo posts at pre-treatment",
    "att_check_pre" = "Passed attention check at pre-treatment",
    "emotions_pre" = "Emotions posts",
    "reasoning_pre" = "Reasoning posts",
    "combo_pre" = "Combo posts",
    
    "age_cov" = "Age",
    "gender_Man_cov" = "Man",
    "education_High_school_or_less_cov" = "High school or less",
    "education_Some_college_cov" = "Some college",
    "education_Bachelor_degree_cov" = "Bachelor\'s degree",
    "education_Graduate_degree_cov" = "Graduate degree",
    "marital_Married_or_in_a_domestic_partnership_cov" = "Married",
    "employment_Unemployed_cov" = "Unemployed",
    "employment_Employed_cov" = "Employed",
    "employment_Student_cov" = "Student",
    "location_Mostly_urban_cov" = "Mostly urban",
    "location_Suburban_cov" = "Suburban",
    "location_Mostly_rural_cov" = "Mostly rural",
    "religion_Christian_cov" = "Christian",
    "religiosity_Attends_cov" = "Attends religious services",
    "social_media_bin_Yes_cov" = "Uses social media",
    "social_media_share_0_20_cov" = "Social Media Share: 0-20%",
    "social_media_share_20_40_cov" = "Social Media Share: 20-40%",
    "social_media_share_40_60_cov" = "Social Media Share: 40-60%",
    "social_media_share_60_80_cov" = "Social Media Share: 60-80%",
    "social_media_share_80_100_cov" = "Social Media Share: 80-100%",
    "social_media_hours_cov" = "Hours spent on Social Media",
    "misinfo_pre_cov" = "Avg. Sharing of Misinfo posts at pre-treatment",
    "base_rate_pre_cov" = "Avg. Sharing of Non-misinfo posts at pre-treatment",
    "att_check_pre_cov" = "Passed attention check at pre-treatment",
    "emotions_pre_cov" = "Emotions posts",
    "reasoning_pre_cov" = "Reasoning posts",
    "combo_pre_cov" = "Combo posts")
  
  # post characteristics
  posts_vars <- c(
    "picture" = "1[Post has a picture]",
    "exclamation" = "1[Post includes exclamation(s) mark]",
    "hashtag" = "1[Post includes hashtag(s)]",
    "url" = "1[Post includes url(s)]",
    "tags" = "1[Post includes tag(s)]",
    "caps" = "1[Post includes word(s) in capital letters]",
    "emojis" = "1[Post includes emoji(s)]",
    "oneself" = "1[Post is written in first person]",
    "insult" = "1[Post includes an insult]",
    "references" = "1[Post makes a reference to an external source/data]",
    "statistic" = "1[Post references a statistic]",
    "gender_man" = "1[Post author is a man]",
    "avatar_human" = "1[Post author's avatar is a human]",
    "num_exclamation" = "Number of exclamation marks",
    "num_hashtag" = "Number of hashtags",
    "num_emojis" = "Number of emojis",
    "length_words" = "Number of words in post",
    "length_characters" = "Number of characters in post"
  )
  
  # Manipulation tactics:
  manipulation_vars = c("factor(type)Combo posts" = "1[Combo manipulation tactic]",
                        "factor(type)Emotions posts" = "1[Emotions manipulation tactic]",
                        "factor(type)Reasoning posts" = "1[Reasoning manipulation tactic]",
                        "factor(type)Base posts" = "1[Non-misinfo tactic]")

  # Treatment variables
  for (treatment in treatments) {
    mapping[paste0("treatment", treatment)] <- treatment
    mapping[paste0("factor(treatment)", treatment)] <- treatment
    
    mapping[paste0("treatment", treatment, ":post")] <- paste(treatment, "x 1[Followup-treatment]")
    mapping[paste0("factor(treatment)", treatment, ":post")] <- paste(treatment, "x 1[Followup-treatment]")
    
    mapping[paste0("treatment", treatment,":post_is_misinfo")] <- paste(treatment, "x 1[Misinfo]")
    mapping[paste0("post_is_misinfo:treatment", treatment)] <- paste(treatment, "x 1[Misinfo]")
    
    mapping[paste0("post_is_misinfo:treatment", treatment, ":post")] <- paste(treatment, "x 1[Misinfo] x 1[Followup-treatment]")
    
    mapping[paste0("treatment", treatment, ":post:post_is_misinfo")] <- paste(treatment, "x 1[Followup-treatment] x 1[Misinfo]")
  }

  # Post domain variables
  for (i in 1:length(post_domains)) {
    domain <- post_domains[i]
    mapping[paste0("factor(fact)", i)] <- paste("Post domain", i)
    
    mapping[paste0("factor(fact)", i, ":post")] <- paste("Post domain", i, "x 1[Followup-treatment]")
    mapping[paste0("post:factor(fact)", i)] <- paste("Post domain", i, "x 1[Followup-treatment]")
    
    mapping[paste0("post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x 1[Misinfo]")
    
    mapping[paste0("factor(fact)", i, ":factor(post)1")] <- paste("Post domain", i, "x 1[Followup-treatment]")

    mapping[paste0("post:post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x 1[Followup-treatment] x 1[Misinfo]")
    
    
    # Interaction with treatments
    for (treatment in treatments) {
      mapping[paste0("factor(fact)", i, ":treatment", treatment)] <- paste("Post domain", i, "x", treatment)
      mapping[paste0("treatment", treatment, ":factor(fact)", i)] <- paste("Post domain", i, "x", treatment)
      mapping[paste0("factor(fact)", i, ":factor(treatment)", treatment)] <- paste("Post domain", i, "x", treatment)
      
      mapping[paste0("factor(fact)", i, ":treatment", treatment, ":post")] <- paste("Post domain", i, "x", treatment, "x 1[Followup-treatment]")
      mapping[paste0("factor(fact)", i, ":factor(treatment)", treatment, ":factor(post)1")] <- paste("Post domain", i, "x", treatment, "x 1[Followup-treatment]")
      mapping[paste0("treatment", treatment, ":post:factor(fact)", i)] <- paste("Post domain", i, "x", treatment, "x 1[Followup-treatment]")
      
      mapping[paste0("treatment", treatment, ":post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x", treatment, "x 1[Misinfo]")
      
      mapping[paste0("treatment", treatment, ":post:post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x", treatment, "x 1[Followup-treatment] x 1[Misinfo]")
    }
  
    
    for (tactic in tactics) {
      
      mapping[paste0("factor(fact)", i, ":factor(type)", tactic)] <- paste("Post domain", i, "x", manipulation_vars[tactic])
      mapping[paste0("factor(fact)", i, ":factor(type)", tactic)] <- paste("Post domain", i, "x", manipulation_vars[paste0("factor(type)",tactic)])
    }
    
  }
  
  
  # Post ID
  for (i in 1:length(post_ids)) {
    mapping[paste0("factor\\\\(post\\\\_id\\\\)", i)] <- paste("Post", i,"indicator") # not working
  }
  post_id_vars <- c(
    "factor(post_id)1" = "Post 1 indicator",
    "factor(post_id)2" = "Post 2 indicator",
    "factor(post_id)3" = "Post 3 indicator",
    "factor(post_id)4" = "Post 4 indicator",
    "factor(post_id)5" = "Post 5 indicator",
    "factor(post_id)6" = "Post 6 indicator",
    "factor(post_id)7" = "Post 7 indicator",
    "factor(post_id)8" = "Post 8 indicator",
    "factor(post_id)9" = "Post 9 indicator",
    "factor(post_id)10" = "Post 10 indicator",

    "factor(post_id)11" = "Post 11 indicator",
    "factor(post_id)12" = "Post 12 indicator",
    "factor(post_id)13" = "Post 13 indicator",
    "factor(post_id)14" = "Post 14 indicator",
    "factor(post_id)15" = "Post 15 indicator",
    "factor(post_id)16" = "Post 16 indicator",
    "factor(post_id)17" = "Post 17 indicator",
    "factor(post_id)18" = "Post 18 indicator",
    "factor(post_id)19" = "Post 19 indicator",
    "factor(post_id)20" = "Post 20 indicator",

    "factor(post_id)21" = "Post 21 indicator",
    "factor(post_id)22" = "Post 22 indicator",
    "factor(post_id)23" = "Post 23 indicator",
    "factor(post_id)24" = "Post 24 indicator",
    "factor(post_id)25" = "Post 25 indicator",
    "factor(post_id)26" = "Post 26 indicator",
    "factor(post_id)27" = "Post 27 indicator",
    "factor(post_id)28" = "Post 28 indicator",
    "factor(post_id)29" = "Post 29 indicator",
    "factor(post_id)30" = "Post 30 indicator",

    "factor(post_id)31" = "Post 31 indicator",
    "factor(post_id)32" = "Post 32 indicator",
    "factor(post_id)33" = "Post 33 indicator",
    "factor(post_id)34" = "Post 34 indicator",
    "factor(post_id)35" = "Post 35 indicator",
    "factor(post_id)36" = "Post 36 indicator",
    "factor(post_id)37" = "Post 37 indicator",
    "factor(post_id)38" = "Post 38 indicator",
    "factor(post_id)39" = "Post 39 indicator",
    "factor(post_id)40" = "Post 40 indicator",

    "factor(post_id)41" = "Post 41 indicator",
    "factor(post_id)42" = "Post 42 indicator",
    "factor(post_id)43" = "Post 43 indicator",
    "factor(post_id)44" = "Post 44 indicator",
    "factor(post_id)45" = "Post 45 indicator",
    "factor(post_id)46" = "Post 46 indicator",
    "factor(post_id)47" = "Post 47 indicator",
    "factor(post_id)48" = "Post 48 indicator",
    "factor(post_id)49" = "Post 49 indicator",
    "factor(post_id)50" = "Post 50 indicator",

    "factor(post_id)51" = "Post 51 indicator",
    "factor(post_id)52" = "Post 52 indicator",
    "factor(post_id)53" = "Post 53 indicator",
    "factor(post_id)54" = "Post 54 indicator",
    "factor(post_id)55" = "Post 55 indicator",
    "factor(post_id)56" = "Post 56 indicator",
    "factor(post_id)57" = "Post 57 indicator",
    "factor(post_id)58" = "Post 58 indicator",
    "factor(post_id)59" = "Post 59 indicator",
    "factor(post_id)60" = "Post 60 indicator"
  )
  
  # Covariate variables
  for (covariate in covariates) {
    mapping[paste0("post:", covariate)] <- paste("Followup-treatment x", cov_vars[covariate])
    mapping[paste0("post_is_misinfo:", covariate)] <- paste("1[Misinfo] x", cov_vars[covariate])
    mapping[paste0("post:post_is_misinfo:", covariate)] <- paste("Followup-treatment x 1[Misinfo] x", cov_vars[covariate])
    
    # Interaction with treatments
    for (treatment in treatments) {
      mapping[paste0("treatment", treatment, ":", covariate)] <- paste(treatment, "x", cov_vars[covariate])
      mapping[paste0("factor(treatment)", treatment, ":", covariate)] <- paste(treatment, "x", cov_vars[covariate])
      mapping[paste0("treatment", treatment, ":post:", covariate)] <- paste(treatment, "x 1[Post] x", cov_vars[covariate])
      mapping[paste0("treatment", treatment, ":post_is_misinfo:", covariate)] <- paste(treatment, "x 1[Misinfo] x", cov_vars[covariate])
      mapping[paste0("treatment", treatment, ":post:post_is_misinfo:", covariate)] <- paste(treatment, "x 1[Post] x 1[Misinfo] x", cov_vars[covariate])
    }
    
    # Interaction with domains
    for (i in 1:length(post_domains)) {
    mapping[paste0("factor(fact)",i,":",covariate)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    mapping[paste0(covariate,":factor(fact)",i)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    }
    
    # Interaction with post
    for (i in 1:length(post_domains)) {
    mapping[paste0("factor(fact)",i,":",covariate)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    mapping[paste0(covariate,":factor(fact)",i)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    }
    
    # Interaction with misinfo
  
  }
  
  # Post attributes
  for (attribute in posts_vars) {
    
    
    
    # Interaction with treatments
    for (treatment in treatments) {
      mapping[paste0("treatment", treatment, ":", attribute)] <- paste(treatment, "x", posts_vars[attribute])
      mapping[paste0("treatment", treatment, ":post:", attribute)] <- paste(treatment, "x 1[Followup-treatment] x ", posts_vars[attribute])
      mapping[paste0("treatment", treatment, ":post_is_misinfo:", attribute)] <- paste(treatment, "x 1[Misinfo] x ", posts_vars[attribute])
      mapping[paste0("treatment", treatment, ":post:post_is_misinfo:", attribute)] <- paste(treatment, "x 1[Followup-treatment] x 1[Misinfo] x ", posts_vars[attribute])
    }
    
    
    for (i in 1:length(post_domains)) {
      mapping[paste0(attribute,":factor(fact)", i)] <- paste("Post domain", i,posts_vars[attribute])
      mapping[paste0("factor(fact)", i,attribute)] <- paste("Post domain", i,posts_vars[attribute])
      
      mapping[paste0("post:",attribute,":","factor(fact)", i)] <- paste("Post domain", i,"x 1[Followup-treatment] x",posts_vars[attribute])
      mapping[paste0("post:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x 1[Followup-treatment] x",posts_vars[attribute])
      
      mapping[paste0("post_is_misinfo:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x 1[Misinfo] x",posts_vars[attribute])
      
      
      for (treatment in treatments) {
        mapping[paste0("treatment", treatment, ":", attribute,":factor(fact)",i)] <- paste("Post domain", i,"x",treatment,"x",posts_vars[attribute])
        mapping[paste0("treatment", treatment, ":factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x",treatment,"x",posts_vars[attribute])
        
        mapping[paste0("treatment", treatment, ":post:",attribute,":factor(fact)",i)] <- paste("Post domain", i,"x",treatment,"x 1[Followup-treatment]",posts_vars[attribute])
        
        mapping[paste0("treatment", treatment, ":post:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x",treatment,"x 1[Followup-treatment]",posts_vars[attribute])
        
        mapping[paste0("treatment", treatment, ":post_is_misinfo:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x",treatment,"x 1[Misinfo]",posts_vars[attribute])
      }
    }
    
    mapping[paste0("post:", attribute)] <- paste("Followup-treatment x", posts_vars[attribute])
    mapping[paste0("post_is_misinfo:", attribute)] <- paste("1[Misinfo] x", posts_vars[attribute])
  }
  
    # random cases not working
    rndm_vars <- c(
      "religiosity_Attends:factor(fact)3" = "Post domain 3 x Religiosity: Attends",
      "religiosity_Attends:factor(fact)4" = "Post domain 4 x Religiosity: Attends",
      "religiosity_Attends:factor(fact)5" = "Post domain 5 x Religiosity: Attends",
      "religiosity_Attends:factor(fact)6" = "Post domain 6 x Religiosity: Attends",
      
      "social_media_share_40_60:factor(fact)10" = "Post domain 10 x Social Media Share: 40-60%",
      "social_media_share_40_60:factor(fact)11" = "Post domain 11 x Social Media Share: 40-60%",
      "social_media_share_40_60:factor(fact)12" = "Post domain 12 x Social Media Share: 40-60%",
      "social_media_share_40_60:factor(fact)13" = "Post domain 13 x Social Media Share: 40-60%",
      
      "factor(post_id)19" = "Post 19 indicator",
      "factor(post_id)20" = "Post 20 indicator",
      "factor(post_id)21" = "Post 21 indicator"
    )

  return(c(mapping,basic_vars,cov_vars,manipulation_vars,post_id_vars,rndm_vars,posts_vars))
}
generate_variable_mapping <- function(treatments, post_domains, tactics, covariates) {
  mapping <- list()

  # Basic variables
  basic_vars <- c("post_is_misinfo" = "1[Misinfo]",
                  "post" = "1[Post-treatment]",
                  "post:post_is_misinfo" = "1[Post-treatment] x 1[Misinfo]",
                  "(Intercept)" = "Facts Baseline") # intercept only used as Facts Baseline
  
  # Covariates
  cov_vars <- c("age" = "Age", 
    "gender_Man" = "Man",
    "education_High_school_or_less" = "High school or less",
    "education_Some_college" = "Some college",
    "education_Bachelor_degree" = "Bachelor\'s degree",
    "education_Graduate_degree" = "Graduate degree",
    "marital_Married_or_in_a_domestic_partnership" = "Married",
    "employment_Unemployed" = "Unemployed",
    "employment_Employed" = "Employed",
    "employment_Student" = "Student",
    "location_Mostly_urban" = "Mostly urban",
    "location_Suburban" = "Suburban",
    "location_Mostly_rural" = "Mostly rural",
    "religion_Christian" = "Christian",
    "religiosity_Attends" = "Attends religious services",
    "social_media_bin_Yes" = "Uses social media",
    "social_media_share_0_20" = "Social Media Share: 0-20%",
    "social_media_share_20_40" = "Social Media Share: 20-40%",
    "social_media_share_40_60" = "Social Media Share: 40-60%",
    "social_media_share_60_80" = "Social Media Share: 60-80%",
    "social_media_share_80_100" = "Social Media Share: 80-100%",
    "social_media_hours" = "Hours spent on Social Media",
    "misinfo_pre_cov" = "Avg. Sharing of Misinfo posts at pre-treatment", 
    "base_rate_pre_cov" = "Avg. Sharing of Non-misinfo posts at pre-treatment",
    "att_check_pre" = "Passed attention check at pre-treatment",
    "emotions_pre" = "Emotions posts",
    "reasoning_pre" = "Reasoning posts",
    "combo_pre" = "Combo posts",
    
    "age_cov" = "Age",
    "gender_Man_cov" = "Man",
    "education_High_school_or_less_cov" = "High school or less",
    "education_Some_college_cov" = "Some college",
    "education_Bachelor_degree_cov" = "Bachelor\'s degree",
    "education_Graduate_degree_cov" = "Graduate degree",
    "marital_Married_or_in_a_domestic_partnership_cov" = "Married",
    "employment_Unemployed_cov" = "Unemployed",
    "employment_Employed_cov" = "Employed",
    "employment_Student_cov" = "Student",
    "location_Mostly_urban_cov" = "Mostly urban",
    "location_Suburban_cov" = "Suburban",
    "location_Mostly_rural_cov" = "Mostly rural",
    "religion_Christian_cov" = "Christian",
    "religiosity_Attends_cov" = "Attends religious services",
    "social_media_bin_Yes_cov" = "Uses social media",
    "social_media_share_0_20_cov" = "Social Media Share: 0-20%",
    "social_media_share_20_40_cov" = "Social Media Share: 20-40%",
    "social_media_share_40_60_cov" = "Social Media Share: 40-60%",
    "social_media_share_60_80_cov" = "Social Media Share: 60-80%",
    "social_media_share_80_100_cov" = "Social Media Share: 80-100%",
    "social_media_hours_cov" = "Hours spent on Social Media",
    "misinfo_pre_cov" = "Avg. Sharing of Misinfo posts at pre-treatment",
    "base_rate_pre_cov" = "Avg. Sharing of Non-misinfo posts at pre-treatment",
    "att_check_pre_cov" = "Passed attention check at pre-treatment",
    "emotions_pre_cov" = "Emotions posts",
    "reasoning_pre_cov" = "Reasoning posts",
    "combo_pre_cov" = "Combo posts")
  
  # post characteristics
  posts_vars <- c(
    "picture" = "1[Post has a picture]",
    "exclamation" = "1[Post includes exclamation(s) mark]",
    "hashtag" = "1[Post includes hashtag(s)]",
    "url" = "1[Post includes url(s)]",
    "tags" = "1[Post includes tag(s)]",
    "caps" = "1[Post includes word(s) in capital letters]",
    "emojis" = "1[Post includes emoji(s)]",
    "oneself" = "1[Post is written in first person]",
    "insult" = "1[Post includes an insult]",
    "references" = "1[Post makes a reference to an external source/data]",
    "statistic" = "1[Post references a statistic]",
    "gender_man" = "1[Post author is a man]",
    "avatar_human" = "1[Post author's avatar is a human]",
    "num_exclamation" = "Number of exclamation marks",
    "num_hashtag" = "Number of hashtags",
    "num_emojis" = "Number of emojis",
    "length_words" = "Number of words in post",
    "length_characters" = "Number of characters in post"
  )
  
  # Manipulation tactics:
  manipulation_vars = c("factor(type)Combo posts" = "1[Combo manipulation tactic]",
                        "factor(type)Emotions posts" = "1[Emotions manipulation tactic]",
                        "factor(type)Reasoning posts" = "1[Reasoning manipulation tactic]",
                        "factor(type)Base posts" = "1[Non-misinfo tactic]")

  # Treatment variables
  for (treatment in treatments) {
    mapping[paste0("treatment", treatment)] <- treatment
    mapping[paste0("factor(treatment)", treatment)] <- treatment
    
    mapping[paste0("treatment", treatment, ":post")] <- paste(treatment, "x 1[Post-treatment]")
    mapping[paste0("factor(treatment)", treatment, ":post")] <- paste(treatment, "x 1[Post-treatment]")
    
    mapping[paste0("treatment", treatment,":post_is_misinfo")] <- paste(treatment, "x 1[Misinfo]")
    mapping[paste0("post_is_misinfo:treatment", treatment)] <- paste(treatment, "x 1[Misinfo]")
    
    mapping[paste0("post_is_misinfo:treatment", treatment, ":post")] <- paste(treatment, "x 1[Misinfo] x 1[Post-treatment]")
    
    mapping[paste0("treatment", treatment, ":post:post_is_misinfo")] <- paste(treatment, "x 1[Post-treatment] x 1[Misinfo]")
  }

  # Post domain variables
  for (i in 1:length(post_domains)) {
    domain <- post_domains[i]
    mapping[paste0("factor(fact)", i)] <- paste("Post domain", i)
    
    mapping[paste0("factor(fact)", i, ":post")] <- paste("Post domain", i, "x 1[Post-treatment]")
    mapping[paste0("post:factor(fact)", i)] <- paste("Post domain", i, "x 1[Post-treatment]")
    
    mapping[paste0("post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x 1[Misinfo]")
    
    mapping[paste0("factor(fact)", i, ":factor(post)1")] <- paste("Post domain", i, "x 1[Post-treatment]")

    mapping[paste0("post:post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x 1[Post-treatment] x 1[Misinfo]")
    
    
    # Interaction with treatments
    for (treatment in treatments) {
      mapping[paste0("factor(fact)", i, ":treatment", treatment)] <- paste("Post domain", i, "x", treatment)
      mapping[paste0("treatment", treatment, ":factor(fact)", i)] <- paste("Post domain", i, "x", treatment)
      mapping[paste0("factor(fact)", i, ":factor(treatment)", treatment)] <- paste("Post domain", i, "x", treatment)
      
      mapping[paste0("factor(fact)", i, ":treatment", treatment, ":post")] <- paste("Post domain", i, "x", treatment, "x 1[Post-treatment]")
      mapping[paste0("factor(fact)", i, ":factor(treatment)", treatment, ":factor(post)1")] <- paste("Post domain", i, "x", treatment, "x 1[Post-treatment]")
      mapping[paste0("treatment", treatment, ":post:factor(fact)", i)] <- paste("Post domain", i, "x", treatment, "x 1[Post-treatment]")
      
      mapping[paste0("treatment", treatment, ":post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x", treatment, "x 1[Misinfo]")
      
      mapping[paste0("treatment", treatment, ":post:post_is_misinfo:factor(fact)", i)] <- paste("Post domain", i, "x", treatment, "x 1[Post-treatment] x 1[Misinfo]")
    }
  
    
    for (tactic in tactics) {
      
      mapping[paste0("factor(fact)", i, ":factor(type)", tactic)] <- paste("Post domain", i, "x", manipulation_vars[tactic])
      mapping[paste0("factor(fact)", i, ":factor(type)", tactic)] <- paste("Post domain", i, "x", manipulation_vars[paste0("factor(type)",tactic)])
    }
    
  }
  
  
  # Post ID
  for (i in 1:length(post_ids)) {
    mapping[paste0("factor\\\\(post\\\\_id\\\\)", i)] <- paste("Post", i,"indicator") # not working
  }
  post_id_vars <- c(
    "factor(post_id)1" = "Post 1 indicator",
    "factor(post_id)2" = "Post 2 indicator",
    "factor(post_id)3" = "Post 3 indicator",
    "factor(post_id)4" = "Post 4 indicator",
    "factor(post_id)5" = "Post 5 indicator",
    "factor(post_id)6" = "Post 6 indicator",
    "factor(post_id)7" = "Post 7 indicator",
    "factor(post_id)8" = "Post 8 indicator",
    "factor(post_id)9" = "Post 9 indicator",
    "factor(post_id)10" = "Post 10 indicator",

    "factor(post_id)11" = "Post 11 indicator",
    "factor(post_id)12" = "Post 12 indicator",
    "factor(post_id)13" = "Post 13 indicator",
    "factor(post_id)14" = "Post 14 indicator",
    "factor(post_id)15" = "Post 15 indicator",
    "factor(post_id)16" = "Post 16 indicator",
    "factor(post_id)17" = "Post 17 indicator",
    "factor(post_id)18" = "Post 18 indicator",
    "factor(post_id)19" = "Post 19 indicator",
    "factor(post_id)20" = "Post 20 indicator",

    "factor(post_id)21" = "Post 21 indicator",
    "factor(post_id)22" = "Post 22 indicator",
    "factor(post_id)23" = "Post 23 indicator",
    "factor(post_id)24" = "Post 24 indicator",
    "factor(post_id)25" = "Post 25 indicator",
    "factor(post_id)26" = "Post 26 indicator",
    "factor(post_id)27" = "Post 27 indicator",
    "factor(post_id)28" = "Post 28 indicator",
    "factor(post_id)29" = "Post 29 indicator",
    "factor(post_id)30" = "Post 30 indicator",

    "factor(post_id)31" = "Post 31 indicator",
    "factor(post_id)32" = "Post 32 indicator",
    "factor(post_id)33" = "Post 33 indicator",
    "factor(post_id)34" = "Post 34 indicator",
    "factor(post_id)35" = "Post 35 indicator",
    "factor(post_id)36" = "Post 36 indicator",
    "factor(post_id)37" = "Post 37 indicator",
    "factor(post_id)38" = "Post 38 indicator",
    "factor(post_id)39" = "Post 39 indicator",
    "factor(post_id)40" = "Post 40 indicator",

    "factor(post_id)41" = "Post 41 indicator",
    "factor(post_id)42" = "Post 42 indicator",
    "factor(post_id)43" = "Post 43 indicator",
    "factor(post_id)44" = "Post 44 indicator",
    "factor(post_id)45" = "Post 45 indicator",
    "factor(post_id)46" = "Post 46 indicator",
    "factor(post_id)47" = "Post 47 indicator",
    "factor(post_id)48" = "Post 48 indicator",
    "factor(post_id)49" = "Post 49 indicator",
    "factor(post_id)50" = "Post 50 indicator",

    "factor(post_id)51" = "Post 51 indicator",
    "factor(post_id)52" = "Post 52 indicator",
    "factor(post_id)53" = "Post 53 indicator",
    "factor(post_id)54" = "Post 54 indicator",
    "factor(post_id)55" = "Post 55 indicator",
    "factor(post_id)56" = "Post 56 indicator",
    "factor(post_id)57" = "Post 57 indicator",
    "factor(post_id)58" = "Post 58 indicator",
    "factor(post_id)59" = "Post 59 indicator",
    "factor(post_id)60" = "Post 60 indicator"
  )
  
  # Covariate variables
  for (covariate in covariates) {
    mapping[paste0("post:", covariate)] <- paste("Post-treatment x", cov_vars[covariate])
    mapping[paste0("post_is_misinfo:", covariate)] <- paste("1[Misinfo] x", cov_vars[covariate])
    mapping[paste0("post:post_is_misinfo:", covariate)] <- paste("Post-treatment x 1[Misinfo] x", cov_vars[covariate])
    
    # Interaction with treatments
    for (treatment in treatments) {
      mapping[paste0("treatment", treatment, ":", covariate)] <- paste(treatment, "x", cov_vars[covariate])
      mapping[paste0("factor(treatment)", treatment, ":", covariate)] <- paste(treatment, "x", cov_vars[covariate])
      mapping[paste0("treatment", treatment, ":post:", covariate)] <- paste(treatment, "x 1[Post] x", cov_vars[covariate])
      mapping[paste0("treatment", treatment, ":post_is_misinfo:", covariate)] <- paste(treatment, "x 1[Misinfo] x", cov_vars[covariate])
      mapping[paste0("treatment", treatment, ":post:post_is_misinfo:", covariate)] <- paste(treatment, "x 1[Post] x 1[Misinfo] x", cov_vars[covariate])
    }
    
    # Interaction with domains
    for (i in 1:length(post_domains)) {
    mapping[paste0("factor(fact)",i,":",covariate)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    mapping[paste0(covariate,":factor(fact)",i)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    }
    
    # Interaction with post
    for (i in 1:length(post_domains)) {
    mapping[paste0("factor(fact)",i,":",covariate)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    mapping[paste0(covariate,":factor(fact)",i)] <- paste("Post domain",i,"x", cov_vars[covariate])  
    }
    
    # Interaction with misinfo
  
  }
  
  # Post attributes
  for (attribute in posts_vars) {
    
    
    
    # Interaction with treatments
    for (treatment in treatments) {
      mapping[paste0("treatment", treatment, ":", attribute)] <- paste(treatment, "x", posts_vars[attribute])
      mapping[paste0("treatment", treatment, ":post:", attribute)] <- paste(treatment, "x 1[Post-treatment] x ", posts_vars[attribute])
      mapping[paste0("treatment", treatment, ":post_is_misinfo:", attribute)] <- paste(treatment, "x 1[Misinfo] x ", posts_vars[attribute])
      mapping[paste0("treatment", treatment, ":post:post_is_misinfo:", attribute)] <- paste(treatment, "x 1[Post-treatment] x 1[Misinfo] x ", posts_vars[attribute])
    }
    
    
    for (i in 1:length(post_domains)) {
      mapping[paste0(attribute,":factor(fact)", i)] <- paste("Post domain", i,posts_vars[attribute])
      mapping[paste0("factor(fact)", i,attribute)] <- paste("Post domain", i,posts_vars[attribute])
      
      mapping[paste0("post:",attribute,":","factor(fact)", i)] <- paste("Post domain", i,"x 1[Post-treatment] x",posts_vars[attribute])
      mapping[paste0("post:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x 1[Post-treatment] x",posts_vars[attribute])
      
      mapping[paste0("post_is_misinfo:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x 1[Misinfo] x",posts_vars[attribute])
      
      
      for (treatment in treatments) {
        mapping[paste0("treatment", treatment, ":", attribute,":factor(fact)",i)] <- paste("Post domain", i,"x",treatment,"x",posts_vars[attribute])
        mapping[paste0("treatment", treatment, ":factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x",treatment,"x",posts_vars[attribute])
        
        mapping[paste0("treatment", treatment, ":post:",attribute,":factor(fact)",i)] <- paste("Post domain", i,"x",treatment,"x 1[Post-treatment]",posts_vars[attribute])
        
        mapping[paste0("treatment", treatment, ":post:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x",treatment,"x 1[Post-treatment]",posts_vars[attribute])
        
        mapping[paste0("treatment", treatment, ":post_is_misinfo:factor(fact)",i,":",attribute)] <- paste("Post domain", i,"x",treatment,"x 1[Misinfo]",posts_vars[attribute])
      }
    }
    
    mapping[paste0("post:", attribute)] <- paste("Post-treatment x", posts_vars[attribute])
    mapping[paste0("post_is_misinfo:", attribute)] <- paste("1[Misinfo] x", posts_vars[attribute])
  }
  
    # random cases not working
    rndm_vars <- c(
      "religiosity_Attends:factor(fact)3" = "Post domain 3 x Religiosity: Attends",
      "religiosity_Attends:factor(fact)4" = "Post domain 4 x Religiosity: Attends",
      "religiosity_Attends:factor(fact)5" = "Post domain 5 x Religiosity: Attends",
      "religiosity_Attends:factor(fact)6" = "Post domain 6 x Religiosity: Attends",
      
      "social_media_share_40_60:factor(fact)10" = "Post domain 10 x Social Media Share: 40-60%",
      "social_media_share_40_60:factor(fact)11" = "Post domain 11 x Social Media Share: 40-60%",
      "social_media_share_40_60:factor(fact)12" = "Post domain 12 x Social Media Share: 40-60%",
      "social_media_share_40_60:factor(fact)13" = "Post domain 13 x Social Media Share: 40-60%",
      
      "factor(post_id)19" = "Post 19 indicator",
      "factor(post_id)20" = "Post 20 indicator",
      "factor(post_id)21" = "Post 21 indicator"
    )

  return(c(mapping,basic_vars,cov_vars,manipulation_vars,post_id_vars,rndm_vars,posts_vars))
}
treatments <- c("No-course Baseline", "Reasoning", "Emotions", "Combo")
tactics <- c("Emotions posts","Combo posts","Reasoning posts","Base posts")
post_domains <- seq(1, 17)
post_ids <- seq(1,62)
covariates <- c("age_cov", "gender_Man_cov", 
                "education_Some_college_cov", "education_Bachelor_degree_cov", 
                "education_Graduate_degree_cov", "marital_Married_or_in_a_domestic_partnership_cov", 
                "employment_Unemployed_cov", "employment_Employed_cov", "location_Mostly_urban_cov", 
                "location_Suburban_cov", "religion_Christian_cov", "religiosity_Attends_cov", 
                "social_media_bin_Yes_cov", "social_media_hours_cov", "social_media_share_80_100_cov",
                "social_media_share_60_80_cov", "social_media_share_40_60_cov",
                "social_media_share_20_40_cov",
                "misinfo_pre_cov", "base_rate_pre_cov","att_check_pre_cov",
                "emotions_pre_cov","reasoning_pre_cov","combo_pre_cov")
variable_mapping <- generate_variable_mapping(treatments, post_domains, tactics, covariates)
variable_mapping_long <- as.character(variable_mapping)
names(variable_mapping_long) <- names(variable_mapping)

variable_mapping_followup <- generate_variable_mapping_followup(treatments, post_domains, tactics, covariates)
variable_mapping_long_followup <- as.character(variable_mapping_followup)
names(variable_mapping_long_followup) <- names(variable_mapping_followup)
# Load the intermediate outputs #
processed_data = readRDS("../intermediate_outcomes/data/intermediate_output/processed_data.rds")
processed_data_AC = readRDS("../intermediate_outcomes/data/intermediate_output/processed_data_AC.rds")
sg_data = readRDS("../intermediate_outcomes/data/intermediate_output/sg_data.rds")
# Extract the different dataframes for code visualization purposes #
course_tests_data_final = processed_data$course_tests_data_final
course_tests_data_by_type_final = processed_data$course_tests_data_by_type_final
followup_course_tests_data_final = processed_data$followup_course_tests_data_final
followup_course_tests_data_by_type_final = processed_data$followup_course_tests_data_by_type_final
followup_course_text_tests_data_final = processed_data$followup_course_text_tests_data_final
opposite_tests_data_final = processed_data$opposite_tests_data_final
non_counterparts_data_final = processed_data$non_counterparts_data_final
all_posts_data_final = processed_data$all_posts_data_final

course_tests_data_final_AC = processed_data_AC$course_tests_data_final
course_tests_data_by_type_final_AC = processed_data_AC$course_tests_data_by_type_final
followup_course_tests_data_final_AC = processed_data_AC$followup_course_tests_data_final
followup_course_tests_data_by_type_final_AC = processed_data_AC$followup_course_tests_data_by_type_final
followup_course_text_tests_data_final_AC = processed_data_AC$followup_course_text_tests_data_final
opposite_tests_data_final_AC = processed_data_AC$opposite_tests_data_final
non_counterparts_data_final_AC = processed_data_AC$non_counterparts_data_final
all_posts_data_final_AC = processed_data_AC$all_posts_data_final
# Load the raw inputs for table and images creation #
funnels = readRDS("tables_and_figures/0_data_pre_processing.rds")
descriptive_stats = readRDS("tables_and_figures/1_descriptive_stats_10172024.rds") # readRDS("tables_and_figures/1_descriptive_stats.rds") if wanting the old version
main_tests = readRDS("tables_and_figures/2_main_tests.rds")
AIPW_estimates = readRDS("tables_and_figures/3_AIPW_estimates.rds")
HTE_analysis = readRDS("tables_and_figures/4_HTE.rds")
# list of covariates
covariates_demeaned <- c("age_cov","gender_Man_cov",
                         #"education_High_school_or_less",
                         "education_Some_college_cov",
                         "education_Bachelor_degree_cov","education_Graduate_degree_cov",
                         "marital_Married_or_in_a_domestic_partnership_cov",
                         "employment_Unemployed_cov","employment_Employed_cov",
                         #"employment_Student",
                         "location_Mostly_urban_cov","location_Suburban_cov",
                         #"location_Mostly_rural",
                         "religion_Christian_cov","religiosity_Attends_cov",
                         "social_media_bin_Yes_cov","social_media_hours_cov",
                         "social_media_share_80_100_cov","social_media_share_60_80_cov",
                         "social_media_share_40_60_cov","social_media_share_20_40_cov",
                         #"social_media_share_0_20",
                         "att_check_pre_cov")

sharing_demeaned <- c("misinfo_pre_cov","base_rate_pre_cov")
tactic_demeaned <- c('emotions_pre_cov','reasoning_pre_cov','combo_pre_cov')

# demographics
demographics_demeaned_treatment <- paste0(covariates_demeaned,'*treatment',collapse = "+")
# pre non-misinfo and pre-misinfo sharing
sharing_demeaned_treatment <- paste0(sharing_demeaned,'*treatment',collapse = "+")
# pre non-misinfo, pre-misinfo sharing and tactic sharing rates
sharing_tactic_demeaned_treatment <- paste0(c(sharing_demeaned,tactic_demeaned),'*treatment',collapse = "+")
# demographics and pre-non-misinfo and pre-misinfo sharing
demographics_sharing_demeaned_treatment <- paste0(c(covariates_demeaned,sharing_demeaned),'*treatment',collapse = "+")
# all
all_covariates_demeaned_treatment <- paste0(c(covariates_demeaned,sharing_demeaned,tactic_demeaned),'*treatment',collapse = "+")

Descriptive Stats Re-Do

The balance plots have to be re-done in this script due to the previous result being run on a older R version, which causes error for any ggplot version greater than 3.5.0.

This session below is a re-do of the existing plot and is commented out to save running time. The output of the descriptive stats re-do is saved to the tables_and_figures folder, with new file name 1_descriptive_stats_REVISED.rds.

UPDATE (10/17/2024): Due the potential error that was found when creating the previous balance plots, the newly updated descriptive stats file is 1_descriptive_stats_10172024.rds. This file is used in the following section.

Table and Figures

Table 2: Funnel of Participants

The number of participants who started the pre-survey is an upper bound estimate because we could count only survey copies on Qualtrics and not identify users. We were only able to identify users once they completed the pre-survey and provided a phone number, which is how we ensured that all down-funnel outcomes counted unique users based on phone number. The post- and follow-up surveys required users to validate their phone number before they could start the survey. We received 40,845 survey copies in total for the pre-survey, of which we discarded 3,092 users who had participated in one of our pilot studies and another 12,466 survey copies filled out by duplicated phone numbers. In the post-survey, we filtered out participants who encountered system errors (N = 104), did not have at least 5 days in between pre- and post-survey dates (N = 2,101), and/or did not complete the full text-message course (N = 509). For the follow-up survey, we filtered out 2,371 survey copies filled out by duplicated phone numbers and retained only the first copy done by each phone number.

funnels$participants_funnel
##                             N Participants % of "Started Pre-survey"
## Started Pre-survey                   25287                         -
## Completed Pre-survey                 22526                    89.08%
## Started Text Message Course          18598                    73.55%
## Completed Day 1 Course               16684                    65.98%
## Completed Day 2 Course               13997                    55.35%
## Completed Day 3 Course               13093                    51.78%
## Completed Day 4 Course               11396                    45.07%
## Completed Entire Course              10934                    43.24%
## Started Post-survey                   9589                    37.92%
## Completed Post-survey                 8684                    34.34%
## Started Follow-up                     5785                    22.88%
## Completed Follow-up                   5316                    21.02%
##                             % of Previous Funnel Stage
## Started Pre-survey                                   -
## Completed Pre-survey                            89.08%
## Started Text Message Course                     82.56%
## Completed Day 1 Course                          89.71%
## Completed Day 2 Course                          83.89%
## Completed Day 3 Course                          93.54%
## Completed Day 4 Course                          87.04%
## Completed Entire Course                         95.95%
## Started Post-survey                              87.7%
## Completed Post-survey                           90.56%
## Started Follow-up                               66.62%
## Completed Follow-up                             91.89%

Table 3: Attrition and Attention Check Passing Rates, By Intervention Assignment Group

Main cells show the number of participants who completed the post-survey (in the Main Experiment) and the number of participants who completed the follow-up (in the Follow-up Experiment) in their respective assignment group. Numbers in parentheses are the ratios of the number of participants who completed the post-survey to the number of participants who completed the pre-survey (in the Main Experiment) and the ratios of the number of participants who completed the follow-up survey to the number of participants who completed the post-survey (in the Follow-up Experiment)}. Numbers in brackets are the ratios of the number of participants who correctly answered all attention checks in the pre- and post-survey to the number of participants who completed the post-survey (in the Main Experiment) and the ratios of the number of participants who correctly answered the single attention check in the follow-up survey to the number of participants who completed the follow-up survey (in the Follow-up Experiment). Numbers in curly brackets are the ratios of the number of participants who correctly answered all attention check questions in the pre-, post-, and follow-up surveys to the number of participants who completed the follow-up survey.

descriptive_stats$attrition_by_treatment
##                     No-course Baseline Facts Baseline Reasoning Emotions
## Accuracy After Post                827            886       856      894
## Share 1                       (36.46%)       (39.05%)  (37.93%) (38.67%)
## Attention Check 5             [30.96%]       [32.96%]  [31.89%] [33.45%]
## Accuracy Inter Post                801            904       834      942
## Share 2                       (36.05%)       (39.95%)  (37.72%) (42.72%)
## Attention Check 7             [37.45%]       [41.26%]  [40.89%] [40.76%]
## Totals Post                       1628           1790      1690     1836
## Share 3                       (36.26%)        (39.5%)  (37.82%) (40.65%)
## Attention Check 9             [34.15%]       [37.15%]  [36.33%]  [37.2%]
## Totals Followup                    964           1069      1072     1122
## Share 4                       (59.21%)       (59.72%)  (63.43%) (61.11%)
## Attention Check 10            [85.48%]       [86.25%]  [86.85%] [84.05%]
## Attention Check 11            {43.36%}       {44.53%}  {41.14%}  {42.6%}
##                        Combo   Totals
## Accuracy After Post      859     4322
## Share 1             (37.82%) (37.99%)
## Attention Check 5   [34.92%] [32.86%]
## Accuracy Inter Post      881     4362
## Share 2             (39.19%) (39.12%)
## Attention Check 7   [40.64%] [40.26%]
## Totals Post             1740     8684
## Share 3              (38.5%) (38.55%)
## Attention Check 9   [37.82%] [36.57%]
## Totals Followup         1089     5316
## Share 4             (62.59%) (61.22%)
## Attention Check 10  [85.86%] [85.68%]
## Attention Check 11   {43.8%} {43.08%}

Table 4: Summary Statistics for Post-Survey Completers

Sample includes the 8,684 participants who completed the post-survey. See Table \(\ref{table:covariates_explain}\) in the Appendix for definitions of covariates.

descriptive_stats$summary_stats
##                              Mean Std_Dev     Q1 Median     Q3 Perc_Missing
## Age                        26.397  7.5918     22     25     29           0%
## Man                         65.4%  0.4757                                0%
## High school or less         27.1%  0.4446                                0%
## Some college                35.5%  0.4787                                0%
## Bachelor's degree           36.1%  0.4802                                0%
## Graduate degree              1.3%  0.1118                                0%
## Married                     32.6%  0.4686                                0%
## Unemployed                  40.1%  0.4901                                0%
## Employed                    32.5%  0.4684                                0%
## Student                     27.4%  0.4459                                0%
## Mostly urban                28.5%  0.4514                                0%
## Suburban                    38.5%  0.4867                                0%
## Mostly rural                  33%  0.4701                                0%
## Christian                   94.2%   0.234                                0%
## Attends religious services  94.6%  0.2256                                0%
## Uses social media           99.3%  0.0815                                0%
## Hrs/day on social media     5.779  3.7131      3      5      7           0%
## 0-20%                       17.6%  0.3811                                0%
## 20-40%                        20%     0.4                                0%
## 40-60%                      30.6%   0.461                                0%
## 60-80%                      23.3%  0.4227                                0%
## 80-100%                      8.4%   0.278                                0%
## All posts                   0.595  0.3038 0.3333 0.6667 0.8889           0%
## Non-misinformation posts    0.693  0.3435 0.3333 0.6667      1           0%
## Misinformation posts        0.546  0.3308 0.3333    0.5 0.8333           0%

Appendix Figure C1: Differences in Samples, by Survey Completion

Pre sample includes the 13,842 participants who completed the pre-survey but not the post-survey. Post sample includes the 3,368 participants who completed both the pre-survey and the post-survey, but not the follow-up. Followup sample includes the 5,316 participants who completed all of the surveys. The differences are taken by subtracting the Pre sample from the Post sample, and the Post sample from the Follow-up sample.

descriptive_stats$std_diff_by_samples

ggsave("tables_and_figures/std_diff_by_samples.png", width = 18, height = 20)

Appendix Figure C2: Differences in Samples of Post-survey Completers, by Intervention Assignment Group

This plot displays the standardized differences between participants in the different treatment groups who completed the post-survey. The differences are calculated with respect to the No-course Baseline group.

descriptive_stats$std_diff_by_treatment_main

ggsave("tables_and_figures/std_diff_by_treatment_main.png", width = 18, height = 20)

Appendix Figure C3: Differences in Samples of Follow-up survey Completers, by Intervention Assignment Group

This plot displays the standardized differences between participants in the different treatment groups who completed the follow-up survey. The differences are calculated with respect to the Facts Baseline group.

descriptive_stats$std_diff_by_treatment_followup

ggsave("tables_and_figures/std_diff_by_treatment_followup.png", width = 18, height = 20)

New Tables

Main Treatment Effects Figure

  • 4 panels: one for each outcome in cross-sectional analysis
  • y-axis: treatment effect relative to Facts baseline
  • x-axis: No-course baseline, Emotions, Reasoning, Combo
  • points: estimates and 95% confidence intervals using diff-in-means, linear OLS with covariates (without accuracy nudge), AIPW
treatment_means <- readRDS("regression_analysis_wide/data/means_by_treatment_group.rds")

# 1 to 4 contain the outcomes of interests
treatment_means_diffinmean <- treatment_means[["models_wide"]]
treatment_means_allcov <- treatment_means[["models_all_covariates"]]


headers <- c("Conditional Misinfo Sharing Rate",
             "Misinfo Sharing Rate",
             "Non-Misinfo Sharing Rate",
             "Sharing Discernment Score")

treatment_means_df <- c()
treatment_means_allcov_df <- c()
# Extract means and std error
for (o in 1:4){
  treatment_means_df <- rbind(treatment_means_df, 
                              data.frame(outcome = headers[o],
                                         treatment = c("Facts Baseline", "No-course Baseline", "Reasoning", "Emotions", "Combo"),
                                         mean = treatment_means_diffinmean[[o]]$coefficients[1:5],
                                         se = treatment_means_diffinmean[[o]]$`std.error`[1:5]))
  treatment_means_allcov_df <- rbind(treatment_means_allcov_df,
                              data.frame(outcome = headers[o],
                                         treatment = c("Facts Baseline", "No-course Baseline", "Reasoning", "Emotions", "Combo"),
                                         mean = treatment_means_allcov[[o]]$coefficients[1:5],
                                         se = treatment_means_allcov[[o]]$`std.error`[1:5]))
  
}
row.names(treatment_means_df) <- NULL
row.names(treatment_means_allcov_df) <- NULL



wide <- readRDS("regression_analysis_wide/data/wide.rds")
tests_names_reg <- c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline")

#### Extrat difference-in-mean estimates
models_wide_te <- readRDS("regression_analysis_wide/data/models_wide_te.rds")
# 1 to 4 contain the outcomes of interests
models_wide_df <- c()
for (o in 1:4){
  models_wide_df <- rbind(models_wide_df,
                          data.frame(outcome = headers[o],
                                     test  = tests_names_reg,
                                     estimate = models_wide_te[[o]]$coefficients[2:5],
                                     se = models_wide_te[[o]]$std.error[2:5]))
}

#### Extract all ocvariates estimates
models_all_covariates_te <- readRDS("regression_analysis_wide/data/models_all_covariates_te.rds")
# 1 to 4 contain the outcomes of interests
models_all_covariates_df <- c()
for (o in 1:4){
  models_all_covariates_df <- rbind(models_all_covariates_df,
                          data.frame(outcome = headers[o],
                                     test  = tests_names_reg,
                                     estimate = models_all_covariates_te[[o]]$coefficients[2:5],
                                     se = models_all_covariates_te[[o]]$std.error[2:5]))
}

#### Extract AIPW estimates
# 1 to 4 contain the outcomes of interests
AIPW_tables <- readRDS("regression_analysis_wide/data/AIPW_tables_list.rds")

# 6 Reasoning, 7 Emotions, 8 Combo, 9 No-course Baseline in AIPW tables
tests_of_interest <- 6:9
tests_names <- c("Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline", "No-course Baseline vs Facts Baseline")

AIPW_tables_df <- c()
for (o in 1:4){
  AIPW_tables_df <- rbind(AIPW_tables_df, 
                          data.frame(outcome = headers[o],
                                     test = tests_names,
                                     estimate = AIPW_tables[[o]]$estimates[tests_of_interest],
                                     se = AIPW_tables[[o]]$`std.err`[tests_of_interest]))
}
# Recall our test is done using Facts Baseline vs No-course Baseline (as the reference)
# Thus, we need to reverse the sign [only for AIPW table]
AIPW_tables_df[AIPW_tables_df$test == "No-course Baseline vs Facts Baseline", "estimate"] <- -AIPW_tables_df[AIPW_tables_df$test == "No-course Baseline vs Facts Baseline", "estimate"]
treatment_means_followup <- readRDS("regression_analysis_wide/followup/data/means_by_treatment_group_followup.rds")
treatment_means_allcov_followup <- treatment_means_followup[["models_wide"]]

headers <- c("Conditional Misinfo Sharing Rate",
             "Misinfo Sharing Rate",
             "Non-Misinfo Sharing Rate",
             "Sharing Discernment Score")

treatment_means_followup_df <- c()
# Extract means and std error
for (o in 1:4){
  treatment_means_followup_df <- rbind(treatment_means_followup_df, 
                              data.frame(outcome = headers[o],
                                         treatment = c("Facts Baseline", "No-course Baseline", "Reasoning", "Emotions", "Combo"),
                                         mean = treatment_means_allcov_followup[[o]]$coefficients[1:5],
                                         se = treatment_means_allcov_followup[[o]]$`std.error`[1:5]))
}
row.names(treatment_means_followup_df) <- NULL


wide_followup <- readRDS("regression_analysis_wide/followup/data/wide_followup.rds")
tests_names_reg <- c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline")

#### Extrat difference-in-mean estimates
models_wide_te_followup <- readRDS("regression_analysis_wide/followup/data/models_wide_te_followup.rds")
# 1 to 4 contain the outcomes of interests
models_wide_followup_df <- c()
for (o in 1:4){
  models_wide_followup_df <- rbind(models_wide_followup_df,
                          data.frame(outcome = headers[o],
                                     test  = tests_names_reg,
                                     estimate = models_wide_te_followup[[o]]$coefficients[2:5],
                                     se = models_wide_te_followup[[o]]$std.error[2:5]))
}

#### Extract all ocvariates estimates
models_all_covariates_te_followup <- readRDS("regression_analysis_wide/followup/data/models_all_covariates_te_followup.rds")
# 1 to 4 contain the outcomes of interests
models_all_covariates_followup_df <- c()
for (o in 1:4){
  models_all_covariates_followup_df <- rbind(models_all_covariates_followup_df,
                          data.frame(outcome = headers[o],
                                     test  = tests_names_reg,
                                     estimate = models_all_covariates_te_followup[[o]]$coefficients[2:5],
                                     se = models_all_covariates_te_followup[[o]]$std.error[2:5]))
}

#### Extract AIPW estimates
# 1 to 4 contain the outcomes of interests
AIPW_tables_followup <- readRDS("regression_analysis_wide/followup/data/AIPW_tables_list_followup.rds")

# 6 Reasoning, 7 Emotions, 8 Combo, 9 No-course Baseline in AIPW tables
tests_of_interest <- 6:9
tests_names <- c("Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline", "No-course Baseline vs Facts Baseline")

AIPW_tables_followup_df <- c()
for (o in 1:4){
  AIPW_tables_followup_df <- rbind(AIPW_tables_followup_df, 
                          data.frame(outcome = headers[o],
                                     test = tests_names,
                                     estimate = AIPW_tables_followup[[o]]$estimates[tests_of_interest],
                                     se = AIPW_tables_followup[[o]]$`std.err`[tests_of_interest]))
}
# Recall our test is done using Facts Baseline vs No-course Baseline (as the reference)
# Thus, we need to reverse the sign [only for AIPW table]
AIPW_tables_followup_df[AIPW_tables_followup_df$test == "No-course Baseline vs Facts Baseline", "estimate"] <- -AIPW_tables_followup_df[AIPW_tables_followup_df$test == "No-course Baseline vs Facts Baseline", "estimate"]
# Plots outcome by assignment group and selected treatment effects #
plot_gen_conditional_misinfo = function(data,color,ylab,xlab,y_min,y_max,title,num_size,baseline,tests){
    
pic = ggplot(data=data,aes(x=treatment,y=mean))+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_blank(),      
        legend.position = c(.9,.8),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),
        legend.box.just = "right", legend.text = element_text(size=12), legend.margin = margin(6, 6, 6, 6),
        legend.box.background = element_rect( fill="transparent", size=1),legend.background = element_blank()) +
    
        geom_bar(stat='identity',width=0.5,color="black",fill=color) +
        geom_errorbar(aes(ymin=mean-1.96*se, ymax = mean+1.96*se),width=0.1, size=0.5, position = position_dodge(1)) 
    
        if (baseline){
        
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+sign(mean)*se),vjust = -2.5,size=num_size)+
                geom_text(aes(label=paste("(",as.character(formatC(se,digits=4,format="f")),")",sep=""),y=mean+sign(mean)*se),vjust = -1,size=num_size-1)}    
    
        if (!baseline){
            
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+se),vjust = -1,size=num_size)    
        }
  
        
        pic = pic + geom_hline(yintercept = 0)+

        geom_segment(aes(x = 2, y = 1.12, xend = 5, yend = 1.12), color = "orange2",size=0.5)+
        geom_segment(aes(x = 2, y = 1.12, xend = 2, yend = 0.7), color = "orange2",size=0.5)+
        geom_segment(aes(x = 5, y = 1.12, xend = 5, yend = 0.6), color = "orange2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 1.02, xend = 4, yend = 1.02), color = "pink2",size=0.5)+
        geom_segment(aes(x = 2, y = 1.02, xend = 2, yend = 0.7), color = "pink2",size=0.5)+
        geom_segment(aes(x = 4, y = 1.02, xend = 4, yend = 0.6), color = "pink2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 0.92, xend = 3, yend = 0.92), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 2, y = 0.92, xend = 2, yend = 0.7), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 3, y = 0.92, xend = 3, yend = 0.65), color = "turquoise2",size=0.5)+
    
        geom_segment(aes(x = 1, y = 0.81, xend = 2, yend = 0.81), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 1, y = 0.81, xend = 1, yend = 0.75), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 2, y = 0.81, xend = 2, yend = 0.7), color = "royalblue3",size=0.5)+

    
        annotate("text",x=4.5,y=1.175,label = paste0(formatC(tests$estimate[4],digits=3,format='f'), "\n(",formatC(tests$se[4],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=3.5,y=1.075,label = paste0(formatC(tests$estimate[3],digits=3,format='f'), "\n(",formatC(tests$se[3],digits=4,format='f'),")"),size=2.5) +    
        annotate("text",x=2.5,y=0.975,label = paste0(formatC(tests$estimate[2],digits=3,format='f'), "\n(",formatC(tests$se[2],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=1.5,y=0.875,label = paste0(formatC(tests$estimate[1],digits=3,format='f'), "\n(",formatC(tests$se[1],digits=4,format='f'),")"),size=2.5) +
        
    
       labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 10, angle = 0, hjust = .5, vjust = 5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 10, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 12, angle = 0, hjust = .5, vjust = 3, face = "bold"),
        axis.title.y = element_text(color = "black", size = 15, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), axis.ticks.x=element_blank())+
        scale_y_continuous(limits = c(y_min,y_max)) +
        scale_x_discrete(limits = data$treatment) +

    
        ggtitle(title) +

        theme(plot.title = element_text(face='bold', size=12, hjust=0.5, vjust=0.5))
pic}
# Plots outcome by assignment group and selected treatment effects #
plot_gen_misinfo = function(data,color,ylab,xlab,y_min,y_max,title,num_size,baseline,tests){
    
pic = ggplot(data=data,aes(x=treatment,y=mean))+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_blank(),      
        legend.position = c(.9,.8),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),
        legend.box.just = "right", legend.text = element_text(size=12), legend.margin = margin(6, 6, 6, 6),
        legend.box.background = element_rect( fill="transparent", size=1),legend.background = element_blank()) +
    
        geom_bar(stat='identity',width=0.5,color="black",fill=color) +
        geom_errorbar(aes(ymin=mean-1.96*se, ymax = mean+1.96*se),width=0.1, size=0.5, position = position_dodge(1)) 
    
        if (baseline){
        
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+sign(mean)*se),vjust = -2.5,size=num_size)+
                geom_text(aes(label=paste("(",as.character(formatC(se,digits=4,format="f")),")",sep=""),y=mean+sign(mean)*se),vjust = -1,size=num_size-1)}    
    
        if (!baseline){
            
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+se),vjust = -1,size=num_size)    
        }
  
        
        pic = pic + geom_hline(yintercept = 0)+

        geom_segment(aes(x = 2, y = 1.04, xend = 5, yend = 1.04), color = "orange2",size=0.5)+
        geom_segment(aes(x = 2, y = 1.04, xend = 2, yend = 0.63), color = "orange2",size=0.5)+
        geom_segment(aes(x = 5, y = 1.04, xend = 5, yend = 0.52), color = "orange2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 0.94, xend = 4, yend = 0.94), color = "pink2",size=0.5)+
        geom_segment(aes(x = 2, y = 0.94, xend = 2, yend = 0.63), color = "pink2",size=0.5)+
        geom_segment(aes(x = 4, y = 0.94, xend = 4, yend = 0.52), color = "pink2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 0.84, xend = 3, yend = 0.84), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 2, y = 0.84, xend = 2, yend = 0.63), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 3, y = 0.84, xend = 3, yend = 0.57), color = "turquoise2",size=0.5)+
    
        geom_segment(aes(x = 1, y = 0.73, xend = 2, yend = 0.73), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 1, y = 0.73, xend = 1, yend = 0.67), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 2, y = 0.73, xend = 2, yend = 0.63), color = "royalblue3",size=0.5)+

    
        annotate("text",x=4.5,y=1.095,label = paste0(formatC(tests$estimate[4],digits=3,format='f'), "\n(",formatC(tests$se[4],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=3.5,y= 0.995,label = paste0(formatC(tests$estimate[3],digits=3,format='f'), "\n(",formatC(tests$se[3],digits=4,format='f'),")"),size=2.5) +    
        annotate("text",x=2.5,y=0.895,label = paste0(formatC(tests$estimate[2],digits=3,format='f'), "\n(",formatC(tests$se[2],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=1.5,y=0.795,label = paste0(formatC(tests$estimate[1],digits=3,format='f'), "\n(",formatC(tests$se[1],digits=4,format='f'),")"),size=2.5) +
        
    
       labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 10, angle = 0, hjust = .5, vjust = 5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 10, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 12, angle = 0, hjust = .5, vjust = 3, face = "bold"),
        axis.title.y = element_text(color = "black", size = 15, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), axis.ticks.x=element_blank())+
        scale_y_continuous(limits = c(y_min,y_max)) +
        scale_x_discrete(limits = data$treatment) +

    
        ggtitle(title) +

        theme(plot.title = element_text(face='bold', size=12, hjust=0.5, vjust=0.5))
pic}
# Plots outcome by assignment group and selected treatment effects #
plot_gen_nonmisinfo = function(data,color,ylab,xlab,y_min,y_max,title,num_size,baseline,tests){
    
pic = ggplot(data=data,aes(x=treatment,y=mean))+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_blank(),      
        legend.position = c(.9,.8),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),
        legend.box.just = "right", legend.text = element_text(size=12), legend.margin = margin(6, 6, 6, 6),
        legend.box.background = element_rect( fill="transparent", size=1),legend.background = element_blank()) +
    
        geom_bar(stat='identity',width=0.5,color="black",fill=color) +
        geom_errorbar(aes(ymin=mean-1.96*se, ymax = mean+1.96*se),width=0.1, size=0.5, position = position_dodge(1)) 
    
        if (baseline){
        
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+sign(mean)*se),vjust = -2.5,size=num_size)+
                geom_text(aes(label=paste("(",as.character(formatC(se,digits=4,format="f")),")",sep=""),y=mean+sign(mean)*se),vjust = -1,size=num_size-1)}    
    
        if (!baseline){
            
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+se),vjust = -1,size=num_size)    
        }
  
        
        pic = pic + geom_hline(yintercept = 0)+

        geom_segment(aes(x = 2, y = 1.2, xend = 5, yend = 1.2), color = "orange2",size=0.5)+
        geom_segment(aes(x = 2, y = 1.2, xend = 2, yend = 0.78), color = "orange2",size=0.5)+
        geom_segment(aes(x = 5, y = 1.2, xend = 5, yend = 0.7), color = "orange2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 1.09, xend = 4, yend = 1.09), color = "pink2",size=0.5)+
        geom_segment(aes(x = 2, y = 1.09, xend = 2, yend = 0.78), color = "pink2",size=0.5)+
        geom_segment(aes(x = 4, y = 1.09, xend = 4, yend = 0.7), color = "pink2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 0.98, xend = 3, yend = 0.98), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 2, y = 0.98, xend = 2, yend = 0.83), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 3, y = 0.98, xend = 3, yend = 0.75), color = "turquoise2",size=0.5)+
    
        geom_segment(aes(x = 1, y = 0.88, xend = 2, yend = 0.88), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 1, y = 0.88, xend = 1, yend = 0.82), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 2, y = 0.88, xend = 2, yend = 0.78), color = "royalblue3",size=0.5)+

    
        annotate("text",x=4.5,y=1.255,label = paste0(formatC(tests$estimate[4],digits=3,format='f'), "\n(",formatC(tests$se[4],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=3.5,y= 1.145,label = paste0(formatC(tests$estimate[3],digits=3,format='f'), "\n(",formatC(tests$se[3],digits=4,format='f'),")"),size=2.5) +    
        annotate("text",x=2.5,y=1.04,label = paste0(formatC(tests$estimate[2],digits=3,format='f'), "\n(",formatC(tests$se[2],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=1.5,y=0.945,label = paste0(formatC(tests$estimate[1],digits=3,format='f'), "\n(",formatC(tests$se[1],digits=4,format='f'),")"),size=2.5) +
        
    
       labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 10, angle = 0, hjust = .5, vjust = 5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 10, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 12, angle = 0, hjust = .5, vjust = 3, face = "bold"),
        axis.title.y = element_text(color = "black", size = 15, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), axis.ticks.x=element_blank())+
        scale_y_continuous(limits = c(y_min,y_max)) +
        scale_x_discrete(limits = data$treatment) +

    
        ggtitle(title) +

        theme(plot.title = element_text(face='bold', size=12, hjust=0.5, vjust=0.5))
pic}
# Plots outcome by assignment group and selected treatment effects #
plot_gen_discern = function(data,color,ylab,xlab,y_min,y_max,title,num_size,baseline,tests){
    
pic = ggplot(data=data,aes(x=treatment,y=mean))+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_blank(),      
        legend.position = c(.9,.8),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),
        legend.box.just = "right", legend.text = element_text(size=12), legend.margin = margin(6, 6, 6, 6),
        legend.box.background = element_rect( fill="transparent", size=1),legend.background = element_blank()) +
    
        geom_bar(stat='identity',width=0.5,color="black",fill=color) +
        geom_errorbar(aes(ymin=mean-1.96*se, ymax = mean+1.96*se),width=0.1, size=0.5, position = position_dodge(1)) 
    
        if (baseline){
        
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+sign(mean)*se),vjust = -2.5,size=num_size)+
                geom_text(aes(label=paste("(",as.character(formatC(se,digits=4,format="f")),")",sep=""),y=mean+sign(mean)*se),vjust = -1,size=num_size-1)}    
    
        if (!baseline){
            
        pic = pic + geom_text(aes(label=as.character(formatC(mean,digits=3,format="f")),y=mean+se),vjust = -1,size=num_size)    
        }
  
        
        pic = pic + geom_hline(yintercept = 0)+

        geom_segment(aes(x = 2, y = 0.46, xend = 5, yend = 0.46), color = "orange2",size=0.5)+
        geom_segment(aes(x = 2, y = 0.46, xend = 2, yend = 0.23), color = "orange2",size=0.5)+
        geom_segment(aes(x = 5, y = 0.46, xend = 5, yend = 0.23), color = "orange2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 0.38, xend = 4, yend = 0.38), color = "pink2",size=0.5)+
        geom_segment(aes(x = 2, y = 0.38, xend = 2, yend = 0.23), color = "pink2",size=0.5)+
        geom_segment(aes(x = 4, y = 0.38, xend = 4, yend = 0.25), color = "pink2",size=0.5)+
    
        geom_segment(aes(x = 2, y = 0.3, xend = 3, yend = 0.3), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 2, y = 0.3, xend = 2, yend = 0.23), color = "turquoise2",size=0.5)+
        geom_segment(aes(x = 3, y = 0.3, xend = 3, yend = 0.23), color = "turquoise2",size=0.5)+
    
        geom_segment(aes(x = 1, y = 0.28, xend = 2, yend = 0.28), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 1, y = 0.28, xend = 1, yend = 0.22), color = "royalblue3",size=0.5)+
        geom_segment(aes(x = 2, y = 0.28, xend = 2, yend = 0.23), color = "royalblue3",size=0.5)+

    
        annotate("text",x=4.5,y=0.505,label = paste0(formatC(tests$estimate[4],digits=3,format='f'), "\n(",formatC(tests$se[4],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=3.5,y= 0.425,label = paste0(formatC(tests$estimate[3],digits=3,format='f'), "\n(",formatC(tests$se[3],digits=4,format='f'),")"),size=2.5) +    
        annotate("text",x=2.5,y=0.34,label = paste0(formatC(tests$estimate[2],digits=3,format='f'), "\n(",formatC(tests$se[2],digits=4,format='f'),")"),size=2.5) +
        annotate("text",x=1.5,y=0.325,label = paste0(formatC(tests$estimate[1],digits=3,format='f'), "\n(",formatC(tests$se[1],digits=4,format='f'),")"),size=2.5) +
        
    
       labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 10, angle = 0, hjust = .5, vjust = 5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 10, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 12, angle = 0, hjust = .5, vjust = 3, face = "bold"),
        axis.title.y = element_text(color = "black", size = 15, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), axis.ticks.x=element_blank())+
        scale_y_continuous(limits = c(y_min,y_max)) +
        scale_x_discrete(limits = data$treatment) +

    
        ggtitle(title) +

        theme(plot.title = element_text(face='bold', size=12, hjust=0.5, vjust=0.5))
pic}
o <- "Sharing Discernment Score"
figure_data <- treatment_means_df[treatment_means_df$outcome == o,]
# make sure treatment order
figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
# reorder figure data
figure_data <- figure_data[order(figure_data$treatment),]
test_data <- AIPW_tables_df[AIPW_tables_df$outcome == o,]
# reorder test data
test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
test_data <- test_data[order(test_data$test),]

figure_discern <- plot_gen_discern(figure_data, c("gray70","royalblue3","turquoise2","pink2","orange2"),
                 o,"Intervention assignment group",
                   -0.0003,0.55,"",3.5,TRUE,test_data)
figure_discern
o <- "Non-Misinfo Sharing Rate"
figure_data <- treatment_means_df[treatment_means_df$outcome == o,]
# make sure treatment order
figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
# reorder figure data
figure_data <- figure_data[order(figure_data$treatment),]
test_data <- AIPW_tables_df[AIPW_tables_df$outcome == o,]
# reorder test data
test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
test_data <- test_data[order(test_data$test),]

figure_nonmisinfo <- plot_gen_nonmisinfo(figure_data, c("gray70","royalblue3","turquoise2","pink2","orange2"),
                 o,"Intervention assignment group",
                   -0.0003,1.3,"",3.5,TRUE,test_data)
figure_nonmisinfo
o <- "Misinfo Sharing Rate"
figure_data <- treatment_means_df[treatment_means_df$outcome == o,]
# make sure treatment order
figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
# reorder figure data
figure_data <- figure_data[order(figure_data$treatment),]
test_data <- AIPW_tables_df[AIPW_tables_df$outcome == o,]
# reorder test data
test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
test_data <- test_data[order(test_data$test),]

figure_misinfo <- plot_gen_misinfo(figure_data, c("gray70","royalblue3","turquoise2","pink2","orange2"),
                 o,"Intervention assignment group",
                   -0.0003,1.15,"",3.5,TRUE,test_data)
figure_misinfo
o <- "Conditional Misinfo Sharing Rate"
figure_data <- treatment_means_df[treatment_means_df$outcome == o,]
# make sure treatment order
figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
# reorder figure data
figure_data <- figure_data[order(figure_data$treatment),]
test_data <- AIPW_tables_df[AIPW_tables_df$outcome == o,]
# reorder test data
test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
test_data <- test_data[order(test_data$test),]

figure_conditional_misinfo <- plot_gen_conditional_misinfo(figure_data, c("gray70","royalblue3","turquoise2","pink2","orange2"),
                 o,"Intervention assignment group",
                   -0.0003,1.22,"",3.5,TRUE,test_data)
figure_conditional_misinfo
plot_gen_te <- function(data,color,ylab,xlab,y_min,y_max,title,num_size,baseline,tests){
  tests$treatment <- str_replace_all(tests$test, " vs Facts Baseline", "")
  tests$treatment <- factor(tests$treatment, levels = c("No-course Baseline", "Reasoning", "Emotions", "Combo"))
  pic = ggplot(data=tests,aes(x=treatment,y=estimate))+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),
              axis.line.x = element_line(colour="black"),
              panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_blank(),      
        legend.position = c(.9,.8),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),
        legend.box.just = "right", legend.text = element_text(size=12), legend.margin = margin(6, 6, 6, 6),
        legend.box.background = element_rect( fill="transparent", size=1),legend.background = element_blank()) +
    
        # geom_bar(stat='identity',width=0.5,color="black",fill=color) +
        geom_errorbar(aes(ymin=estimate-1.96*se, ymax = estimate+1.96*se),width=0.15, size=2, position = position_dodge(1),
                      colour=color) +
        geom_point(size=5,colour=color)
    
      pic = pic+
        # dashed line
        geom_hline(yintercept = 0, linetype="dashed")+
        labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 17, angle = 0, hjust = .5, vjust = .5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 20, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 27.5, angle = 0, hjust = .5, vjust = .5, face = "bold"),
        axis.title.y = element_text(color = "black", size = 27.5, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), axis.ticks.x=element_blank()
        )+
        scale_y_continuous(limits = c(y_min,y_max)) +
        scale_x_discrete(limits = tests$treatment) +
    
        ggtitle(title,
                subtitle = paste0("Relative to Facts Baseline mean: ", round(data[data$treatment == "Facts Baseline", "mean"], 4))) +

        theme(plot.title = element_text(face='bold', size=25, hjust=0.5, vjust=0.5),
              plot.subtitle = element_text(face='bold', size=20))
pic}
for (o in headers){
  figure_data <- treatment_means_df[treatment_means_df$outcome == o,]
  # make sure treatment order
  figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
  # reorder figure data
  figure_data <- figure_data[order(figure_data$treatment),]
  test_data <- models_wide_df[models_wide_df$outcome == o,]
  # reorder test data
  test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
  test_data <- test_data[order(test_data$test),]
  
  figure <- plot_gen_te(figure_data, c("royalblue3","turquoise2","pink2","orange2"),
                   o,"Intervention assignment group",
                     -0.17,0.17,"",3.5,TRUE,test_data)
  
  print(figure)
  ggsave(paste0("figures/", o, ".png"), plot = figure, width = 10, height = 8)
}
for (o in headers){
  figure_data <- treatment_means_followup_df[treatment_means_followup_df$outcome == o,]
  # make sure treatment order
  figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
  # reorder figure data
  figure_data <- figure_data[order(figure_data$treatment),]
  test_data <- models_wide_followup_df[models_wide_followup_df$outcome == o,]
  # reorder test data
  test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
  test_data <- test_data[order(test_data$test),]
  
  figure <- plot_gen_te(figure_data, c("royalblue3","turquoise2","pink2","orange2"),
                   paste0(o, "\n(Follow-up)"),"Intervention assignment group",
                     -0.17,0.17,"",3.5,TRUE,test_data)
  
  print(figure)
  ggsave(paste0("figures/", o, "_followup.png"), plot = figure, width = 10, height = 8)
}
### Attempt at combining main and followup
plot_gen_te_combined <- function(data,color,ylab,xlab,y_min,y_max,title,num_size,baseline,tests){
  tests$treatment <- str_replace_all(tests$test, " vs Facts Baseline", "")
  tests$treatment <- factor(tests$treatment, levels = c("No-course Baseline", "Reasoning", "Emotions", "Combo"))
  pic = ggplot(data=tests,aes(x=treatment,y=estimate, color = followup))+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),
              axis.line.x = element_line(colour="black"),
              panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_blank(),      
        legend.position = c(.9,.8),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),
        legend.box.just = "right", legend.text = element_text(size=12), legend.margin = margin(6, 6, 6, 6),
        legend.box.background = element_rect( fill="transparent", size=1),legend.background = element_blank()) +
    
        # geom_bar(stat='identity',width=0.5,color="black",fill=color) +
        geom_errorbar(aes(ymin=estimate-1.96*se, ymax = estimate+1.96*se),width=0.3, size=1.5, position = position_dodge(0.5)) +
        geom_point(size=5, position = position_dodge(0.5))
    
      pic = pic+
        # dashed line
        geom_hline(yintercept = 0, linetype="dashed")+
        labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 17, angle = 0, hjust = 0.25, vjust = .5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 20, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 27.5, angle = 0, hjust = .5, vjust = .5, face = "bold"),
        axis.title.y = element_text(color = "black", size = 27.5, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), axis.ticks.x=element_blank()
        )+
        scale_y_continuous(limits = c(y_min,y_max)) +
        scale_x_discrete(limits = tests$treatment) +
    
        ggtitle(title,
                subtitle = paste0("Relative to Facts Baseline mean: ", 
                                  round(data[data$treatment == "Facts Baseline" & data$followup == "main", "mean"], 4),
                                  "(Main); ", 
                                  round(data[data$treatment == "Facts Baseline" & data$followup == "followup", "mean"], 4), 
                                  "(Follow-up)")) +

        theme(plot.title = element_text(face='bold', size=25, hjust=0.5, vjust=0.5),
              plot.subtitle = element_text(face='bold', size=17))
pic}
treatment_means_followup_df$followup <- "followup"
treatment_means_df$followup <- "main"
models_wide_followup_df$followup <- "followup"
models_wide_df$followup <- "main"

for (o in headers){
  figure_data <- rbind(
    treatment_means_followup_df[treatment_means_followup_df$outcome == o,],
    treatment_means_df[treatment_means_df$outcome == o,])
  # make sure treatment order
  figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
  # reorder figure data
  figure_data <- figure_data[order(figure_data$treatment),]
  figure_data$followup <- factor(figure_data$followup, levels = c("main", "followup"))
  
  test_data <- rbind(
    models_wide_followup_df[models_wide_followup_df$outcome == o,],
    models_wide_df[models_wide_df$outcome == o,])
  # reorder test data
  test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
  test_data <- test_data[order(test_data$test),]
  test_data$followup <- factor(test_data$followup, levels = c("main", "followup"))
  
  figure <- plot_gen_te_combined(figure_data, c("blue4","yellow2"),
                   o,"Intervention assignment group",
                     -0.17,0.17,"",3.5,TRUE,test_data)
  
  print(figure)
  ggsave(paste0("figures/", o, "_combined.png"), plot = figure, width = 10, height = 8)
}
### Attempt at combining diff_in_mean, OLS w/ covariates, and AIPW
plot_gen_te_main_figure <- function(color,ylab,xlab,y_min,y_max,title,num_size,baseline,tests){
  tests$treatment <- str_replace_all(tests$test, " vs Facts Baseline", "")
  tests$treatment <- factor(tests$treatment, levels = c("No-course Baseline", "Reasoning", "Emotions", "Combo"))
  pic = ggplot(data=tests,aes(x=treatment,y=estimate, color = type))+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),
              axis.line.x = element_line(colour="black"),
              panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_blank(),      
        legend.position = c(1,.8),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),
        legend.box.just = "right", legend.text = element_text(size=18), legend.margin = margin(6, 6, 6, 6),
        legend.box.background = element_rect( fill="transparent", size=1),legend.background = element_blank()) +
    
        # geom_bar(stat='identity',width=0.5,color="black",fill=color) +
        geom_errorbar(aes(ymin=estimate-1.96*se, ymax = estimate+1.96*se),width=0.4, size=1.5, position = position_dodge(0.5)) +
        geom_point(size=5, position = position_dodge(0.5))
    
      pic = pic+
        # dashed line
        geom_hline(yintercept = 0, linetype="dashed")+
        labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 19, angle = 0, hjust = 0.5, vjust = .5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 25, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 27.5, angle = 0, hjust = .5, vjust = .5, face = "bold"),
        axis.title.y = element_text(color = "black", size = 27.5, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), 
        axis.ticks.x=element_blank()
        )+
        scale_y_continuous(limits = c(y_min,y_max))
        # scale_x_discrete(limits = tests$treatment, expand = c(0, -0.4)) 
        
        # ggtitle(title,
        #         subtitle = paste0("Relative to Facts Baseline mean: ", 
        #                           round(data[data$treatment == "Facts Baseline" & data$followup == "main", "mean"], 4),
        #                           "(Main); ", 
        #                           round(data[data$treatment == "Facts Baseline" & data$followup == "followup", "mean"], 4), 
        #                           "(Follow-up)")) +

        # theme(plot.title = element_text(face='bold', size=25, hjust=0.5, vjust=0.5),
        #       plot.subtitle = element_text(face='bold', size=17))
pic}
models_wide_df$type <- "Diff-in-Mean"
models_all_covariates_df$type <- "OLS w/ All Covariates"
AIPW_tables_df$type <- "AIPW"

vars <- c( "outcome","test","estimate","se","type"  )

for (o in headers){
  # figure_data <- rbind(
  #   treatment_means_followup_df[treatment_means_followup_df$outcome == o,],
  #   treatment_means_df[treatment_means_df$outcome == o,])
  # # make sure treatment order
  # figure_data$treatment <- factor(figure_data$treatment, levels = c("No-course Baseline", "Facts Baseline", "Reasoning", "Emotions",  "Combo"))
  # # reorder figure data
  # figure_data <- figure_data[order(figure_data$treatment),]
  # figure_data$type <- factor(figure_data$type, levels = c("Diff-in-Mean", "OLS w/ All Covariates", "AIPW"))
  
  test_data <- rbind(
    models_wide_df[models_wide_followup_df$outcome == o,  vars],
    models_all_covariates_df[models_wide_df$outcome == o, vars],
    AIPW_tables_df[AIPW_tables_df$outcome == o, vars])
  # reorder test data
  test_data$test <- factor(test_data$test, levels = c("No-course Baseline vs Facts Baseline", "Reasoning vs Facts Baseline", "Emotions vs Facts Baseline", "Combo vs Facts Baseline"))
  test_data <- test_data[order(test_data$test),]
  test_data$type <- factor(test_data$type, levels = c("Diff-in-Mean", "OLS w/ All Covariates", "AIPW"))
  
  figure <- plot_gen_te_main_figure( c("blue4","yellow2"),
                   o,"Intervention assignment group",
                     -0.17,0.17,"",3.5,TRUE,test_data)
  
  print(figure)
  ggsave(paste0("figures/", o, "_mainfigure.png"), plot = figure, width = 10, height = 8)
}

Figure 5: Misinformation sharing for Treatment Courses only, by assignment group

Sample includes 4,646 participants in the Reasoning, Emotions or Combo intervention assignment groups who completed the post-survey and shared at least one non-misinformation post in the pre-survey. Each group of bars displays the Sharing Rate for misinformation posts of each type, as defined in Equation \(\ref{eq:outcome}\), by participants in their respective intervention assignment group, pooling participants in the Accuracy Inter and Accuracy After groups. Above each bar, the standard error is shown in parentheses below the Sharing Rate. The thin black bars represent 95% confidence intervals. Differences in Sharing Rates are shown above lines connecting the two relevant intervention assignment groups, with standard errors in parentheses.

# Plots outcome by assignment group and selected treatment effects #
plot_gen_side_by_side = function(data,color,ylab,xlab,y_max,title,num_size,baseline,tests){
    
pic = ggplot(data=data,aes(x=grouping,y=mean,group=W,fill=W),xlab = n_tile)+
        theme_bw()+
        theme(axis.line.y = element_line(colour="black"),panel.border = element_blank(), 
              panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        legend.title = element_text(size=40, face= "bold"),      
        legend.position = c(0.72,0.95),legend.justification = c("right", "bottom"), 
        legend.key = element_rect(colour = "transparent"),legend.direction="horizontal",
        legend.box.just = "right", legend.text = element_text(size=40), legend.margin = margin(6, 6, 6, 6),
        legend.background = element_rect(color = NA)) +
    
        geom_bar(stat='identity',position=position_dodge(width=0.72),width=0.7,color="black",alpha=0.5) +
        geom_errorbar(aes(ymin=mean-1.96*sd, ymax = mean+1.96*sd),width=0.3, size=1, position = position_dodge(0.7)) +
        geom_hline(yintercept = 0) +
    
        scale_fill_manual(name="Treatment course:",values=color) +
        labs(y=ylab,x=xlab)+
        theme(axis.text.x = element_text(color = "black", size = 40, angle = 0, hjust = .5, vjust = 5, face = "plain"),
        axis.text.y = element_text(color = "black", size = 45, angle = 0, hjust = 0, vjust = .5, face = "plain",
                                   margin=unit(rep(0.5,4),"cm")),  
        axis.title.x = element_text(color = "black", size = 55, angle = 0, hjust = .5, vjust = 3, face = "bold"),
        axis.title.y = element_text(color = "black", size = 60, angle = 90, hjust = .5, vjust = .5, face = "bold"),
        axis.ticks.length.y = unit(-0.25,"cm"), axis.ticks.x=element_blank())+
        scale_y_continuous(limits = c(-0.0003,y_max)) +
        scale_x_discrete(breaks=data$grouping) +
    
        geom_segment(aes(x = 0.66, y = 0.7, xend = 1.12, yend = 0.7), color = "turquoise2",size=2)+
        geom_segment(aes(x = 0.66, y = 0.7, xend = 0.66, yend = 0.64), color = "turquoise2",size=2)+
        geom_segment(aes(x = 1.12, y = 0.7, xend = 1.12, yend = 0.64), color = "turquoise2",size=2)+
    
        geom_segment(aes(x = 0.66, y = 0.83, xend = 1.33, yend = 0.83), color = "turquoise2",size=2)+
        geom_segment(aes(x = 0.66, y = 0.83, xend = 0.66, yend = 0.64), color = "turquoise2",size=2)+
        geom_segment(aes(x = 1.33, y = 0.83, xend = 1.33, yend = 0.64), color = "turquoise2",size=2)+
    
        geom_segment(aes(x = 1.66, y = 0.7, xend = 1.99, yend = 0.7), color = "pink2",size=2)+
        geom_segment(aes(x = 1.66, y = 0.7, xend = 1.66, yend = 0.64), color = "pink2",size=2)+
        geom_segment(aes(x = 1.99, y = 0.7, xend = 1.99, yend = 0.64), color = "pink2",size=2)+
    
        geom_segment(aes(x = 2.01, y = 0.7, xend = 2.33, yend = 0.7), color = "pink2",size=2)+
        geom_segment(aes(x = 2.01, y = 0.7, xend = 2.01, yend = 0.64), color = "pink2",size=2)+
        geom_segment(aes(x = 2.33, y = 0.7, xend = 2.33, yend = 0.64), color = "pink2",size=2)+
    
        geom_segment(aes(x = 3.33, y = 0.7, xend = 2.88, yend = 0.7), color = "orange2",size=2)+
        geom_segment(aes(x = 3.33, y = 0.7, xend = 3.33, yend = 0.64), color = "orange2",size=2)+
        geom_segment(aes(x = 2.88, y = 0.7, xend = 2.88, yend = 0.64), color = "orange2",size=2)+
    
        geom_segment(aes(x = 2.66, y = 0.83, xend = 3.33, yend = 0.83), color = "orange2",size=2)+
        geom_segment(aes(x = 2.66, y = 0.83, xend = 2.66, yend = 0.64), color = "orange2",size=2)+
        geom_segment(aes(x = 3.33, y = 0.83, xend = 3.33, yend = 0.64), color = "orange2",size=2)+
    
        annotate("text",x=3.115,y=0.755,label = paste0(formatC(tests$estimates[6],digits=3,format='f'), "\n(",formatC(tests$std.err[6],digits=4,format='f'),")"),size=12) +  
        annotate("text",x=3,y=0.885,label =     paste0(formatC(tests$estimates[5],digits=3,format='f'), "\n(",formatC(tests$std.err[5],digits=4,format='f'),")"),size=12) +
        annotate("text",x=2.17,y=0.755,label =  paste0(formatC(tests$estimates[4],digits=3,format='f'), "\n(",formatC(tests$std.err[4],digits=4,format='f'),")"),size=12) +
        annotate("text",x=1.83,y=0.755,label =  paste0(formatC(tests$estimates[3],digits=3,format='f'), "\n(",formatC(tests$std.err[3],digits=4,format='f'),")"),size=12) +
        annotate("text",x=1,y=0.885,label =     paste0(formatC(tests$estimates[2],digits=3,format='f'), "\n(",formatC(tests$std.err[2],digits=4,format='f'),")"),size=12) +
        annotate("text",x=0.885,y=0.755,label = paste0(formatC(tests$estimates[1],digits=3,format='f'), "\n(",formatC(tests$std.err[1],digits=4,format='f'),")"),size=12) +
       
        ggtitle(title) +

        theme(plot.title = element_text(face='bold', size=50, hjust=0.5, vjust=0.5))
    
        if (baseline){
        
        pic = pic + geom_text(aes(group=W,label=formatC(mean,digits=3,format="f"),y=mean+2*sd), position = position_dodge(0.72),vjust = -2.5,size=num_size)+
        geom_text(aes(group=W,label=paste("(",formatC(sd,digits=4,format='f'),")",sep=""),y=mean+2*sd), position = position_dodge(0.72),vjust = -1,size=num_size-1)}
    
        if (!baseline){
            
        pic = pic + geom_text(aes(group=W,label=as.character(formatC(mean,digits=3,format="f")),y=mean+2*sd), position = position_dodge(0.72),vjust = -1,size=num_size)    
        }
pic}
# Pre-allocate dataframe #
figure_5_data = data.frame(matrix(NA,9,3))
colnames(figure_5_data) = c("mean","sd","base_perc")

# Fill means and standard errors #
figure_5_data[1:3,1] = aggregate(share_post~treatment,course_tests_data_by_type_final[course_tests_data_by_type_final$type_post=="Reasoning posts" &
                                                                 course_tests_data_by_type_final$treatment %in% c("Reasoning","Emotions","Combo"),],mean)[,2]
figure_5_data[4:6,1] = aggregate(share_post~treatment,course_tests_data_by_type_final[course_tests_data_by_type_final$type_post=="Emotions posts" &
                                                                 course_tests_data_by_type_final$treatment %in% c("Reasoning","Emotions","Combo"),],mean)[,2]
figure_5_data[7:9,1] = aggregate(share_post~treatment,course_tests_data_by_type_final[course_tests_data_by_type_final$type_post =="Combo posts" &
                                                                 course_tests_data_by_type_final$treatment %in% c("Reasoning","Emotions","Combo"),],mean)[,2]

figure_5_data[1:3,2] = aggregate(share_post~treatment,course_tests_data_by_type_final[course_tests_data_by_type_final$type_post=="Reasoning posts" &
                                                                 course_tests_data_by_type_final$treatment %in% c("Reasoning","Emotions","Combo"),],se_binary)[,2]
figure_5_data[4:6,2] = aggregate(share_post~treatment,course_tests_data_by_type_final[course_tests_data_by_type_final$type_post=="Emotions posts" &
                                                                 course_tests_data_by_type_final$treatment %in% c("Reasoning","Emotions","Combo"),],se_binary)[,2]
figure_5_data[7:9,2] = aggregate(share_post~treatment,course_tests_data_by_type_final[course_tests_data_by_type_final$type_post =="Combo posts" &
                                                                 course_tests_data_by_type_final$treatment %in% c("Reasoning","Emotions","Combo"),],se_binary)[,2]
# Add grouping variables #
figure_5_data$W = factor(rep(c("Reasoning","Emotions","Combo"),3),levels = c("Reasoning","Emotions","Combo"))
figure_5_data$grouping = factor(rep(c("Reasoning posts","Emotions posts","Combo posts"),each=3),levels = c("Reasoning posts","Emotions posts","Combo posts"))

# Extract relevant treatment effect estimates #
tests_figure_5 = data.frame(matrix(NA),6,2)
tests_figure_5 = main_tests$tests[c("Test 13","Test 14","Test 16","Test 17","Test 19","Test 20"),c("estimates","std.err")]
figure_5 = plot_gen_side_by_side(figure_5_data,c("turquoise2","pink2","orange2"),"Sharing Rate",
                                 "Post type",1,"",12,TRUE,tests_figure_5)
figure_5

ggsave("figures/misinfo_sharing_by_assignment_group.png", plot = figure_5, width = 30, height = 15)

Panel Regression Table

panel_2 <- readRDS("regression_analysis_long/data/panel_2.rds")
cov_estimates_list <- readRDS("regression_analysis_long/data/cov_estimates_list.rds")

panel <- readRDS("regression_analysis_long/data/panel.rds")
# cov_estimates_list_all <- readRDS("regression_analysis_long/data/cov_estimates_list_all.rds")
# cov_roose_all_list <- readRDS("regression_analysis_long/data/cov_roose_all_list.rds")
# models_cov <- list('cov1_lm','cov2_lm','cov3_lm','cov4_lm','cov5_lm','cov6_lm')
# models_cov <- lapply(1:length(models_cov), 
#                      function(x) readRDS(paste0("regression_analysis_long/R2_outofsample/R2oos_cov_2treat_",x, "_5.rds")))
# 
R2oos_cov_alltreat_all <- c("", "", "", "", "", "")
R2oos_cov_2treat_all <- c("", "", "", "", "", "")
covariate_list <- c(demographics_demeaned_treatment,
                    sharing_demeaned_treatment,
                    sharing_tactic_demeaned_treatment,
                    demographics_sharing_demeaned_treatment,
                    all_covariates_demeaned_treatment)

panel_3 <- panel %>% filter(treatment %in% c("Reasoning","Facts Baseline"))
panel_3$treatment <- factor(panel_3$treatment, levels = c('Facts Baseline','Reasoning'))

panel_4 <- panel %>% filter(treatment %in% c("Combo","Facts Baseline"))
panel_4$treatment <- factor(panel_4$treatment, levels = c('Facts Baseline','Combo'))

panel_5 <- panel %>% filter(treatment %in% c("No-course Baseline","Facts Baseline"))
panel_5$treatment <- factor(panel_5$treatment, levels = c('Facts Baseline','No-course Baseline'))
cov_estimates_list_reasoning <- list()
for (cov_list in covariate_list) {

# Demographics
formula_cov1_lm <- paste0("share ~ treatment*post*post_is_misinfo "," + ",cov_list)
cov1_lm <- feols(as.formula(formula_cov1_lm),panel_3)

formula_cov2_lm <- paste0("share ~ treatment*post*post_is_misinfo "," + ",cov_list," | user")
cov2_lm <- feols(as.formula(formula_cov2_lm),panel_3)

# Misinfo and Non-misinfo sharing rates
formula_cov3_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(fact) "," + ",cov_list," | user")
cov3_lm <- feols(as.formula(formula_cov3_lm),panel_3)

# Misinfo, Non-misinfo, and Tactic sharing rates
formula_cov4_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(type) "," + ",cov_list," | user")
cov4_lm <- feols(as.formula(formula_cov4_lm),panel_3)

# Demographics and Misinfo and Non-misinfo sharing rates
formula_cov5_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(fact)*factor(type) "," + ",cov_list," | user")
cov5_lm <- feols(as.formula(formula_cov5_lm),panel_3)

# Demographics, Misinfo and Non-misinfo sharing rates, and Tactic sharing rates
formula_cov6_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(post_id) "," + ",cov_list," | user")
cov6_lm <- feols(as.formula(formula_cov6_lm),panel_3)

cov_estimates_list_reasoning[[length(cov_estimates_list_reasoning) + 1]] <- list(cov1_lm,cov2_lm,cov3_lm,cov4_lm,cov5_lm,cov6_lm)
}
cov_estimates_list_combo <- list()

for (cov_list in covariate_list) {

# Demographics
formula_cov1_lm <- paste0("share ~ treatment*post*post_is_misinfo "," + ",cov_list)
cov1_lm <- feols(as.formula(formula_cov1_lm),panel_4)

formula_cov2_lm <- paste0("share ~ treatment*post*post_is_misinfo "," + ",cov_list," | user")
cov2_lm <- feols(as.formula(formula_cov2_lm),panel_4)

# Misinfo and Non-misinfo sharing rates
formula_cov3_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(fact) "," + ",cov_list," | user")
cov3_lm <- feols(as.formula(formula_cov3_lm),panel_4)

# Misinfo, Non-misinfo, and Tactic sharing rates
formula_cov4_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(type) "," + ",cov_list," | user")
cov4_lm <- feols(as.formula(formula_cov4_lm),panel_4)

# Demographics and Misinfo and Non-misinfo sharing rates
formula_cov5_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(fact)*factor(type) "," + ",cov_list," | user")
cov5_lm <- feols(as.formula(formula_cov5_lm),panel_4)

# Demographics, Misinfo and Non-misinfo sharing rates, and Tactic sharing rates
formula_cov6_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(post_id) "," + ",cov_list," | user")
cov6_lm <- feols(as.formula(formula_cov6_lm),panel_4)

cov_estimates_list_combo[[length(cov_estimates_list_combo) + 1]] <- list(cov1_lm,cov2_lm,cov3_lm,cov4_lm,cov5_lm,cov6_lm)
}
cov_estimates_list_nocourse <- list()

for (cov_list in covariate_list) {

# Demographics
formula_cov1_lm <- paste0("share ~ treatment*post*post_is_misinfo "," + ",cov_list)
cov1_lm <- feols(as.formula(formula_cov1_lm),panel_5)

formula_cov2_lm <- paste0("share ~ treatment*post*post_is_misinfo "," + ",cov_list," | user")
cov2_lm <- feols(as.formula(formula_cov2_lm),panel_5)

# Misinfo and Non-misinfo sharing rates
formula_cov3_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(fact) "," + ",cov_list," | user")
cov3_lm <- feols(as.formula(formula_cov3_lm),panel_5)

# Misinfo, Non-misinfo, and Tactic sharing rates
formula_cov4_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(type) "," + ",cov_list," | user")
cov4_lm <- feols(as.formula(formula_cov4_lm),panel_5)

# Demographics and Misinfo and Non-misinfo sharing rates
formula_cov5_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(fact)*factor(type) "," + ",cov_list," | user")
cov5_lm <- feols(as.formula(formula_cov5_lm),panel_5)

# Demographics, Misinfo and Non-misinfo sharing rates, and Tactic sharing rates
formula_cov6_lm <- paste0("share ~ treatment*post*post_is_misinfo + factor(post_id) "," + ",cov_list," | user")
cov6_lm <- feols(as.formula(formula_cov6_lm),panel_5)

cov_estimates_list_nocourse[[length(cov_estimates_list_nocourse) + 1]] <- list(cov1_lm,cov2_lm,cov3_lm,cov4_lm,cov5_lm,cov6_lm)
}
cov <- 5

# Print model
headers <- c("Share (binary indicator)")
model_list <- cov_estimates_list[[cov]]
names <- unique(c(names(cov_estimates_list[[cov]][[1]]$coefficients),
                  names(cov_estimates_list[[cov]][[2]]$coefficients),
                  names(cov_estimates_list[[cov]][[3]]$coefficients),
                  names(cov_estimates_list[[cov]][[4]]$coefficients),
                  names(cov_estimates_list[[cov]][[5]]$coefficients),
                  names(cov_estimates_list[[cov]][[6]]$coefficients)))
variable_labels_wide <- variable_mapping_long[names]
# remova NA
variable_labels_wide <- variable_labels_wide[!is.na(variable_labels_wide)]

# remove blankrows
coef_names <- names
matrix_coeff_na <- expand.grid(coef_name = coef_names, model = seq(length(model_list)))
matrix_coeff_na$var <- 0
matrix_coeff_na$var_na <- 0
for (m in 1:length(model_list)) {
  na_coeff <- names(model_list[[m]]$coefficients)[is.na(model_list[[m]]$coefficients)]
  for (c in na_coeff) {
    matrix_coeff_na$var[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1 # 1 if variable is in the model (not all models have all variables)
    matrix_coeff_na$var_na[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1
  }
}
matrix_coeff_na <- matrix_coeff_na %>% group_by(coef_name) %>% mutate(var = sum(var), var_na = sum(var_na)) %>% distinct(coef_name,var,var_na)
rows_to_omit <- as.vector(unique(matrix_coeff_na$coef_name[matrix_coeff_na$var_na != 0])) # omit if NA in all models
rows_to_omit <- gsub("\\^\\s","^",paste0("^",rows_to_omit,"$", collapse = "|"))
rows_to_omit <- gsub("\\(","\\\\(",gsub("\\)","\\\\)",rows_to_omit))

# keep variables
# keep <- c("treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
#              "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
#              "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]")

keep <- list(
             #  "treatmentReasoning:post:post_is_misinfo" = "Reasoning x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentReasoning:post" = "Reasoning x 1[Post-treatment]",
             # "treatmentReasoning:post_is_misinfo" = "Reasoning x 1[Misinfo]",
              "treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
             "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
             "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]"
             
             # "treatmentCombo:post:post_is_misinfo" = "Combo x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentCombo:post" = "Combo x 1[Post-treatment]",
             # "treatmentCombo:post_is_misinfo" = "Combo x 1[Misinfo]",
             )

custom.gof.rows <- list("Fixed Effect" = function(x) {
  if (sum(grepl("post_id", formula(x)[[3]]))> 0) return ("Post ID")
  if (sum(grepl("fact", formula(x)[[3]]) & grepl("type", formula(x)[[3]]))> 0) return ("Domain x Tactic")
  if (sum(grepl("fact", formula(x)[[3]]))> 0) return ("Domain")
  if (sum(grepl("type", formula(x)[[3]]))> 0) return ("Tactic")
  return ("")
})

Emotions

etable(model_list, 
       title = paste("Linear Regression:", headers, 
                     "vs. Treatment for different set of fixed effects\n<br>Covariates: Demographics + Sharing rates"),
       dict = variable_labels_wide,
       headers = c("Baseline<br>(1)",
                            "User ID FE<br>(2)",
                            "User ID FE +<br>Post domain FE<br>(3)",
                            "User ID FE +<br>Post tactic FE<br>(4)",
                            "User ID FE +<br>Post domain x Post tactic<br>(5)",
                            "User ID FE +<br>Post ID FE<br>(6)"),
       keep = paste0("%", names(keep)),
       signif.code = c("***" = 0.02, "**" = 0.1, "*" = 0.2),
       notes = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
       extralines = list("Fixed Effect" = c("", "", "Domain", "Tactic", "Domain x Tactic", "Post ID")),
       digits = 4,tex = F)
##                                                       model 1
##                                               Baseline<br>(1)
## Dependent Var.:                                         share
##                                                              
## Emotions x 1[Post-treatment]              -0.0938*** (0.0115)
## Emotions x 1[Misinfo]                        -0.0039 (0.0100)
## Emotions x 1[Post-treatment] x 1[Misinfo]   -0.0202* (0.0141)
## Fixed Effect                                                 
## Fixed-Effects:                            -------------------
## user                                                       No
## ________________________________________  ___________________
## S.E. type                                                 IID
## Observations                                           65,268
## R2                                                    0.27443
## Within R2                                                  --
## 
##                                                       model 2
##                                             User ID FE<br>(2)
## Dependent Var.:                                         share
##                                                              
## Emotions x 1[Post-treatment]              -0.0938*** (0.0132)
## Emotions x 1[Misinfo]                        -0.0039 (0.0100)
## Emotions x 1[Post-treatment] x 1[Misinfo]   -0.0202* (0.0136)
## Fixed Effect                                                 
## Fixed-Effects:                            -------------------
## user                                                      Yes
## ________________________________________  ___________________
## S.E. type                                            by: user
## Observations                                           65,268
## R2                                                    0.34226
## Within R2                                             0.05688
## 
##                                                                         model 3
##                                           User ID FE +<br>Post domain FE<br>(3)
## Dependent Var.:                                                           share
##                                                                                
## Emotions x 1[Post-treatment]                                -0.0948*** (0.0129)
## Emotions x 1[Misinfo]                                          -0.0015 (0.0097)
## Emotions x 1[Post-treatment] x 1[Misinfo]                    -0.0221** (0.0129)
## Fixed Effect                                                             Domain
## Fixed-Effects:                                              -------------------
## user                                                                        Yes
## ________________________________________                    ___________________
## S.E. type                                                              by: user
## Observations                                                             65,268
## R2                                                                      0.39387
## Within R2                                                               0.13089
## 
##                                                                         model 4
##                                           User ID FE +<br>Post tactic FE<br>(4)
## Dependent Var.:                                                           share
##                                                                                
## Emotions x 1[Post-treatment]                                -0.0938*** (0.0132)
## Emotions x 1[Misinfo]                                          -0.0039 (0.0100)
## Emotions x 1[Post-treatment] x 1[Misinfo]                     -0.0202* (0.0136)
## Fixed Effect                                                             Tactic
## Fixed-Effects:                                              -------------------
## user                                                                        Yes
## ________________________________________                    ___________________
## S.E. type                                                              by: user
## Observations                                                             65,268
## R2                                                                      0.34309
## Within R2                                                               0.05808
## 
##                                                                                    model 5
##                                           User ID FE +<br>Post domain x Post tactic<br>(5)
## Dependent Var.:                                                                      share
##                                                                                           
## Emotions x 1[Post-treatment]                                           -0.0956*** (0.0128)
## Emotions x 1[Misinfo]                                                     -0.0024 (0.0096)
## Emotions x 1[Post-treatment] x 1[Misinfo]                               -0.0246** (0.0127)
## Fixed Effect                                                               Domain x Tactic
## Fixed-Effects:                                                         -------------------
## user                                                                                   Yes
## ________________________________________                               ___________________
## S.E. type                                                                         by: user
## Observations                                                                        65,268
## R2                                                                                 0.41539
## Within R2                                                                          0.16175
## 
##                                                                     model 6
##                                           User ID FE +<br>Post ID FE<br>(6)
## Dependent Var.:                                                       share
##                                                                            
## Emotions x 1[Post-treatment]                            -0.0956*** (0.0128)
## Emotions x 1[Misinfo]                                      -0.0024 (0.0096)
## Emotions x 1[Post-treatment] x 1[Misinfo]                -0.0246** (0.0127)
## Fixed Effect                                                        Post ID
## Fixed-Effects:                                          -------------------
## user                                                                    Yes
## ________________________________________                ___________________
## S.E. type                                                          by: user
## Observations                                                         65,268
## R2                                                                  0.41539
## Within R2                                                           0.16175
## ---
## Signif. codes: 0 '***' 0.02 '**' 0.1 '*' 0.2 ' ' 1
texreg::texreg(model_list,
                      custom.header = list("Share (binary indicator)" = 1:length(model_list)),
                      custom.model.names = c("\\makecell{Baseline \\\\ (1)}",
                                             "\\makecell{User ID FE \\\\ (2)}",
                                             "\\makecell{User ID FE + \\\\ Post domain FE \\\\ (3)}",
                                             "\\makecell{User ID FE + \\\\ Post tactic FE \\\\ (4)}",
                                             "\\makecell{User ID FE + \\\\ Post domain x Post tactic \\\\ (5)}",
                                             "\\makecell{User ID FE + \\\\ Post ID FE \\\\ (6)}"),
                      stars = c(0.20, 0.10, 0.02),
                      custom.note = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
                      caption = paste("Linear Regression:", headers, "vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]"),
                      caption.above = TRUE,
                      doctype = FALSE,
                      html.tag = FALSE,
                      table.tag = FALSE,
                      single.row = FALSE,
                      include.groups = FALSE,
                      digits = 4,
                      custom.coef.names = variable_labels_wide,
                      custom.coef.map = keep,
                      custom.gof.rows = list("Fixed Effects" = c("",rep("user",length(model_list)-1)),
                                             "Fixed Effects" = c("","","Domain","Tactic","Domain x Tactic","Post ID"),
                                             "Covariates" = c("",rep("Demographics + Sharing rates",length(model_list)-1)),
                                             "Clustered Std. Errors" = rep("user",length(model_list)),
                                             "Out-of-sample R^2" = c(R2oos_cov_2treat_all)),
                      reorder.gof = c(6,7,8,9,10,5,1,2,3,4))
## 
## \begin{table}
## \caption{Linear Regression: Share (binary indicator) vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]}
## \begin{center}
## \begin{tabular}{l c c c c c c}
## \hline
##  & \multicolumn{6}{c}{Share (binary indicator)} \\
## \cline{2-7}
##  & \makecell{Baseline \\ (1)} & \makecell{User ID FE \\ (2)} & \makecell{User ID FE + \\ Post domain FE \\ (3)} & \makecell{User ID FE + \\ Post tactic FE \\ (4)} & \makecell{User ID FE + \\ Post domain x Post tactic \\ (5)} & \makecell{User ID FE + \\ Post ID FE \\ (6)} \\
## \hline
## Emotions x 1[Post-treatment] x 1[Misinfo] & $-0.0202^{*}$   & $-0.0202^{*}$                & $-0.0221^{**}$               & $-0.0202^{*}$                & $-0.0246^{**}$               & $-0.0246^{**}$               \\
##                                           & $(0.0141)$      & $(0.0136)$                   & $(0.0129)$                   & $(0.0136)$                   & $(0.0127)$                   & $(0.0127)$                   \\
## Emotions x 1[Post-treatment]              & $-0.0938^{***}$ & $-0.0938^{***}$              & $-0.0948^{***}$              & $-0.0938^{***}$              & $-0.0956^{***}$              & $-0.0956^{***}$              \\
##                                           & $(0.0115)$      & $(0.0132)$                   & $(0.0129)$                   & $(0.0132)$                   & $(0.0128)$                   & $(0.0128)$                   \\
## Emotions x 1[Misinfo]                     & $-0.0039$       & $-0.0039$                    & $-0.0015$                    & $-0.0039$                    & $-0.0024$                    & $-0.0024$                    \\
##                                           & $(0.0100)$      & $(0.0100)$                   & $(0.0097)$                   & $(0.0100)$                   & $(0.0096)$                   & $(0.0096)$                   \\
## \hline
## Num. obs.                                 & $65268$         & $65268$                      & $65268$                      & $65268$                      & $65268$                      & $65268$                      \\
## R$^2$ (full model)                        & $0.2744$        & $0.3423$                     & $0.3939$                     & $0.3431$                     & $0.4154$                     & $0.4154$                     \\
## R$^2$ (proj model)                        & $$              & $0.0569$                     & $0.1309$                     & $0.0581$                     & $0.1618$                     & $0.1618$                     \\
## Adj. R$^2$ (full model)                   & $0.2738$        & $0.3035$                     & $0.3580$                     & $0.3044$                     & $0.3804$                     & $0.3804$                     \\
## Adj. R$^2$ (proj model)                   & $$              & $0.0568$                     & $0.1306$                     & $0.0579$                     & $0.1609$                     & $0.1609$                     \\
## Out-of-sample R$^2$                       &                 &                              &                              &                              &                              &                              \\
## Fixed Effects                             &                 & user                         & user                         & user                         & user                         & user                         \\
## Fixed Effects                             &                 &                              & Domain                       & Tactic                       & Domain x Tactic              & Post ID                      \\
## Covariates                                &                 & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates \\
## Clustered Std. Errors                     & user            & user                         & user                         & user                         & user                         & user                         \\
## \hline
## \multicolumn{7}{l}{\scriptsize{Significance levels: \*p<0.10, \*\*p<0.05, \*\*\*p<0.01 one-sided test.}}
## \end{tabular}
## \label{table:coefficients}
## \end{center}
## \end{table}

Reasoning

cov <- 5

# Print model
headers <- c("Share (binary indicator)")
model_list <- cov_estimates_list_reasoning[[cov]]
names <- unique(c(names(cov_estimates_list_reasoning[[cov]][[1]]$coefficients),
                  names(cov_estimates_list_reasoning[[cov]][[2]]$coefficients),
                  names(cov_estimates_list_reasoning[[cov]][[3]]$coefficients),
                  names(cov_estimates_list_reasoning[[cov]][[4]]$coefficients),
                  names(cov_estimates_list_reasoning[[cov]][[5]]$coefficients),
                  names(cov_estimates_list_reasoning[[cov]][[6]]$coefficients)))
variable_labels_wide <- variable_mapping_long[names]
# remova NA
variable_labels_wide <- variable_labels_wide[!is.na(variable_labels_wide)]

# remove blankrows
coef_names <- names
matrix_coeff_na <- expand.grid(coef_name = coef_names, model = seq(length(model_list)))
matrix_coeff_na$var <- 0
matrix_coeff_na$var_na <- 0
for (m in 1:length(model_list)) {
  na_coeff <- names(model_list[[m]]$coefficients)[is.na(model_list[[m]]$coefficients)]
  for (c in na_coeff) {
    matrix_coeff_na$var[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1 # 1 if variable is in the model (not all models have all variables)
    matrix_coeff_na$var_na[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1
  }
}
matrix_coeff_na <- matrix_coeff_na %>% group_by(coef_name) %>% mutate(var = sum(var), var_na = sum(var_na)) %>% distinct(coef_name,var,var_na)
rows_to_omit <- as.vector(unique(matrix_coeff_na$coef_name[matrix_coeff_na$var_na != 0])) # omit if NA in all models
rows_to_omit <- gsub("\\^\\s","^",paste0("^",rows_to_omit,"$", collapse = "|"))
rows_to_omit <- gsub("\\(","\\\\(",gsub("\\)","\\\\)",rows_to_omit))

# keep variables
# keep <- c("treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
#              "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
#              "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]")

keep <- list(
              "treatmentReasoning:post:post_is_misinfo" = "Reasoning x 1[Post-treatment] x 1[Misinfo]",
             "treatmentReasoning:post" = "Reasoning x 1[Post-treatment]",
             "treatmentReasoning:post_is_misinfo" = "Reasoning x 1[Misinfo]"
             #  "treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
             # "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]"
             # 
             # "treatmentCombo:post:post_is_misinfo" = "Combo x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentCombo:post" = "Combo x 1[Post-treatment]",
             # "treatmentCombo:post_is_misinfo" = "Combo x 1[Misinfo]",
             )

custom.gof.rows <- list("Fixed Effect" = function(x) {
  if (sum(grepl("post_id", formula(x)[[3]]))> 0) return ("Post ID")
  if (sum(grepl("fact", formula(x)[[3]]) & grepl("type", formula(x)[[3]]))> 0) return ("Domain x Tactic")
  if (sum(grepl("fact", formula(x)[[3]]))> 0) return ("Domain")
  if (sum(grepl("type", formula(x)[[3]]))> 0) return ("Tactic")
  return ("")
})
texreg::texreg(model_list,
                      custom.header = list("Share (binary indicator)" = 1:length(model_list)),
                      custom.model.names = c("\\makecell{Baseline \\\\ (1)}",
                                             "\\makecell{User ID FE \\\\ (2)}",
                                             "\\makecell{User ID FE + \\\\ Post domain FE \\\\ (3)}",
                                             "\\makecell{User ID FE + \\\\ Post tactic FE \\\\ (4)}",
                                             "\\makecell{User ID FE + \\\\ Post domain x Post tactic \\\\ (5)}",
                                             "\\makecell{User ID FE + \\\\ Post ID FE \\\\ (6)}"),
                      stars = c(0.20, 0.10, 0.02),
                      custom.note = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
                      caption = paste("Linear Regression:", headers, "vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]"),
                      caption.above = TRUE,
                      doctype = FALSE,
                      html.tag = FALSE,
                      table.tag = FALSE,
                      single.row = FALSE,
                      include.groups = FALSE,
                      digits = 4,
                      custom.coef.names = variable_labels_wide,
                      custom.coef.map = keep,
                      custom.gof.rows = list("Fixed Effects" = c("",rep("user",length(model_list)-1)),
                                             "Fixed Effects" = c("","","Domain","Tactic","Domain x Tactic","Post ID"),
                                             "Covariates" = c("",rep("Demographics + Sharing rates",length(model_list)-1)),
                                             "Clustered Std. Errors" = rep("user",length(model_list)),
                                             "Out-of-sample R^2" = c(R2oos_cov_2treat_all)),
                      reorder.gof = c(6,7,8,9,10,5,1,2,3,4))
## 
## \begin{table}
## \caption{Linear Regression: Share (binary indicator) vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]}
## \begin{center}
## \begin{tabular}{l c c c c c c}
## \hline
##  & \multicolumn{6}{c}{Share (binary indicator)} \\
## \cline{2-7}
##  & \makecell{Baseline \\ (1)} & \makecell{User ID FE \\ (2)} & \makecell{User ID FE + \\ Post domain FE \\ (3)} & \makecell{User ID FE + \\ Post tactic FE \\ (4)} & \makecell{User ID FE + \\ Post domain x Post tactic \\ (5)} & \makecell{User ID FE + \\ Post ID FE \\ (6)} \\
## \hline
## Reasoning x 1[Post-treatment] x 1[Misinfo] & $0.0154$        & $0.0154$                     & $0.0130$                     & $0.0154$                     & $0.0109$                     & $0.0109$                     \\
##                                            & $(0.0143)$      & $(0.0139)$                   & $(0.0132)$                   & $(0.0139)$                   & $(0.0130)$                   & $(0.0130)$                   \\
## Reasoning x 1[Post-treatment]              & $-0.0777^{***}$ & $-0.0777^{***}$              & $-0.0786^{***}$              & $-0.0777^{***}$              & $-0.0785^{***}$              & $-0.0785^{***}$              \\
##                                            & $(0.0117)$      & $(0.0130)$                   & $(0.0128)$                   & $(0.0130)$                   & $(0.0127)$                   & $(0.0127)$                   \\
## Reasoning x 1[Misinfo]                     & $-0.0196^{**}$  & $-0.0196^{**}$               & $-0.0143^{*}$                & $-0.0196^{**}$               & $-0.0152^{*}$                & $-0.0152^{*}$                \\
##                                            & $(0.0101)$      & $(0.0101)$                   & $(0.0097)$                   & $(0.0101)$                   & $(0.0096)$                   & $(0.0096)$                   \\
## \hline
## Num. obs.                                  & $62640$         & $62640$                      & $62640$                      & $62640$                      & $62640$                      & $62640$                      \\
## R$^2$ (full model)                         & $0.2820$        & $0.3481$                     & $0.3995$                     & $0.3486$                     & $0.4198$                     & $0.4198$                     \\
## R$^2$ (proj model)                         & $$              & $0.0476$                     & $0.1227$                     & $0.0484$                     & $0.1524$                     & $0.1524$                     \\
## Adj. R$^2$ (full model)                    & $0.2814$        & $0.3097$                     & $0.3639$                     & $0.3102$                     & $0.3850$                     & $0.3850$                     \\
## Adj. R$^2$ (proj model)                    & $$              & $0.0475$                     & $0.1224$                     & $0.0482$                     & $0.1515$                     & $0.1515$                     \\
## Out-of-sample R$^2$                        &                 &                              &                              &                              &                              &                              \\
## Fixed Effects                              &                 & user                         & user                         & user                         & user                         & user                         \\
## Fixed Effects                              &                 &                              & Domain                       & Tactic                       & Domain x Tactic              & Post ID                      \\
## Covariates                                 &                 & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates \\
## Clustered Std. Errors                      & user            & user                         & user                         & user                         & user                         & user                         \\
## \hline
## \multicolumn{7}{l}{\scriptsize{Significance levels: \*p<0.10, \*\*p<0.05, \*\*\*p<0.01 one-sided test.}}
## \end{tabular}
## \label{table:coefficients}
## \end{center}
## \end{table}

Combo

cov <- 5

# Print model
headers <- c("Share (binary indicator)")
model_list <- cov_estimates_list_combo[[cov]]
names <- unique(c(names(cov_estimates_list_combo[[cov]][[1]]$coefficients),
                  names(cov_estimates_list_combo[[cov]][[2]]$coefficients),
                  names(cov_estimates_list_combo[[cov]][[3]]$coefficients),
                  names(cov_estimates_list_combo[[cov]][[4]]$coefficients),
                  names(cov_estimates_list_combo[[cov]][[5]]$coefficients),
                  names(cov_estimates_list_combo[[cov]][[6]]$coefficients)))
variable_labels_wide <- variable_mapping_long[names]
# remova NA
variable_labels_wide <- variable_labels_wide[!is.na(variable_labels_wide)]

# remove blankrows
coef_names <- names
matrix_coeff_na <- expand.grid(coef_name = coef_names, model = seq(length(model_list)))
matrix_coeff_na$var <- 0
matrix_coeff_na$var_na <- 0
for (m in 1:length(model_list)) {
  na_coeff <- names(model_list[[m]]$coefficients)[is.na(model_list[[m]]$coefficients)]
  for (c in na_coeff) {
    matrix_coeff_na$var[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1 # 1 if variable is in the model (not all models have all variables)
    matrix_coeff_na$var_na[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1
  }
}
matrix_coeff_na <- matrix_coeff_na %>% group_by(coef_name) %>% mutate(var = sum(var), var_na = sum(var_na)) %>% distinct(coef_name,var,var_na)
rows_to_omit <- as.vector(unique(matrix_coeff_na$coef_name[matrix_coeff_na$var_na != 0])) # omit if NA in all models
rows_to_omit <- gsub("\\^\\s","^",paste0("^",rows_to_omit,"$", collapse = "|"))
rows_to_omit <- gsub("\\(","\\\\(",gsub("\\)","\\\\)",rows_to_omit))

# keep variables
# keep <- c("treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
#              "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
#              "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]")

keep <- list(
             #  "treatmentReasoning:post:post_is_misinfo" = "Reasoning x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentReasoning:post" = "Reasoning x 1[Post-treatment]",
             # "treatmentReasoning:post_is_misinfo" = "Reasoning x 1[Misinfo]"
             #  "treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
             # "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]"
             # 
             "treatmentCombo:post:post_is_misinfo" = "Combo x 1[Post-treatment] x 1[Misinfo]",
             "treatmentCombo:post" = "Combo x 1[Post-treatment]",
             "treatmentCombo:post_is_misinfo" = "Combo x 1[Misinfo]"
             )

custom.gof.rows <- list("Fixed Effect" = function(x) {
  if (sum(grepl("post_id", formula(x)[[3]]))> 0) return ("Post ID")
  if (sum(grepl("fact", formula(x)[[3]]) & grepl("type", formula(x)[[3]]))> 0) return ("Domain x Tactic")
  if (sum(grepl("fact", formula(x)[[3]]))> 0) return ("Domain")
  if (sum(grepl("type", formula(x)[[3]]))> 0) return ("Tactic")
  return ("")
})
texreg::texreg(model_list,
                      custom.header = list("Share (binary indicator)" = 1:length(model_list)),
                      custom.model.names = c("\\makecell{Baseline \\\\ (1)}",
                                             "\\makecell{User ID FE \\\\ (2)}",
                                             "\\makecell{User ID FE + \\\\ Post domain FE \\\\ (3)}",
                                             "\\makecell{User ID FE + \\\\ Post tactic FE \\\\ (4)}",
                                             "\\makecell{User ID FE + \\\\ Post domain x Post tactic \\\\ (5)}",
                                             "\\makecell{User ID FE + \\\\ Post ID FE \\\\ (6)}"),
                      stars = c(0.20, 0.10, 0.02),
                      custom.note = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
                      caption = paste("Linear Regression:", headers, "vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]"),
                      caption.above = TRUE,
                      doctype = FALSE,
                      html.tag = FALSE,
                      table.tag = FALSE,
                      single.row = FALSE,
                      include.groups = FALSE,
                      digits = 4,
                      custom.coef.names = variable_labels_wide,
                      custom.coef.map = keep,
                      custom.gof.rows = list("Fixed Effects" = c("",rep("user",length(model_list)-1)),
                                             "Fixed Effects" = c("","","Domain","Tactic","Domain x Tactic","Post ID"),
                                             "Covariates" = c("",rep("Demographics + Sharing rates",length(model_list)-1)),
                                             "Clustered Std. Errors" = rep("user",length(model_list)),
                                             "Out-of-sample R^2" = c(R2oos_cov_2treat_all)),
                      reorder.gof = c(6,7,8,9,10,5,1,2,3,4))
## 
## \begin{table}
## \caption{Linear Regression: Share (binary indicator) vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]}
## \begin{center}
## \begin{tabular}{l c c c c c c}
## \hline
##  & \multicolumn{6}{c}{Share (binary indicator)} \\
## \cline{2-7}
##  & \makecell{Baseline \\ (1)} & \makecell{User ID FE \\ (2)} & \makecell{User ID FE + \\ Post domain FE \\ (3)} & \makecell{User ID FE + \\ Post tactic FE \\ (4)} & \makecell{User ID FE + \\ Post domain x Post tactic \\ (5)} & \makecell{User ID FE + \\ Post ID FE \\ (6)} \\
## \hline
## Combo x 1[Post-treatment] x 1[Misinfo] & $-0.0127$       & $-0.0127$                    & $-0.0139$                    & $-0.0127$                    & $-0.0189^{*}$                & $-0.0189^{*}$                \\
##                                        & $(0.0142)$      & $(0.0138)$                   & $(0.0132)$                   & $(0.0138)$                   & $(0.0130)$                   & $(0.0130)$                   \\
## Combo x 1[Post-treatment]              & $-0.0884^{***}$ & $-0.0884^{***}$              & $-0.0883^{***}$              & $-0.0884^{***}$              & $-0.0885^{***}$              & $-0.0885^{***}$              \\
##                                        & $(0.0116)$      & $(0.0131)$                   & $(0.0128)$                   & $(0.0131)$                   & $(0.0127)$                   & $(0.0127)$                   \\
## Combo x 1[Misinfo]                     & $0.0040$        & $0.0040$                     & $0.0062$                     & $0.0040$                     & $0.0065$                     & $0.0065$                     \\
##                                        & $(0.0100)$      & $(0.0099)$                   & $(0.0097)$                   & $(0.0099)$                   & $(0.0096)$                   & $(0.0096)$                   \\
## \hline
## Num. obs.                              & $63540$         & $63540$                      & $63540$                      & $63540$                      & $63540$                      & $63540$                      \\
## R$^2$ (full model)                     & $0.2860$        & $0.3539$                     & $0.4019$                     & $0.3547$                     & $0.4216$                     & $0.4216$                     \\
## R$^2$ (proj model)                     & $$              & $0.0526$                     & $0.1229$                     & $0.0537$                     & $0.1519$                     & $0.1519$                     \\
## Adj. R$^2$ (full model)                & $0.2854$        & $0.3159$                     & $0.3665$                     & $0.3166$                     & $0.3870$                     & $0.3870$                     \\
## Adj. R$^2$ (proj model)                & $$              & $0.0525$                     & $0.1226$                     & $0.0536$                     & $0.1510$                     & $0.1510$                     \\
## Out-of-sample R$^2$                    &                 &                              &                              &                              &                              &                              \\
## Fixed Effects                          &                 & user                         & user                         & user                         & user                         & user                         \\
## Fixed Effects                          &                 &                              & Domain                       & Tactic                       & Domain x Tactic              & Post ID                      \\
## Covariates                             &                 & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates \\
## Clustered Std. Errors                  & user            & user                         & user                         & user                         & user                         & user                         \\
## \hline
## \multicolumn{7}{l}{\scriptsize{Significance levels: \*p<0.10, \*\*p<0.05, \*\*\*p<0.01 one-sided test.}}
## \end{tabular}
## \label{table:coefficients}
## \end{center}
## \end{table}

No-course

cov <- 5

# Print model
headers <- c("Share (binary indicator)")
model_list <- cov_estimates_list_nocourse[[cov]]
names <- unique(c(names(cov_estimates_list_nocourse[[cov]][[1]]$coefficients),
                  names(cov_estimates_list_nocourse[[cov]][[2]]$coefficients),
                  names(cov_estimates_list_nocourse[[cov]][[3]]$coefficients),
                  names(cov_estimates_list_nocourse[[cov]][[4]]$coefficients),
                  names(cov_estimates_list_nocourse[[cov]][[5]]$coefficients),
                  names(cov_estimates_list_nocourse[[cov]][[6]]$coefficients)))
variable_labels_wide <- variable_mapping_long[names]
# remova NA
variable_labels_wide <- variable_labels_wide[!is.na(variable_labels_wide)]

# remove blankrows
coef_names <- names
matrix_coeff_na <- expand.grid(coef_name = coef_names, model = seq(length(model_list)))
matrix_coeff_na$var <- 0
matrix_coeff_na$var_na <- 0
for (m in 1:length(model_list)) {
  na_coeff <- names(model_list[[m]]$coefficients)[is.na(model_list[[m]]$coefficients)]
  for (c in na_coeff) {
    matrix_coeff_na$var[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1 # 1 if variable is in the model (not all models have all variables)
    matrix_coeff_na$var_na[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1
  }
}
matrix_coeff_na <- matrix_coeff_na %>% group_by(coef_name) %>% mutate(var = sum(var), var_na = sum(var_na)) %>% distinct(coef_name,var,var_na)
rows_to_omit <- as.vector(unique(matrix_coeff_na$coef_name[matrix_coeff_na$var_na != 0])) # omit if NA in all models
rows_to_omit <- gsub("\\^\\s","^",paste0("^",rows_to_omit,"$", collapse = "|"))
rows_to_omit <- gsub("\\(","\\\\(",gsub("\\)","\\\\)",rows_to_omit))

# keep variables
# keep <- c("treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
#              "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
#              "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]")

keep <- list(
              "treatmentNo-course Baseline:post:post_is_misinfo" = "No-course Baseline x 1[Post-treatment] x 1[Misinfo]",
             "treatmentNo-course Baseline:post" = "No-course Baseline x 1[Post-treatment]",
             "treatmentNo-course Baseline:post_is_misinfo" = "No-course Baseline x 1[Misinfo]"
             #  "treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentEmotions:post" = "Emotions x 1[Post-treatment]",
             # "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]"
             # 
             # "treatmentCombo:post:post_is_misinfo" = "Combo x 1[Post-treatment] x 1[Misinfo]",
             # "treatmentCombo:post" = "Combo x 1[Post-treatment]",
             # "treatmentCombo:post_is_misinfo" = "Combo x 1[Misinfo]",
             )

custom.gof.rows <- list("Fixed Effect" = function(x) {
  if (sum(grepl("post_id", formula(x)[[3]]))> 0) return ("Post ID")
  if (sum(grepl("fact", formula(x)[[3]]) & grepl("type", formula(x)[[3]]))> 0) return ("Domain x Tactic")
  if (sum(grepl("fact", formula(x)[[3]]))> 0) return ("Domain")
  if (sum(grepl("type", formula(x)[[3]]))> 0) return ("Tactic")
  return ("")
})
texreg::texreg(model_list,
                      custom.header = list("Share (binary indicator)" = 1:length(model_list)),
                      custom.model.names = c("\\makecell{Baseline \\\\ (1)}",
                                             "\\makecell{User ID FE \\\\ (2)}",
                                             "\\makecell{User ID FE + \\\\ Post domain FE \\\\ (3)}",
                                             "\\makecell{User ID FE + \\\\ Post tactic FE \\\\ (4)}",
                                             "\\makecell{User ID FE + \\\\ Post domain x Post tactic \\\\ (5)}",
                                             "\\makecell{User ID FE + \\\\ Post ID FE \\\\ (6)}"),
                      stars = c(0.20, 0.10, 0.02),
                      custom.note = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
                      caption = paste("Linear Regression:", headers, "vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]"),
                      caption.above = TRUE,
                      doctype = FALSE,
                      html.tag = FALSE,
                      table.tag = FALSE,
                      single.row = FALSE,
                      include.groups = FALSE,
                      digits = 4,
                      custom.coef.names = variable_labels_wide,
                      custom.coef.map = keep,
                      custom.gof.rows = list("Fixed Effects" = c("",rep("user",length(model_list)-1)),
                                             "Fixed Effects" = c("","","Domain","Tactic","Domain x Tactic","Post ID"),
                                             "Covariates" = c("",rep("Demographics + Sharing rates",length(model_list)-1)),
                                             "Clustered Std. Errors" = rep("user",length(model_list)),
                                             "Out-of-sample R^2" = c(R2oos_cov_2treat_all)),
                      reorder.gof = c(6,7,8,9,10,5,1,2,3,4))
## 
## \begin{table}
## \caption{Linear Regression: Share (binary indicator) vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]}
## \begin{center}
## \begin{tabular}{l c c c c c c}
## \hline
##  & \multicolumn{6}{c}{Share (binary indicator)} \\
## \cline{2-7}
##  & \makecell{Baseline \\ (1)} & \makecell{User ID FE \\ (2)} & \makecell{User ID FE + \\ Post domain FE \\ (3)} & \makecell{User ID FE + \\ Post tactic FE \\ (4)} & \makecell{User ID FE + \\ Post domain x Post tactic \\ (5)} & \makecell{User ID FE + \\ Post ID FE \\ (6)} \\
## \hline
## No-course Baseline x 1[Post-treatment] x 1[Misinfo] & $0.0033$       & $0.0033$                     & $0.0049$                     & $0.0033$                     & $0.0042$                     & $0.0042$                     \\
##                                                     & $(0.0143)$     & $(0.0140)$                   & $(0.0133)$                   & $(0.0140)$                   & $(0.0131)$                   & $(0.0131)$                   \\
## No-course Baseline x 1[Post-treatment]              & $0.0514^{***}$ & $0.0514^{***}$               & $0.0511^{***}$               & $0.0514^{***}$               & $0.0506^{***}$               & $0.0506^{***}$               \\
##                                                     & $(0.0117)$     & $(0.0126)$                   & $(0.0124)$                   & $(0.0126)$                   & $(0.0123)$                   & $(0.0123)$                   \\
## No-course Baseline x 1[Misinfo]                     & $0.0051$       & $0.0051$                     & $0.0046$                     & $0.0051$                     & $0.0046$                     & $0.0046$                     \\
##                                                     & $(0.0101)$     & $(0.0101)$                   & $(0.0098)$                   & $(0.0101)$                   & $(0.0097)$                   & $(0.0097)$                   \\
## \hline
## Num. obs.                                           & $61524$        & $61524$                      & $61524$                      & $61524$                      & $61524$                      & $61524$                      \\
## R$^2$ (full model)                                  & $0.2867$       & $0.3484$                     & $0.3985$                     & $0.3489$                     & $0.4195$                     & $0.4195$                     \\
## R$^2$ (proj model)                                  & $$             & $0.0312$                     & $0.1057$                     & $0.0320$                     & $0.1369$                     & $0.1369$                     \\
## Adj. R$^2$ (full model)                             & $0.2861$       & $0.3100$                     & $0.3629$                     & $0.3105$                     & $0.3846$                     & $0.3846$                     \\
## Adj. R$^2$ (proj model)                             & $$             & $0.0311$                     & $0.1054$                     & $0.0318$                     & $0.1359$                     & $0.1359$                     \\
## Out-of-sample R$^2$                                 &                &                              &                              &                              &                              &                              \\
## Fixed Effects                                       &                & user                         & user                         & user                         & user                         & user                         \\
## Fixed Effects                                       &                &                              & Domain                       & Tactic                       & Domain x Tactic              & Post ID                      \\
## Covariates                                          &                & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates \\
## Clustered Std. Errors                               & user           & user                         & user                         & user                         & user                         & user                         \\
## \hline
## \multicolumn{7}{l}{\scriptsize{Significance levels: \*p<0.10, \*\*p<0.05, \*\*\*p<0.01 one-sided test.}}
## \end{tabular}
## \label{table:coefficients}
## \end{center}
## \end{table}

Panel Regression Followup Table

panel_2 <- readRDS("regression_analysis_long/data/panel_2_followup.rds")
cov_estimates_list <- readRDS("regression_analysis_long/data/cov_estimates_list_followup.rds")
# cov_roose_all_list <- readRDS("regression_analysis_long/data/cov_roose_all_list.rds")
# models_cov <- list('cov1_lm','cov2_lm','cov3_lm','cov4_lm','cov5_lm','cov6_lm')
# models_cov <- lapply(1:length(models_cov), 
#                      function(x) readRDS(paste0("regression_analysis_long/R2_outofsample/R2oos_cov_2treat_",x, "_5.rds")))
# 
R2oos_cov_2treat_all <- c("", "", "", "", "", "")
cov <- 5

# Print model
headers <- c("Share (binary indicator)")
model_list <- cov_estimates_list[[cov]]
names <- unique(c(names(cov_estimates_list[[cov]][[1]]$coefficients),
                  names(cov_estimates_list[[cov]][[2]]$coefficients),
                  names(cov_estimates_list[[cov]][[3]]$coefficients),
                  names(cov_estimates_list[[cov]][[4]]$coefficients),
                  names(cov_estimates_list[[cov]][[5]]$coefficients),
                  names(cov_estimates_list[[cov]][[6]]$coefficients)))
variable_labels_wide <- variable_mapping_long_followup[names]
# remova NA
variable_labels_wide <- variable_labels_wide[!is.na(variable_labels_wide)]

# remove blankrows
coef_names <- names
matrix_coeff_na <- expand.grid(coef_name = coef_names, model = seq(length(model_list)))
matrix_coeff_na$var <- 0
matrix_coeff_na$var_na <- 0
for (m in 1:length(model_list)) {
  na_coeff <- names(model_list[[m]]$coefficients)[is.na(model_list[[m]]$coefficients)]
  for (c in na_coeff) {
    matrix_coeff_na$var[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1 # 1 if variable is in the model (not all models have all variables)
    matrix_coeff_na$var_na[matrix_coeff_na$coef_name == c & matrix_coeff_na$model == m] <- 1
  }
}
matrix_coeff_na <- matrix_coeff_na %>% group_by(coef_name) %>% mutate(var = sum(var), var_na = sum(var_na)) %>% distinct(coef_name,var,var_na)
rows_to_omit <- as.vector(unique(matrix_coeff_na$coef_name[matrix_coeff_na$var_na != 0])) # omit if NA in all models
rows_to_omit <- gsub("\\^\\s","^",paste0("^",rows_to_omit,"$", collapse = "|"))
rows_to_omit <- gsub("\\(","\\\\(",gsub("\\)","\\\\)",rows_to_omit))

# keep variables
keep <- c("treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Followup-treatment] x 1[Misinfo]",
             "treatmentEmotions:post" = "Emotions x 1[Followup-treatment]",
             "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]")

keep <- list("treatmentEmotions:post:post_is_misinfo" = "Emotions x 1[Followup-treatment] x 1[Misinfo]",
             "treatmentEmotions:post" = "Emotions x 1[Followup-treatment]",
             "treatmentEmotions:post_is_misinfo" = "Emotions x 1[Misinfo]")
etable(model_list, 
       title = paste("Linear Regression:", headers, 
                     "vs. Treatment for different set of fixed effects\n<br>Covariates: Demographics + Sharing rates"),
       dict = variable_labels_wide,
       headers = c("Baseline<br>(1)",
                            "User ID FE<br>(2)",
                            "User ID FE +<br>Post domain FE<br>(3)",
                            "User ID FE +<br>Post tactic FE<br>(4)",
                            "User ID FE +<br>Post domain x Post tactic<br>(5)",
                            "User ID FE +<br>Post ID FE<br>(6)"),
       keep = paste0("%", names(keep)),
       signif.code = c("***" = 0.02, "**" = 0.1, "*" = 0.2),
       notes = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
       extralines = list("Fixed-Effect" = c("", "", "Domain", "Tactic", "Domain x Tactic", "Post ID")),
       digits = 4,tex = FALSE)
##                                                           model 1
##                                                   Baseline<br>(1)
## Dependent Var.:                                             share
##                                                                  
## Emotions x 1[Followup-treatment]              -0.0522*** (0.0207)
## Emotions x 1[Misinfo]                            -0.0022 (0.0126)
## Emotions x 1[Followup-treatment] x 1[Misinfo]  -0.0411** (0.0242)
## Fixed-Effect                                                     
## Fixed-Effects:                                -------------------
## user                                                           No
## ________________________________________      ___________________
## S.E. type                                                     IID
## Observations                                               28,483
## R2                                                        0.29932
## Within R2                                                      --
## 
##                                                          model 2
##                                                User ID FE<br>(2)
## Dependent Var.:                                            share
##                                                                 
## Emotions x 1[Followup-treatment]              -0.0522** (0.0227)
## Emotions x 1[Misinfo]                           -0.0022 (0.0129)
## Emotions x 1[Followup-treatment] x 1[Misinfo] -0.0411** (0.0233)
## Fixed-Effect                                                    
## Fixed-Effects:                                ------------------
## user                                                         Yes
## ________________________________________      __________________
## S.E. type                                               by: user
## Observations                                              28,483
## R2                                                       0.33333
## Within R2                                                0.07896
## 
##                                                                             model 3
##                                               User ID FE +<br>Post domain FE<br>(3)
## Dependent Var.:                                                               share
##                                                                                    
## Emotions x 1[Followup-treatment]                                 -0.0468** (0.0211)
## Emotions x 1[Misinfo]                                             -2.26e-5 (0.0125)
## Emotions x 1[Followup-treatment] x 1[Misinfo]                   -0.0522*** (0.0215)
## Fixed-Effect                                                                 Domain
## Fixed-Effects:                                                  -------------------
## user                                                                            Yes
## ________________________________________                        ___________________
## S.E. type                                                                  by: user
## Observations                                                                 28,483
## R2                                                                          0.39085
## Within R2                                                                   0.15843
## 
##                                                                             model 4
##                                               User ID FE +<br>Post tactic FE<br>(4)
## Dependent Var.:                                                               share
##                                                                                    
## Emotions x 1[Followup-treatment]                                 -0.0522** (0.0227)
## Emotions x 1[Misinfo]                                              -0.0022 (0.0129)
## Emotions x 1[Followup-treatment] x 1[Misinfo]                    -0.0411** (0.0233)
## Fixed-Effect                                                                 Tactic
## Fixed-Effects:                                                   ------------------
## user                                                                            Yes
## ________________________________________                         __________________
## S.E. type                                                                  by: user
## Observations                                                                 28,483
## R2                                                                          0.33438
## Within R2                                                                   0.08042
## 
##                                                                                        model 5
##                                               User ID FE +<br>Post domain x Post tactic<br>(5)
## Dependent Var.:                                                                          share
##                                                                                               
## Emotions x 1[Followup-treatment]                                            -0.0489** (0.0211)
## Emotions x 1[Misinfo]                                                         -0.0029 (0.0124)
## Emotions x 1[Followup-treatment] x 1[Misinfo]                              -0.0526*** (0.0213)
## Fixed-Effect                                                                   Domain x Tactic
## Fixed-Effects:                                                             -------------------
## user                                                                                       Yes
## ________________________________________                                   ___________________
## S.E. type                                                                             by: user
## Observations                                                                            28,483
## R2                                                                                     0.41259
## Within R2                                                                              0.18846
## 
##                                                                         model 6
##                                               User ID FE +<br>Post ID FE<br>(6)
## Dependent Var.:                                                           share
##                                                                                
## Emotions x 1[Followup-treatment]                             -0.0489** (0.0211)
## Emotions x 1[Misinfo]                                          -0.0029 (0.0124)
## Emotions x 1[Followup-treatment] x 1[Misinfo]               -0.0526*** (0.0213)
## Fixed-Effect                                                            Post ID
## Fixed-Effects:                                              -------------------
## user                                                                        Yes
## ________________________________________                    ___________________
## S.E. type                                                              by: user
## Observations                                                             28,483
## R2                                                                      0.41258
## Within R2                                                               0.18846
## ---
## Signif. codes: 0 '***' 0.02 '**' 0.1 '*' 0.2 ' ' 1
texreg::texreg(model_list,
                      custom.header = list("Share (binary indicator)" = 1:length(model_list)),
                      custom.model.names = c("\\makecell{Baseline \\\\ (1)}",
                                             "\\makecell{User ID FE \\\\ (2)}",
                                             "\\makecell{User ID FE + \\\\ Post domain FE \\\\ (3)}",
                                             "\\makecell{User ID FE + \\\\ Post tactic FE \\\\ (4)}",
                                             "\\makecell{User ID FE + \\\\ Post domain x Post tactic \\\\ (5)}",
                                             "\\makecell{User ID FE + \\\\ Post ID FE \\\\ (6)}"),
                      stars = c(0.20, 0.10, 0.02),
                      custom.note = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
                      caption = paste("Linear Regression:", headers, "vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]"),
                      caption.above = TRUE,
                      doctype = FALSE,
                      html.tag = FALSE,
                      table.tag = FALSE,
                      single.row = FALSE,
                      include.groups = FALSE,
                      digits = 4,
                      custom.coef.names = variable_labels_wide,
                      custom.coef.map = keep,
                      custom.gof.rows = list("Fixed Effects" = c("",rep("user",length(model_list)-1)),
                                             "Fixed Effects" = c("","","Domain","Tactic","Domain x Tactic","Post ID"),
                                             "Covariates" = c("",rep("Demographics + Sharing rates",length(model_list)-1)),
                                             "Clustered Std. Errors" = rep("user",length(model_list)),
                                             "Out-of-sample R^2" = c(R2oos_cov_2treat_all)),
                      reorder.gof = c(6,7,8,9,10,5,1,2,3,4))
## 
## \begin{table}
## \caption{Linear Regression: Share (binary indicator) vs. Treatment for different set of fixed effects [Covariates: Demographics + Sharing rates]}
## \begin{center}
## \begin{tabular}{l c c c c c c}
## \hline
##  & \multicolumn{6}{c}{Share (binary indicator)} \\
## \cline{2-7}
##  & \makecell{Baseline \\ (1)} & \makecell{User ID FE \\ (2)} & \makecell{User ID FE + \\ Post domain FE \\ (3)} & \makecell{User ID FE + \\ Post tactic FE \\ (4)} & \makecell{User ID FE + \\ Post domain x Post tactic \\ (5)} & \makecell{User ID FE + \\ Post ID FE \\ (6)} \\
## \hline
## Emotions x 1[Followup-treatment] x 1[Misinfo] & $-0.0411^{**}$  & $-0.0411^{**}$               & $-0.0522^{***}$              & $-0.0411^{**}$               & $-0.0526^{***}$              & $-0.0526^{***}$              \\
##                                               & $(0.0242)$      & $(0.0233)$                   & $(0.0215)$                   & $(0.0234)$                   & $(0.0213)$                   & $(0.0213)$                   \\
## Emotions x 1[Followup-treatment]              & $-0.0522^{***}$ & $-0.0522^{**}$               & $-0.0468^{**}$               & $-0.0522^{**}$               & $-0.0489^{**}$               & $-0.0489^{**}$               \\
##                                               & $(0.0207)$      & $(0.0227)$                   & $(0.0211)$                   & $(0.0227)$                   & $(0.0211)$                   & $(0.0211)$                   \\
## Emotions x 1[Misinfo]                         & $-0.0021$       & $-0.0021$                    & $-0.0000$                    & $-0.0021$                    & $-0.0029$                    & $-0.0029$                    \\
##                                               & $(0.0126)$      & $(0.0129)$                   & $(0.0125)$                   & $(0.0129)$                   & $(0.0124)$                   & $(0.0124)$                   \\
## \hline
## Num. obs.                                     & $28483$         & $28483$                      & $28483$                      & $28483$                      & $28483$                      & $28483$                      \\
## R$^2$ (full model)                            & $0.2993$        & $0.3333$                     & $0.3908$                     & $0.3344$                     & $0.4126$                     & $0.4126$                     \\
## R$^2$ (proj model)                            & $$              & $0.0790$                     & $0.1584$                     & $0.0804$                     & $0.1885$                     & $0.1885$                     \\
## Adj. R$^2$ (full model)                       & $0.2980$        & $0.2776$                     & $0.3396$                     & $0.2787$                     & $0.3621$                     & $0.3620$                     \\
## Adj. R$^2$ (proj model)                       & $$              & $0.0788$                     & $0.1577$                     & $0.0801$                     & $0.1864$                     & $0.1864$                     \\
## Out-of-sample R$^2$                           &                 &                              &                              &                              &                              &                              \\
## Fixed Effects                                 &                 & user                         & user                         & user                         & user                         & user                         \\
## Fixed Effects                                 &                 &                              & Domain                       & Tactic                       & Domain x Tactic              & Post ID                      \\
## Covariates                                    &                 & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates & Demographics + Sharing rates \\
## Clustered Std. Errors                         & user            & user                         & user                         & user                         & user                         & user                         \\
## \hline
## \multicolumn{7}{l}{\scriptsize{Significance levels: \*p<0.10, \*\*p<0.05, \*\*\*p<0.01 one-sided test.}}
## \end{tabular}
## \label{table:coefficients}
## \end{center}
## \end{table}

Follow-up Linear OLS Regression Table

Columns: each outcome in cross-sectional analysis Rows: coefficient on Emotions x Follow-up (NOTE: THIS TERM DOES NOT EXIST AS WE ARE RUNNING ON THE WIDE DATASET), Facts baseline mean, Covariates (x for included), Adj. R^2

# Load data
wide <- readRDS("regression_analysis_wide/followup/data/wide_followup.rds")
# Load models
models_all_covariates_te <- readRDS("regression_analysis_wide/followup/data/models_all_covariates_te_followup.rds")



# Print model
headers <- c("Share (binary indicator)")
model_list <- models_all_covariates_te
names <- unique(c(names(models_all_covariates_te[[1]]$coefficients),
                  names(models_all_covariates_te[[2]]$coefficients),
                  names(models_all_covariates_te[[3]]$coefficients),
                  names(models_all_covariates_te[[4]]$coefficients)))
variable_labels_wide <- variable_mapping_long_followup[names]
# remova NA
variable_labels_wide <- variable_labels_wide[!is.na(variable_labels_wide)]


# keep variables
keep <- c("(Intercept)" = "Facts Baseline mean",
             "treatmentEmotions" = "Emotions")
keep <- list("(Intercept)" = "Facts Baseline mean",
             "treatmentEmotions" = "Emotions")

outcomes<- c("Conditional Misinfo Sharing Rate",
             "Misinfo Sharing Rate",
             "Non-Misinfo Sharing Rate",
             "Sharing Discernment Score")
texreg::texreg(model_list,
                      # custom.header = list("Share (binary indicator)" = 1:length(model_list)),
                      custom.model.names = c("\\makecell{Conditional Misinf \\\\ Sharing Rate \\\\ (1)}",
                                             "\\makecell{Misinfo \\\\ Sharing Rate \\\\ (2)}",
                                             "\\makecell{Non-Misinfo \\\\ Sharing Rate \\\\ (3)}",
                                             "\\makecell{Sharing Discernment \\\\ Score \\\\ (4)}"),
                      stars = c(0.20, 0.10, 0.02),
                      custom.note = "Significance levels: \\*p<0.10, \\*\\*p<0.05, \\*\\*\\*p<0.01 one-sided test.",
                      caption = paste("Linear Regression: Followup analysis for different outcomes [Covariates: Demographics + Sharing rates +  Accuracy Scores]"),
                      caption.above = TRUE,
                      doctype = FALSE,
                      html.tag = FALSE,
                      table.tag = FALSE,
                      single.row = FALSE,
                      include.groups = FALSE,
                      include.ci = FALSE,
                      digits = 3,
                      custom.coef.names = variable_labels_wide,
                      custom.coef.map = keep,
                      custom.gof.rows = list( "Covariates" = c(rep("All",length(model_list)))))
## 
## \begin{table}
## \caption{Linear Regression: Followup analysis for different outcomes [Covariates: Demographics + Sharing rates +  Accuracy Scores]}
## \begin{center}
## \begin{tabular}{l c c c c}
## \hline
##  & \makecell{Conditional Misinf \\ Sharing Rate \\ (1)} & \makecell{Misinfo \\ Sharing Rate \\ (2)} & \makecell{Non-Misinfo \\ Sharing Rate \\ (3)} & \makecell{Sharing Discernment \\ Score \\ (4)} \\
## \hline
## Facts Baseline mean & $0.489^{***}$  & $0.400^{***}$  & $0.680^{***}$  & $0.280^{***}$ \\
##                     & $(0.014)$      & $(0.010)$      & $(0.014)$      & $(0.014)$     \\
## Emotions            & $-0.123^{***}$ & $-0.101^{***}$ & $-0.057^{***}$ & $0.044^{**}$  \\
##                     & $(0.020)$      & $(0.014)$      & $(0.020)$      & $(0.021)$     \\
## \hline
## Covariates          & All            & All            & All            & All           \\
## R$^2$               & $0.096$        & $0.163$        & $0.089$        & $0.031$       \\
## Adj. R$^2$          & $0.070$        & $0.144$        & $0.068$        & $0.009$       \\
## Num. obs.           & $4251$         & $5316$         & $5316$         & $5316$        \\
## RMSE                & $0.398$        & $0.329$        & $0.461$        & $0.481$       \\
## \hline
## \multicolumn{5}{l}{\scriptsize{Significance levels: \*p<0.10, \*\*p<0.05, \*\*\*p<0.01 one-sided test.}}
## \end{tabular}
## \label{table:coefficients}
## \end{center}
## \end{table}
                      # custom.gof.names = c("R^2", "Adj. R^2", "Statistics", "P Value", "DF Resid.", "Num. obs."),
                      # reorder.gof = c(7,1,2,3, 4, 5, 6))

Appendix Lee Bounds Figure

leebounds <- readRDS("../additional_analysis/lee_bounds/Lee_Bounds_combined.rds")
leebounds

HTE Table

Columns: high misinfo sharers, low misinfo sharers, high non-misinfo sharers, low non-misinfo sharers, high misinfo accuracy, low misinfo accuracy Rows: each outcome in cross-sectional analysis Cells: emotions course - facts baseline treatment effect, (SE), [TE/Facts Baseline Mean]

link to example format

Accuracy Nudge Figure

  • 3 panels: one for each outcome in cross-sectional analysis except pre-specified outcome
  • y-axis: mean of outcome
  • x-axis: two pairs of bars; first pair no-course baseline, accuracy inter/after; second pair emotions course, accuracy inter/after (like below)

Note these needs to be edited in additional analyses script

accuracy_nudge_plots <- readRDS("additional_analyses/data/accuracy_nudge_plots.rds")
accuracy_nudge_plots$plot_misinfo

accuracy_nudge_plots$plot_nonmisinfo

accuracy_nudge_plots$plot_disc