# Scale ID: 			CISS-21
# Scale Name: 		Coping Inventory for Stressful Situations
# TILDA Variables: 	CISSavoidance; CISSemotionorient; CISStaskorient
# Dataset:      		TILDA Waves 3 & 6
# Author:
# Institution:  		The Irish Longitudinal Study on Ageing (TILDA)
# 
# Description:
# Creates the Coping Inventory for Stressful Situations Short Form 3 factor scale.
# 
# Version:      1.0
# Date:         2026-09-01
# Language:     R

# Assumption: the working data frame is called `data`.

ciss_items <- paste0("SCQCISS", 1:21)
special_missing <- c(-99, -812, -823, -834, -845)

for (v in ciss_items) {
  rv <- paste0("R", v)
  data[[rv]] <- data[[v]]
  data[[rv]][data[[rv]] %in% special_missing] <- NA_real_
}

data$CISStaskorient <-
  data$RSCQCISS2 + data$RSCQCISS6 + data$RSCQCISS8 +
  data$RSCQCISS11 + data$RSCQCISS13 + data$RSCQCISS16 + data$RSCQCISS19

data$CISSemotionorient <-
  data$RSCQCISS3 + data$RSCQCISS5 + data$RSCQCISS10 +
  data$RSCQCISS12 + data$RSCQCISS14 + data$RSCQCISS17 + data$RSCQCISS20

data$CISSavoidance <-
  data$RSCQCISS1 + data$RSCQCISS4 + data$RSCQCISS7 +
  data$RSCQCISS9 + data$RSCQCISS15 + data$RSCQCISS18 + data$RSCQCISS21

attr(data$CISStaskorient, "label") <- "CISS-SF: Task-orient style coping"
attr(data$CISSemotionorient, "label") <- "CISS-SF: Emotion-orient style coping"
attr(data$CISSavoidance, "label") <- "CISS-SF: Avoidance style coping"

data[paste0("R", ciss_items)] <- NULL
