---
title: "RESPONDENTS’ PREFERRED SURVEY TOPICS: MEASUREMENT AND PREVALENCE"
subtitle: "Replication Files: Study 1"
author: "Tobias Gummer, Saskia Bartholomäus, and Bernd Weiss"
date: "19.01.2026"
output:
  html_document:
    theme: united
    toc: true
    toc_depth: 4
    toc_float:
      collapsed: true
      smooth_scroll: true
---
# Data Preparation

The data required for the replication code can be granted for scientific purposes upon request. 

Bartholomäus, S., and Gummer, T. (2025). PrADePS Pretest (SDN-10.7802-2635; Version 1.0.0) [Data set]. https://doi.org/10.7802/2635

```{r loading dataset, include=TRUE}
# Loading Dataset
cat("pretest_csv <- read.csv(file = '[INCLUDE PATH TO THE PRETEST DATA SET HERE]/20251007_PrADePSPretestData.csv', sep = ';')")
```

```{r renaming variables, message=FALSE, warning=FALSE, results='hide'}
# Renaming Variables
pretest_csv <- dplyr::rename(
  pretest_csv,                    #dataset
  i_gender      = v_2683,         #newname = oldname
  i_birthyear   = rtr3p1_y,
  i_education   = v_2686, 
  i_state       = v_2687,
  i_polinterest = jazc030a,
  s_interesting = jazq001a,

  m_migration   = v_2925, 
  m_pol         = v_2927,
  m_crisis      = v_2932, 
  m_nature      = v_2881, 
  m_economy     = v_2882, 
  m_work        = v_2886, 
  m_media       = v_2890, 
  m_well        = v_2891, 
  m_values      = v_2895,
  i_comp        = v_2803)
```

```{r creating variable labels, message=FALSE, warning=FALSE, results='hide'}
# Variable Labels
labels <- list(
  i_gender         = "Gender",
  i_birthyear      = "Year of Birth",
  i_age            = "Age in Years",
  i_education      = "Educaional Level",
  i_state          = "Federal State",
  i_east           = "Eastern Germany",
  i_polinterest    = "Political Interest",
  st_polinterest   = "Political Interest",
  s_interesting    = "Survey is Interesting",

  tp_pol           = "Topic Interest Politics",
  tp_well          = "Topic Interest Well-Being",
  tp_nature        = "Topic Interest Nature",
  tp_values        = "Topic Interest Values",
  tp_media         = "Topic Interest Media",
  tp_work          = "Topic Interest Work",
  tp_migration     = "Topic Interest Migration",
  tp_economy       = "Topic Interest Economy",
  tp_crisis        = "Topic Interest Crisis",
  
  vb_quest         = "Questionnaire",
  vb_explain       = "Explanaition",
  vb_comp          = "Matrix")
```

```{r creating subsets, message=FALSE, warning=FALSE, results='hide'}
# Creating Subsets
subset <- select(pretest_csv, lfdn, duration, i_gender : i_polinterest, s_interesting, v_2786 : v_2802, rnd_pg_7235041 : rnd_pg_7236459,
  m_migration, m_values, m_pol, m_crisis, m_nature, m_economy, m_work, m_media, m_well, i_comp)
# subset for balance tests
balance <- select(pretest_csv, i_gender : i_state)
```  

```{r defining missing values, message=FALSE, warning=FALSE, results='hide'}
# Defining Missing Values
pretest_csv[pretest_csv == -111 | pretest_csv == -77] <- NA

subset[subset == -111 | subset == -77 | subset == 97 | subset == 98 | subset == 99] <- NA
subset$lfdn <- pretest_csv$lfdn
subset$duration <- pretest_csv$duration
subset$duration[subset$duration == -111] <- NA
```  

```{r defining experimental groups, message=FALSE, warning=FALSE, results='hide'}
# Defining Experimental Groups
subset <- mutate(subset, vb_quest = ifelse(rnd_pg_7235041 == 7234835, 1, 0))
balance$vb_quest <- subset$vb_quest

subset <- mutate(subset, vb_explain = ifelse(rnd_pg_7235688 == 7235696, 1, 0))
balance$vb_explain <- subset$vb_explain

subset <- mutate(subset, vb_comp = case_match(rnd_pg_7236459, 7236339 ~ 1, 7236470 ~ 2, 7236473 ~ 3))
balance$vb_comp <- subset$vb_comp

subset <- set_labels(subset, vb_quest, labels = c("Politics" = 0, "Well-Being" = 1))
subset <- set_labels(subset, vb_explain, labels = c("without Example" = 0, "with Example" = 1))
subset <- set_labels(subset, vb_comp, labels = c("Economy, Work, Nature" = 1, "Media, Well-Being, Values" = 2, "Migration, Politics, Crisis" = 3))
```

```{r merging variables, message=FALSE, warning=FALSE, results='hide'}
# Merging Variables of Groups
subset <- mutate(subset, tp_pol = ifelse(!is.na(subset$v_2785), v_2785, v_2795))              
subset <- mutate(subset, tp_well = ifelse(!is.na(subset$v_2786), v_2786, v_2794))
subset <- mutate(subset, tp_nature = ifelse(!is.na(subset$v_2787), v_2787, v_2796))
subset <- mutate(subset, tp_values = ifelse(!is.na(subset$v_2788), v_2788, v_2797))
subset <- mutate(subset, tp_media = ifelse(!is.na(subset$v_2789), v_2789, v_2798))  
subset <- mutate(subset, tp_work = ifelse(!is.na(subset$v_2790), v_2790, v_2799)) 
subset <- mutate(subset, tp_migration = ifelse(!is.na(subset$v_2791), v_2791, v_2800))     
subset <- mutate(subset, tp_economy = ifelse(!is.na(subset$v_2792), v_2792, v_2801))    
subset <- mutate(subset, tp_crisis = ifelse(!is.na(subset$v_2793), v_2793, v_2802))

subset <- set_labels(subset, tp_pol, tp_well, tp_nature, tp_values, tp_crisis, tp_media, tp_work, tp_migration, tp_economy, 
  labels = c("not interested at all" = 1, "very interested" = 7))

# share of correct assessments	
subset$m1 <- rowMeans(subset(pretest_csv, select = c(m_migration, m_pol, m_crisis)), na.rm = FALSE)
subset$m2 <- rowMeans(subset(pretest_csv, select = c(m_nature, m_economy, m_work)), na.rm = FALSE)
subset$m3 <- rowMeans(subset(pretest_csv, select = c(m_media, m_well, m_values)), na.rm = FALSE)
 
subset$matrix_mean <- subset$m1
subset <- mutate(subset, matrix_mean = ifelse(!is.na(subset$matrix_mean), matrix_mean, m2))
subset <- mutate(subset, matrix_mean = ifelse(!is.na(subset$matrix_mean), matrix_mean, m3))
```

```{r dq indicators, message=FALSE, warning=FALSE, results='hide'}
# Defining Data Quality Indicators
topic <- select(subset, tp_pol : tp_crisis)

# extreme responding
as.data.frame(extreme <- 1 * (topic == 1 | topic == 7))
  subset$extreme <- (rowSums(extreme, na.rm = FALSE))/9

# midpoint responding
as.data.frame(midpoint <- 1 * (topic == 4))
  subset$midpoint <- (rowSums(midpoint, na.rm = FALSE))/9

# item nonresponse
as.data.frame(na <- 1 * (is.na(topic)))
  subset$na <- (rowSums(na, na.rm = FALSE))/9

# acquiescence
as.data.frame(acquiescence <- 1 * (topic == 7 | topic == 6 | topic == 5))
  subset$acquiescence <- (rowSums(acquiescence, na.rm = FALSE))/9
  
# comprehensability 
subset$i_comp <- (subset$i_comp - 1) / 6
```

```{r recoding gender, message=FALSE, warning=FALSE, results='hide'}
# Recoding Gender: randomly replace diverse values 
diverse <- subset$i_gender == 3
subset$i_gender <- replace(subset$i_gender, diverse, sample(1:2, sum(diverse), TRUE, prob = c(0.5, 0.5)))
rm(diverse)
```

```{r categorizing education, message=FALSE, warning=FALSE, results='hide'}
# Categorizing Education
subset <- mutate(subset, i_education = case_match(i_education,  
  1 ~ 2, 2 ~ 1, 3 ~ 1, 4 ~ 1, 5 ~ 2, 6 ~ 1, 7 ~ 2, 8 ~ 3, 9 ~ 3))   
balance$i_education <- subset$i_education

subset <- set_labels(subset, i_education, labels = c("low" = 1, "medium" = 2, "high" = 3))
```

```{r recoding political interest, message=FALSE, warning=FALSE, results='hide'}
# Recoding Political Interest
subset <- mutate(subset, i_polinterest = case_match(i_polinterest, 1 ~ 5, 2 ~ 4, 3 ~ 3, 4 ~ 2, 5 ~ 1))
  
subset <- set_labels(subset, i_polinterest, labels = c("not at all" = 1, "very strong" = 5))
```

```{r recoding age in years, message=FALSE, warning=FALSE, results='hide'}
# Recoding Age in Years
subset <- mutate(subset, i_age = 2022-i_birthyear)
balance$i_age <- subset$i_age

subset <- mutate(subset, age_group = case_when(i_age <= 30 ~ 1, i_age > 30 & i_age <= 48 ~ 2, i_age > 48 & i_age <= 63 ~ 3, i_age > 63 ~ 4))
subset <- set_labels(subset, age_group, labels = c("<= 30" = 1, "> 30 & <= 49" = 2, "> 49 & <= 63" = 3, "> 63" = 4))
```

```{r recoding residence in Germany, message=FALSE, warning=FALSE, results='hide'}
# Recoding Residence in Germany
subset <- mutate(subset, i_east = ifelse(              #gen var east
 i_state == 3 | i_state == 4 | i_state == 8 |          #2 if i_state = x
 i_state == 13 | i_state == 14 |i_state == 16, 2, 1))  #else 1    
  
subset <- set_labels(subset, i_east, labels = c("West Germany" = 1, "East Germany" = 2))

balance <-  mutate(balance, i_east = ifelse(i_state == 3 | i_state == 4 | i_state == 8 | i_state == 13 | i_state == 14 |i_state == 16, 2, 1))  
balance <- mutate(balance, i_east = ifelse(i_state == 99, 0, i_east))
```

```{r defining factor variables, message=FALSE, warning=FALSE, results='hide'}
# Defining Factor Variables
subset$vb_quest <- as_factor(subset$vb_quest)
subset$vb_explain <- as_factor(subset$vb_explain)
subset$i_gender <- as_factor(subset$i_gender)
subset$i_education <- as_factor(subset$i_education)
subset$i_east <- as_factor(subset$i_east)
subset$age_group <- as_factor(subset$age_group)
#response$device_type <- as_factor(response$device_type)
```

```{r wide to long, echo=TRUE, message=FALSE, warning=FALSE}
# Structure Dataset: long format
long <- gather(subset, variable, matrix, m_migration:m_well)
  matrix1_long <- filter(long, vb_comp == 1, variable == "m_economy" | variable == "m_work" | variable == "m_nature")
  matrix2_long <- filter(long, vb_comp == 2, variable == "m_media" | variable == "m_well" | variable == "m_values")
  matrix3_long <- filter(long, vb_comp == 3, variable == "m_migration" | variable == "m_pol" | variable == "m_crisis")
long <- smartbind(matrix1_long, matrix2_long, matrix3_long)
rm(matrix1_long, matrix2_long, matrix3_long)

long$tp_interest <- 0
long <- mutate(long, tp_interest = ifelse(variable == "m_migration", tp_migration, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_crisis", tp_crisis, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_economy", tp_economy, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_media", tp_media, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_nature", tp_nature, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_pol", tp_pol, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_values", tp_values, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_well", tp_well, tp_interest))
long <- mutate(long, tp_interest = ifelse(variable == "m_work", tp_work, tp_interest))
```

```{r save datasets, message=FALSE, warning=FALSE, results='hide'}
# Save Datasets
save(subset, labels, file = "data/subset.RData")
save(balance, labels, file = "data/balance.RData")
save(long, labels, file = "data/long.RData")
```

```{r clearing memory, message=FALSE, warning=FALSE, results='hide'}
# Clearing Memory
rm(list = setdiff(ls(), c("custom_theme")))
```