# Scale ID: 			Creative Lives Measure
# Scale Name: 		Creative Lives Measure
# TILDA Variables: 	CreativeLivesScore
# Dataset:      		TILDA Waves 7
# Author:
# Institution:  		The Irish Longitudinal Study on Ageing (TILDA)
# 
# Description:
# Cleans and codes up summed score of the Creative Lives Measure.
# 
# Version:      1.0
# Date:         2026-09-01
# Language:     R

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

creative_items <- paste0("CreatFreq", 1:6)

for (v in creative_items) print(table(data[[v]], useNA = "ifany"))

special_missing <- c(-99, -812, -823, -834, -845, -856, -867, -1)
for (v in creative_items) {
  data[[v]][data[[v]] %in% special_missing] <- NA_real_
  data[[paste0(v, "_recoded")]] <- data[[v]] - 1
}

recoded_items <- paste0(creative_items, "_recoded")

# Match Stata egen rowtotal(): ignore missing components and return 0 if all missing.
data$CreativeLivesScore <- rowSums(data[recoded_items], na.rm = TRUE)

attr(data$CreativeLivesScore, "label") <-
  "Total Score of Arts Engagement Questionnaire"

print(table(data$CreativeLivesScore, useNA = "ifany"))
