## Study 2 — clean: data/data_raw/raw_study2_(271657).csv -> data/data_cleaned/study2_clean_(271657).Rds
## Factor-only design (5 factors: length, certainty, information, questions, attitude),
## launch cohort only. Substantive recoding and analysis live in the manuscript QMD.
source(here::here("R", "_helpers.R"))

d <- read.csv(path_raw("raw_study2_(271657).csv"), stringsAsFactors = FALSE)
d$is_ai <- grepl("^AI-", d$id)   # none in Study 2 (no AI respondent rows), kept for a uniform schema
d$completed_flag <- tolower(trimws(as.character(d$completed))) %in% c("1", "true", "t", "yes")
if ("initial_forecast" %in% names(d)) d$initial <- suppressWarnings(as.numeric(d$initial_forecast))
if ("revised_forecast" %in% names(d)) d$revised <- suppressWarnings(as.numeric(d$revised_forecast))
# 5 factor flags (present for the 'factors' treatment).
factor_cols <- intersect(c("factor_length", "factor_certainty", "factor_information",
                           "factor_questions", "factor_attitude"), names(d))

dir.create(here::here("data", "data_cleaned"), showWarnings = FALSE, recursive = TRUE)
saveRDS(d, path_clean("study2_clean_(271657).Rds"))
message(sprintf("study2_clean_(271657).Rds: %d rows, %d completed; factor cols: %s",
  nrow(d), sum(d$completed_flag), paste(factor_cols, collapse = ", ")))
