# Scale ID: 			PCL-6
# Scale Name: 		PTSD Checklist 6
# TILDA Variables: 	PCL6Score; PCL6_screen
# Dataset:      		TILDA Wave 1-6
# Author:
# Institution:  		The Irish Longitudinal Study on Ageing (TILDA)
# 
# Description:
# Generates scoring for the PTSD Checklist 6.
# 
# Version:      1.0
# Date:         2026-09-01
# Language:     R
#
# Assumption: the working data frame is called `data`.

# Recode -99 responses to missing.
pcl_items <- paste0("SCQPCL", 1:6)

for (var in pcl_items) {
  data[[var]][data[[var]] %in% c(-99, -812, -823, -834, -845)] <- NA
}

# Total score: 6-30.
# Stata rowtotal() is used first, then the score is set missing if any item is missing.
data$PCL6Score <- rowSums(data[pcl_items], na.rm = TRUE)
data$PCL6_missing <- rowSums(is.na(data[pcl_items]))
data$PCL6Score[data$PCL6_missing > 0] <- NA_real_

attr(data$PCL6Score, "label") <- "PTSD Checklist 6 (PCL-6) total score"

# Positive PTSD screen using cut-off >=14.
data$PCL6_screen <- NA_real_
data$PCL6_screen[!is.na(data$PCL6Score) & data$PCL6Score < 14] <- 0
data$PCL6_screen[!is.na(data$PCL6Score) & data$PCL6Score >= 14] <- 1

attr(data$PCL6_screen, "label") <- "PCL-6 probable PTSD screen"
attr(data$PCL6_screen, "labels") <- c(
  "Negative screening (<14)" = 0,
  "Positive screening (14+)" = 1
)

print(table(data$PCL6_screen, useNA = "ifany"))
summary(data$PCL6Score)
