---
title: "RESPONDENTS’ PREFERRED SURVEY TOPICS: MEASUREMENT AND PREVALENCE"
subtitle: "Replication Files: Study 2"
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 accessed under a data use agreement. 

GESIS – Leibniz Institute for the Social Sciences (2024). GESIS Panel - Standard Edition (ZA5665; Version 54.0.0) [Data set]. https://doi.org/10.4232/1.14386 

```{r loading dataset, include=TRUE}
# Loading Dataset
cat("gesispanel_dta <- read_dta('[INCLUDE PATH TO THE PRETEST DATA SET HERE]/ZA5665_GESIS_Panel_v54-0-0.dta')")
cat("gesispanel_dta   <- remove_all_labels(gesispanel_dta)")
```
 
```{r renaming variables, message=FALSE, warning=FALSE, results='hide'}
# Renaming Variables
gesispanel_dta <- dplyr::rename(gesispanel_dta, 
  tp_well = kaea069a, 
  tp_pol = kaea070a, 
  tp_nature = kaea071a, 
  tp_personal = kaea072a,
  tp_media = kaea073a, 
  tp_work = kaea074a, 
  tp_migration = kaea075a, 
  tp_economy = kaea076a, 
  tp_leisure = kaea077a,
  tp_crisis = kaea078a,  
  
  i_polinterest = kazc030a, 
  i_trust = kazc056a,
  
  i_gender = jdzh023b,
  year = jdzh024c,
  i_education = jdzh030a,
  east_a12 = a12d021b,
  east_d12 = d12d025b,
  east_f12 = f12d021b,
  east_i12 = i12c049b)
```
  
```{r creating variable labels, message=FALSE, warning=FALSE, results='hide'}
# Variable Labels
labels <- list(
  i_gender         = "Gender",
  i_age            = "Age in Years",
  i_education      = "Educaional Level",
  i_east           = "Eastern Germany",
  
  i_polinterest    = "Political Interest",
  i_trust          = "General Trust",
  
  tp_pol           = "Topic Interest Politics",
  tp_well          = "Topic Interest Well-Being",
  tp_nature        = "Topic Interest Nature",
  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",
  tp_personal      = "Topic Interest Personality",
  tp_leisure       = "Topic Interest Leisure")
```
  
```{r creaing value labels, message=FALSE, warning=FALSE, results='hide'}
# Value Labels
gesispanel_dta <- set_labels(gesispanel_dta, i_gender, labels = c("male" = 1, "female" = 2))
gesispanel_dta <- set_labels(gesispanel_dta, i_education, labels = c("low" = 1, "medium" = 2, "high" = 3))
gesispanel_dta <- set_labels(gesispanel_dta, i_east, labels = c("west" = 1, "east" = 2))
gesispanel_dta <- set_labels(gesispanel_dta, i_trust, labels = c("not at all" = 1, "very strong" = 7))
gesispanel_dta <- set_labels(gesispanel_dta, i_polinterest, labels = c("not at all" = 1, "very strong" = 5))
gesispanel_dta <- set_labels(gesispanel_dta, tp_pol, tp_well, tp_nature, tp_personal, tp_media, tp_work, tp_migration, tp_economy, tp_crisis, tp_leisure, 
  labels = c("very interested" = 7, "not interestes at all" = 1)) 
```
 
```{r creating subsets, message=FALSE, warning=FALSE, results='hide'}
# Creating Subsets
subset <- select(gesispanel_dta, z000001a, tp_well:tp_crisis, i_polinterest, i_trust, i_gender, year, i_education, east_a12, east_d12, east_f12, east_i12)
```

```{r defining missing values, message=FALSE, warning=FALSE, results='hide'}
# Defining Missing Values
subset[subset == -11 | subset == -22 | subset == -33 | subset == -55 | subset == -77 | subset == -88 | subset == -99 | subset == -111 | subset == 97 | subset == 98] <- NA
save(subset, labels, file = "data/subset.RData")
```
 
```{r merging variables, message=FALSE, warning=FALSE, results='hide'}
# Merging Variables of Groups
subset <- mutate(subset, i_east = ifelse(!is.na(subset$east_a12), east_a12, east_d12))
subset <- mutate(subset, i_east = ifelse(!is.na(subset$i_east),  i_east, east_f12))
subset <- mutate(subset, i_east = ifelse(!is.na(subset$i_east), i_east, east_i12))
```
 
```{r recoding age, message=FALSE, warning=FALSE, results='hide'}
# Recoding Age in Years
subset <- mutate(subset, i_age = 2023-year)

subset <- mutate(subset, age_group = case_when(i_age <= 48 ~ 1, i_age > 48 & i_age <= 63 ~ 2, i_age > 63 ~ 3))
subset <- set_labels(subset, age_group, labels = c("<= 48" = 1, "49 - 63" = 2, "> 63" = 3))
```
 
```{r recoding 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))   
```
 
```{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))
```
 
```{r defining factor variables, message=FALSE, warning=FALSE, results='hide'}
# Defining Factor Variables
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)
```

```{r save datasets, message=FALSE, warning=FALSE, results='hide'}
# Save Datasets
save(subset, labels, file = "data/subset.RData")
rm(list = setdiff(ls(), c("custom_theme")))
```

