The NextGen Harmonised Data Gateway
  • Home
  • Variable Database
    • Variable Database
    • Make it Green!
    • Make it Digital!
    • Make it Equal!
    • Make it Healthy!
    • Make it Strong!
  • Harmonisation
    • Harmonisation Toolbox
    • Make it Green!
    • Make it Digital!
    • Make it Equal!
    • Make it Healthy!
    • Make it Strong!
  • Data
  • Training
  • Contact
    • User Support
    • Team

On this page

  • Set-up
  • 1. Prepare Data: EB 2017
  • 2. Prepare Data: EB 2013
  • 3. Prepare Data: EB 2009
  • 4. Prepare Data: EB 2004
  • 5. Prepare Data: EQLS
  • 6. Prepare Data: ISSP 2007
  • 7. Harmonisation
  • Summary

Frequency of Physical Exercise

This page guides you through the harmonisation process of the Frequency of Physical Exercise item.

The item was administered in EB 2017, 2013, 2009, 2004; EQLS 2016, 2012; and ISSP 2007. Before we start harmonising, please download these data sets from the respective repositories. You can find links to the survey repositories on the Make It Healthy! data documentation page, in the section devoted to Frequency of Physical Exercise. If you click on the single year, the link takes you to the specific data set. We are working with the .sav format. So please make sure to download the datasets in this format.

Set-up

Please download the statistical software R (R Core Team, 2024) and RStudio (RStudio Team, 2023). Then start a project in RStudio by clicking File > New Project and set up a new directory or assign your project to an existing directory (i.e., folder). Within the project directory, create a folder called “data”. Now save the downloaded EB, EQLS and ISSP survey data into this “data” folder. Lastly, please download the following packages using the install.packages() function if they have not been before.

install.packages()
packages <- c( "tidyverse", "readxl", "xlsx", "haven", "labelled", "tidyr", "knitr", "kableExtra", "dplyr", "openxlsx")

installed <- packages %in% rownames(installed.packages())
if (any(!installed)) install.packages(packages[!installed])

Every package installed in R must also be loaded. This is what the library-function is for.

library(tidyverse)
library(readxl)
library(openxlsx) # If you have problems installing or loading the xlsx-package, use the openxlsx. 
library(haven)
library(labelled)
library(tidyr)
library(knitr)
library(kableExtra)
library(dplyr)

An important step during the harmonisation process is to prepare the source data sets in a consistent and systematic way. For that, the functions “codebook” (create_codebook_short()) and ”crosswalk table” (create_cwt()) by Kołczyńska (2022) are used. They show the correspondence between source data sets and harmonised data regarding variable names and values. These functions are adopted into our needs, and the R file containing them can be downloaded here . Please save this file in the R project folder and import it into the R project via source("kolczynska2022_i4ng.R").

How-to

If you cannot download the R-file and if it is opened in a new tab, please open a new file in your R-Studio project under File -> New File -> R Script and copy the text from the kolczynska2022-file into this new file. Make sure that you save this new file in your project folder under the name “kolczynska2022_i4ng.R”.

source("kolczynska2022_i4ng.R")

Now we can name our target variable as “h_ps_exer”. The name is a combination of “h” representing the main topic “healthy”, the concept “Physical State and Daily Functioning” and the variable label “Frequency of Physical Exercise”.

target_var_hrms <- "h_ps_exer"

Before we can harmonise any data, we need to prepare the source data sets:

1. Prepare Data: EB 2017

Six steps must be carried out in the following coding section:

1.1 Import data

eb17 <- haven::read_sav("data/ZA6939_v3-0-0.sav", user_na=TRUE)  
Check the source item

Use this output to compare it with your output. Check especially if the labels match.

attr(eb17$qb1, "label")
[1] "SPORT ACTIVITY - FREQUENCY"
eb17 %>% count(qb1)
# A tibble: 7 × 2
  qb1                            n
  <dbl+lbl>                  <int>
1 1 [5 times a week or more]  2244
2 2 [3 to 4 times a week]     3101
3 3 [1 to 2 times a week]     5114
4 4 [1 to 3 times a month]    1360
5 5 [Less often]              3060
6 6 [Never]                  13093
7 7 (NA) [DK]                   59

1.2. Create codebook

Not just the substantive variables but also protocol variables need to be selected from this data set. Protocol variables selected for this harmonisation are the source data’s country, weight, and ID variables. In this step, we create a codebook that provides an overview of the selected variables and their naming in the harmonised data.

codebook_eb17 <- create_codebook_short(eb17) %>%
  mutate(survey = "EB",
         target_var = ifelse(var_source == "isocntry", "country_source", NA),
         target_var = ifelse(var_source == "w3a", "w2_poststr", target_var),
         target_var =ifelse(grepl("unified respondent number|Respondent's identification number|RESPONDENT ID", var_label_source, perl = TRUE), "caseID_source", target_var),
         target_var =  ifelse(grepl("SPORT ACTIVITY - FREQUENCY", var_label_source), 
                             target_var_hrms, 
                             target_var),
         target_var = gsub(" ", "_", target_var),
         target_var = tolower(target_var))

codebook_eb17 includes the columns called: var_source, var_label_source, survey, target_var. The variable names which will be used in the harmonised data are listed under target_var.

var_source var_label_source survey target_var
uniqid UNIQUE RESPONDENT ID (CASEID BY TNS COUNTRY CODE) (SEE NOTE) EB caseid_source
isocntry COUNTRY CODE - ISO 3166 EB country_source
qb1 SPORT ACTIVITY - FREQUENCY EB h_ps_exer
qb1r SPORT ACTIVITY - FREQUENCY (RECODED) EB h_ps_exer
w3a WEIGHT RESULT FROM TARGET - UNITED GERMANY EB w2_poststr

 

1.3. Retrieve names of the chosen source variables

variables <- codebook_eb17 %>% drop_na(target_var) %>% pull(var_source)

The retrieved variables are: uniqid, isocntry, qb1, qb1r, w3a.

 

1.4. Select a subset of the survey data containing only the chosen variables

eb17_small <- eb17 %>% select(all_of(variables)) %>% mutate(caseid = row_number())

You will see that the following data set is a subset of the EB 2017 containing the chosen variables for the harmonised data. The first six rows of the dataset are as follows:

uniqid isocntry qb1 qb1r w3a caseid
16711728 BE 3 2 1.3897 1
16708419 BE 6 4 1.3138 2
16708417 BE 6 4 1.5267 3
16708415 BE 6 4 1.6886 4
16707074 BE 1 1 1.3717 5
16707061 BE 4 3 1.3717 6

 

1.5. Create a crosswalk table for the chosen variables

A crosswalk table provides a connection between the source variable values and the target variable values. First, it provides the variables, their labels, and the possible values. Then, the information is linked with the codebook information of the newly specified target variables. Lastly, target values are defined in a variable called target_value.

Here, weight and ID variables are excluded from the crosswalk table. Original codes for the country variable are preserved. Lastly, NAs are assigned to missing values.

eb17_cwt <- create_cwt(eb17_small %>% select(isocntry, qb1)) %>%
  left_join(codebook_eb17, by=join_by(var_source, var_label_source)) %>%
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|NA|applicable|Can't choose|]DK|] DK|Na|Inap", value_label_source), #* CHECK
                               value_code, 
                               target_value),
         value_code = as.character(value_code)
  )
Important

There are decisions about the substantive variable made by taking into account EB, EQLS and ISSP data. The utility of creating a crosswalk table is that the results of these decisions can be seen explicitly by comparing the value_code and target_value columns.

In particular, definitions of missing values differ across EB, EQLS and ISSP. Missing values are not harmonised but recoded into the single missing value “NA”.

Let’s look at the correspondence between h_ps_exer and qb1:

eb17_cwt %>% filter(var_source == "qb1") %>% 
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
var_source var_label_source npos value_n value_label_source value_code survey target_var target_value
qb1 SPORT ACTIVITY - FREQUENCY 1 [1] 5 times a week or more: 2244 [1] 5 times a week or more 1 EB h_ps_exer 1
qb1 SPORT ACTIVITY - FREQUENCY 2 [2] 3 to 4 times a week: 3101 [2] 3 to 4 times a week 2 EB h_ps_exer 2
qb1 SPORT ACTIVITY - FREQUENCY 3 [3] 1 to 2 times a week: 5114 [3] 1 to 2 times a week 3 EB h_ps_exer 3
qb1 SPORT ACTIVITY - FREQUENCY 4 [4] 1 to 3 times a month: 1360 [4] 1 to 3 times a month 4 EB h_ps_exer 4
qb1 SPORT ACTIVITY - FREQUENCY 5 [5] Less often: 3060 [5] Less often 5 EB h_ps_exer 5
qb1 SPORT ACTIVITY - FREQUENCY 6 [6] Never: 13093 [6] Never 6 EB h_ps_exer 6
qb1 SPORT ACTIVITY - FREQUENCY 7 [7] DK: 59 [7] DK 7 EB h_ps_exer NA
Optional

It might be useful to export the crosswalk table as a spreadsheet since it serves as a reference document that visualises the connection between the source and harmonised data set.

write.xlsx(eb17_cwt, paste("data/",  target_var_hrms, "_cwt_eb17.xlsx", sep = ''))

 

1.6. Recode survey data using the crosswalk table

To be able to merge survey data with the crosswalk table information, we first need to convert the wide data format to a long data format.

eb17_small_long <- eb17_small %>% 
  mutate(across(everything(), as.character)) %>% 
  pivot_longer(cols = c(qb1, isocntry),
               names_to = "var_source", values_to = "value_source") 

This is how the first six rows of the eb17_small_long should look like:

uniqid qb1r w3a caseid var_source value_source
16711728 2 1.3897 1 qb1 3
16711728 2 1.3897 1 isocntry BE
16708419 4 1.3138 2 qb1 6
16708419 4 1.3138 2 isocntry BE
16708417 4 1.5267 3 qb1 6
16708417 4 1.5267 3 isocntry BE

Now we use left_join() to recode source values according to the crosswalk table, eb17_cwt.

eb17_hrmsd <- eb17_small_long %>%
  left_join(eb17_cwt, by = c("value_source" = "value_code", "var_source")) %>%
  select(-c(npos, value_n)) %>%
  mutate(target_value = as.character(target_value)) %>%
  pivot_wider(
    id_cols = c(uniqid, w3a, caseid, survey),    
    names_from = target_var,      
    values_from = target_value        
  ) %>% pivot_longer(
    cols = all_of(target_var_hrms),
    names_to = "target_var", values_to = "target_value") %>%
  rename(caseID_source = uniqid)

Now, EB 2017 data is ready for harmonisation. This is how the first six rows of the eb17_hrmsd should look like:

caseID_source w3a caseid survey country_source target_var target_value
16711728 1.3897 1 EB BE h_ps_exer 3
16708419 1.3138 2 EB BE h_ps_exer 6
16708417 1.5267 3 EB BE h_ps_exer 6
16708415 1.6886 4 EB BE h_ps_exer 6
16707074 1.3717 5 EB BE h_ps_exer 1
16707061 1.3717 6 EB BE h_ps_exer 4
Optional

At this step, the prepared data can be exported as an Rdata file and saved for later re-use.

saveRDS(eb17_hrmsd, paste("data/",  target_var_hrms, "_eb17.rds", sep = ''))

 

2. Prepare Data: EB 2013

We will follow the same steps used for the EB 2017 item.

 

2.1. Import data

eb13 <- haven::read_sav("I:/Team_IntUm/Infra4NextGen/Survey_Programmes/Eurobarometer/data/ZA5877_v2-0-0.sav",
                       user_na=TRUE)
Check the source item

Use this output to compare it with your output. Check especially if the labels match.

attr(eb17$qd1, "label")
Warning: Unknown or uninitialised column: `qd1`.
NULL
eb13 %>% count(qd1)
# A tibble: 7 × 2
  qd1                            n
  <dbl+lbl>                  <int>
1 1 [5 times a week or more]  2524
2 2 [3 to 4 times a week]     3189
3 3 [1 to 2 times a week]     5170
4 4 [1 to 3 times a month]    1510
5 5 [Less often]              3587
6 6 [Never]                  11846
7 7 (NA) [DK]                   93

 

2.2. Create codebook

Protocol variables selected for this harmonisation are the source data’s country, weight, and ID variables.

codebook_eb13 <- create_codebook_short(eb13) %>%
  mutate(survey = "EB",
         target_var = ifelse(var_source == "isocntry", "country_source", NA),
         target_var = ifelse(var_source=="w3a","w2_poststr", target_var),
         target_var = ifelse(grepl("unified respondent number|Respondent's identification number|RESPONDENT ID", var_label_source, perl = TRUE), "caseID_source", target_var),
         target_var = ifelse(grepl("^SPORT ACTIVITY - FREQUENCY$", var_label_source), 
                             target_var_hrms, # Find NAME FOR THE TARGET VARIABLE to be harmonised
                             target_var),
         target_var = gsub(" ", "_", target_var),
         target_var = tolower(target_var))

The variable names which will be used in the harmonised data are listed under target_var.

var_source var_label_source survey target_var
uniqid UNIQUE RESPONDENT ID (CASEID BY TNS COUNTRY CODE) EB caseid_source
isocntry COUNTRY CODE - ISO 3166 EB country_source
qd1 SPORT ACTIVITY - FREQUENCY EB h_ps_exer
w3a WEIGHT RESULT FROM TARGET - UNITED GERMANY EB w2_poststr

 

2.3. Retrieve names of the chosen source variables

variables <- codebook_eb13 %>% drop_na(target_var) %>% pull(var_source)

The retrieved variables are: uniqid, isocntry, qd1, w3a.

 

2.4. Select a subset of the survey data containing only the chosen variables

eb13_small <- eb13 %>% select(all_of(variables)) %>% mutate(caseid = row_number()) # this will be used to link this data to the new ones.

You will see that the following data set is a subset of the EB 2013 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:

uniqid isocntry qd1 w3a caseid
1000001 BE 3 0.8415 1
1000002 BE 1 0.6015 2
1000003 BE 3 0.5410 3
1000004 BE 3 0.8415 4
1000005 BE 4 0.9136 5
1000006 BE 1 0.6015 6

 

2.5. Create a crosswalk table for the chosen variables

Similar to what was implemented in step 1.5, weight and ID variables are excluded from the crosswalk table. Only country and the substantive variable are used for creating the crosswalk table. Original codes for the country variable are preserved. For the substantive variable, “NA” is assigned to missing values; the other values are kept identical.

eb13_cwt <- create_cwt(eb13_small %>%
                        select(isocntry, qd1)) %>% 
  left_join(codebook_eb13, by=join_by(var_source, var_label_source)) %>%
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|NA|applicable|Can't choose|]DK|] DK|Na|Inap", value_label_source), #* CHECK
                               value_code, 
                               target_value),
         value_code = as.character(value_code)
  )
Important

The survey-specific missing values are recoded into the single missing value “NA”.

Let’s look at the correspondence between h_ps_exer and qd1:

eb13_cwt %>% filter(var_source == "qd1") %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
var_source var_label_source npos value_n value_label_source value_code survey target_var target_value
qd1 SPORT ACTIVITY - FREQUENCY 1 [1] 5 times a week or more: 2524 [1] 5 times a week or more 1 EB h_ps_exer 1
qd1 SPORT ACTIVITY - FREQUENCY 2 [2] 3 to 4 times a week: 3189 [2] 3 to 4 times a week 2 EB h_ps_exer 2
qd1 SPORT ACTIVITY - FREQUENCY 3 [3] 1 to 2 times a week: 5170 [3] 1 to 2 times a week 3 EB h_ps_exer 3
qd1 SPORT ACTIVITY - FREQUENCY 4 [4] 1 to 3 times a month: 1510 [4] 1 to 3 times a month 4 EB h_ps_exer 4
qd1 SPORT ACTIVITY - FREQUENCY 5 [5] Less often: 3587 [5] Less often 5 EB h_ps_exer 5
qd1 SPORT ACTIVITY - FREQUENCY 6 [6] Never: 11846 [6] Never 6 EB h_ps_exer 6
qd1 SPORT ACTIVITY - FREQUENCY 7 [7] DK: 93 [7] DK 7 EB h_ps_exer NA
Optional

It might be useful to export the crosswalk table as a spreadsheet since it serves as a reference document that visualises the connection between the source and harmonised data set.

write.xlsx(eb13_cwt, paste("data/",  target_var_hrms, "_cwt_eb13.xlsx", sep = ''))

 

2.6. Recode survey data using the crosswalk table

We first convert the wide data format to a long data format, and then merge survey data with the crosswalk table information.

eb13_small_long <- eb13_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(qd1, isocntry), , #*var_source_hrms
               names_to = "var_source", values_to = "value_source")

This is how the first six rows of the eb13_small_long should look like:

uniqid w3a caseid var_source value_source
1000001 0.8415 1 qd1 3
1000001 0.8415 1 isocntry BE
1000002 0.6015 2 qd1 1
1000002 0.6015 2 isocntry BE
1000003 0.541 3 qd1 3
1000003 0.541 3 isocntry BE

Now we use left_join() to recode source values according to the crosswalk table, eb13_cwt.

eb13_hrmsd <- eb13_small_long %>%
  left_join(eb13_cwt, by = c("value_source" = "value_code", "var_source")) %>%
  select(-c(npos, value_n)) %>%
  mutate(target_value = as.character(target_value)) %>%
  pivot_wider(
    id_cols = c(uniqid, w3a,caseid, survey),    # Columns to keep as unique identifiers
    names_from = target_var,      # Column that will become the new column names
    values_from = target_value         # Column containing the values for those new columns
  ) %>% pivot_longer(
    cols = all_of(target_var_hrms),
    names_to = "target_var", values_to = "target_value") %>%
  rename(caseID_source = uniqid)

EB 2013 data is ready for harmonisation. This is how the first six rows of the eb13_hrmsd should look like:

head(eb13_hrmsd) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
caseID_source w3a caseid survey country_source target_var target_value
1000001 0.8415 1 EB BE h_ps_exer 3
1000002 0.6015 2 EB BE h_ps_exer 1
1000003 0.541 3 EB BE h_ps_exer 3
1000004 0.8415 4 EB BE h_ps_exer 3
1000005 0.9136 5 EB BE h_ps_exer 4
1000006 0.6015 6 EB BE h_ps_exer 1
Optional

At this step, the prepared data can be exported as an Rdata file and saved for later re-use.

saveRDS(eb13_hrmsd, paste("data/",  target_var_hrms, "_eb13.rds", sep = ''))

 

3. Prepare Data: EB 2009

We will follow the same steps.

 

3.1. Import data

eb09 <- haven::read_sav("I:/Team_IntUm/Infra4NextGen/Survey_Programmes/Eurobarometer/data/ZA4977_v2-0-0.sav",
                       user_na=TRUE)
Check the source item

Use this output to compare it with your output. Check especially if the labels match.

attr(eb09$v282, "label")
[1] "QF1 SPORT ACTIVITY - FREQUENCY"
eb09 %>% count(v282)
# A tibble: 8 × 2
  v282                                   n
  <dbl+lbl>                          <int>
1 1 [5 times a week or more]          2681
2 2 [3 to 4 times a week]             2944
3 3 [1 to 2 times a week]             4664
4 4 [1 to 3 times a month]            1694
5 5 [Less often]                      4114
6 6 [Never]                          10589
7 7 (NA) [DK]                          102
8 9 (NA) [Inap. (not 1 to 30 in V6)]  3504

 

3.2. Create codebook

Protocol variables selected for this harmonisation are the source data’s country, weight, and ID variables. Note that two weight variables are selected for this data: “v8 - W1 WEIGHT RESULT FROM TARGET” and “v12 - W3 WEIGHT GERMANY”. For more information, please see section 7.2.

codebook_eb09 <- create_codebook_short(eb09) %>%
  mutate(survey = "EB",
         target_var = ifelse(var_source == "v7", "country_source", NA),
         target_var = ifelse(var_source == "v8" | var_source == "v12", var_source, target_var),
         target_var = ifelse(grepl("UNIQUE CASE ID", var_label_source, perl = TRUE), "caseID_source", target_var),
         target_var = ifelse(grepl("^QF1 SPORT ACTIVITY - FREQUENCY$", var_label_source), 
                             target_var_hrms, # Find NAME FOR THE TARGET VARIABLE to be harmonised
                             target_var),
         target_var = gsub(" ", "_", target_var),
         target_var = tolower(target_var))

The variable names which will be used in the harmonised data are listed under target_var.

var_source var_label_source survey target_var
v5 UNIQUE CASE ID (TNS COUNTRY ID + TNS INTERVIEW ID) EB caseid_source
v7 NATION - ALL SAMPLES ISO 3166 EB country_source
v8 W1 WEIGHT RESULT FROM TARGET EB v8
v12 W3 WEIGHT GERMANY EB v12
v282 QF1 SPORT ACTIVITY - FREQUENCY EB h_ps_exer

 

3.3. Retrieve names of the chosen source variables

variables <- codebook_eb09 %>% drop_na(target_var) %>% pull(var_source)

The retrieved variables are: v5, v7, v8, v12, v282.

 

3.4. Select a subset of the survey data containing only the chosen variables

eb09_small <- eb09 %>% select(all_of(variables)) %>% mutate(caseid = row_number()) # this will be used to link this data to the new ones.

You will see that the following data set is a subset of the EB 2009 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:

v5 v7 v8 v12 v282 caseid
1000001 BE 1.0178 0 3 1
1000002 BE 1.6065 0 5 2
1000003 BE 1.4197 0 6 3
1000004 BE 1.0178 0 5 4
1000005 BE 1.1857 0 1 5
1000006 BE 1.4452 0 5 6

 

3.5. Create a crosswalk table for the chosen variables

Similar to what was implemented in step 2.5, weight and ID variables are excluded from the crosswalk table, only country and the substantive variable are used for creating the crosswalk table. Original codes for the country variable are preserved. For the substantive variable, “NA” is assigned to missing values; the other values are kept identical.

eb09_cwt <- create_cwt(eb09_small %>%
                        select(v7, v282)) %>% 
  left_join(codebook_eb09, by=join_by(var_source, var_label_source)) %>%
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|NA|applicable|Can't choose|]DK|] DK|Na", value_label_source), #* CHECK
                               value_code, 
                               target_value),
         value_code = as.character(value_code)
  )
Important

The survey-specific missing values are recoded into the single missing value “NA”.

Let’s look at the correspondence between h_ps_exer and v282:

eb09_cwt %>% filter(var_source == "v282") %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
var_source var_label_source npos value_n value_label_source value_code survey target_var target_value
v282 QF1 SPORT ACTIVITY - FREQUENCY 1 [1] 5 times a week or more: 2681 [1] 5 times a week or more 1 EB h_ps_exer 1
v282 QF1 SPORT ACTIVITY - FREQUENCY 2 [2] 3 to 4 times a week: 2944 [2] 3 to 4 times a week 2 EB h_ps_exer 2
v282 QF1 SPORT ACTIVITY - FREQUENCY 3 [3] 1 to 2 times a week: 4664 [3] 1 to 2 times a week 3 EB h_ps_exer 3
v282 QF1 SPORT ACTIVITY - FREQUENCY 4 [4] 1 to 3 times a month: 1694 [4] 1 to 3 times a month 4 EB h_ps_exer 4
v282 QF1 SPORT ACTIVITY - FREQUENCY 5 [5] Less often: 4114 [5] Less often 5 EB h_ps_exer 5
v282 QF1 SPORT ACTIVITY - FREQUENCY 6 [6] Never: 10589 [6] Never 6 EB h_ps_exer 6
v282 QF1 SPORT ACTIVITY - FREQUENCY 7 [7] DK: 102 [7] DK 7 EB h_ps_exer NA
v282 QF1 SPORT ACTIVITY - FREQUENCY 8 [9] Inap. (not 1 to 30 in V6): 3504 [9] Inap. (not 1 to 30 in V6) 9 EB h_ps_exer 9
Optional

It might be useful to export the crosswalk table as a spreadsheet since it serves as a reference document that visualises the connection between the source and harmonised data set.

write.xlsx(eb09_cwt, paste("data/",  target_var_hrms, "_cwt_eb09.xlsx", sep = ''))

 

3.6. Recode survey data using the crosswalk table

We first convert the wide data format to a long data format, and then merge survey data with the crosswalk table information.

eb09_small_long <- eb09_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(v282, v7), #*var_source_hrms
               names_to = "var_source", values_to = "value_source")

This is how the first six rows of the eb09_small_long should look like:

v5 v8 v12 caseid var_source value_source
1000001 1.0178 0 1 v282 3
1000001 1.0178 0 1 v7 BE
1000002 1.6065 0 2 v282 5
1000002 1.6065 0 2 v7 BE
1000003 1.4197 0 3 v282 6
1000003 1.4197 0 3 v7 BE

Now we use left_join() to recode source values according to the crosswalk table, eb09_cwt.

eb09_hrmsd <- eb09_small_long %>%
  left_join(eb09_cwt, by = c("value_source" = "value_code", "var_source")) %>%
  select(-c(npos, value_n)) %>%
  mutate(target_value = as.character(target_value)) %>%
  pivot_wider(
    id_cols = c(v5, v8, v12, caseid, survey),    # Columns to keep as unique identifiers
    names_from = target_var,      # Column that will become the new column names
    values_from = target_value         # Column containing the values for those new columns
  ) %>% pivot_longer(
    cols =all_of(target_var_hrms),
    names_to = "target_var", values_to = "target_value") %>%
  rename(caseID_source = v5)

EB 2009 data is ready for harmonisation. This is how the first six rows of the eb09_hrmsd should look like:

head(eb09_hrmsd) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
caseID_source v8 v12 caseid survey country_source target_var target_value
1000001 1.0178 0 1 EB BE h_ps_exer 3
1000002 1.6065 0 2 EB BE h_ps_exer 5
1000003 1.4197 0 3 EB BE h_ps_exer 6
1000004 1.0178 0 4 EB BE h_ps_exer 5
1000005 1.1857 0 5 EB BE h_ps_exer 1
1000006 1.4452 0 6 EB BE h_ps_exer 5
Optional

At this step, the prepared data can be exported as an Rdata file and saved for later re-use.

saveRDS(eb09_hrmsd, paste("data/",  target_var_hrms, "_eb09.rds", sep = ''))

4. Prepare Data: EB 2004

We will follow the same steps used for the EB 2009 item.  

4.1. Import data

eb04 <- haven::read_sav("I:/Team_IntUm/Infra4NextGen/Survey_Programmes/Eurobarometer/data/ZA4229_v1-1-0.sav",
                       user_na=TRUE)
Check the source item

Use this output to compare it with your output. Check especially if the labels match.

attr(eb04$v362, "label")
[1] "Q48 SPORT ACTIVITY: FREQUENCY"
eb04 %>% count(v362)
# A tibble: 7 × 2
  v362                                n
  <dbl+lbl>                       <int>
1 1 [3 times a week or more]       4347
2 2 [1 to 2 times a week]          4880
3 3 [1 to 3 times a month]         1847
4 4 [Less often]                   3622
5 5 [Never]                        9985
6 6 (NA) [DK]                       110
7 9 (NA) [Inap. (29 to 33 in V6)]  4543

 

4.2. Create codebook

Protocol variables selected for this harmonisation are the source data’s country, weight, and ID variables. Note that two weight variables are selected also for this data: “v8 - W1 WEIGHT RESULT FROM TARGET” and “v12 - W3 WEIGHT GERMANY”. For more information, please see section 7.2.

codebook_eb04 <- create_codebook_short(eb04) %>%
  mutate(survey = "EB",
         target_var = ifelse(var_source == "v7", "country_source", NA),
         target_var = ifelse(var_source == "v8" | var_source == "v12", var_source, target_var),
         target_var = ifelse(grepl("ORIGINAL RESPONDENT ID", var_label_source, perl = TRUE), "caseID_source", target_var),
         target_var = ifelse(var_source == "capi_cawi", "mode", target_var),
         target_var = ifelse(grepl("SPORT ACTIVITY: FREQUENCY", var_label_source), 
                             target_var_hrms, # Find NAME FOR THE TARGET VARIABLE to be harmonised
                             target_var),
         target_var = gsub(" ", "_", target_var),
         target_var = tolower(target_var))

The variable names which will be used in the harmonised data are listed under target_var.

var_source var_label_source survey target_var
v7 NATION - ALL SAMPLES ISO 3166 EB country_source
v8 W1 WEIGHT RESULT FROM TARGET EB v8
v12 W3 WEIGHT SPECIAL GERMANY EB v12
v362 Q48 SPORT ACTIVITY: FREQUENCY EB h_ps_exer
v541 ORIGINAL RESPONDENT ID EB caseid_source

  4.3. Retrieve names of the chosen source variables

variables <- codebook_eb04 %>% drop_na(target_var) %>% pull(var_source)

The retrieved variables are: v7, v8, v12, v362, v541.  

4.4. Select a subset of the survey data containing only the chosen variables

eb04_small <- eb04 %>% select(all_of(variables)) %>% mutate(caseid = row_number()) # this will be used to link this data to the new ones.

You will see that the following data set is a subset of the EB 2004 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:

v7 v8 v12 v362 v541 caseid
BE 1.0901 0 4 1000001 1
BE 1.0901 0 2 1000002 2
BE 0.8159 0 3 1000003 3
BE 0.6009 0 4 1000004 4
BE 0.7945 0 5 1000005 5
BE 1.2724 0 5 1000006 6

 

4.5. Create a crosswalk table for the chosen variables

Similar to what was implemented in step 3.5, weight and ID variables are excluded from the crosswalk table. Only country and the substantive variable are used for creating the crosswalk table. Original codes for the country variable are preserved. For the substantive variable, “NA” is assigned to missing values; the other values are kept identical.

eb04_cwt <- create_cwt(eb04_small %>%
                        select(v7, v362)) %>% 
  left_join(codebook_eb04, by=join_by(var_source, var_label_source)) %>%
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|NA|applicable|Can't choose|]DK|] DK|Na", value_label_source), #* CHECK
                               value_code, 
                               target_value),
         value_code = as.character(value_code)
  )
Important

The survey-specific missing values are recoded into the single missing value “NA”.

Let’s look at the correspondence between h_ps_exer and v362:

eb04_cwt %>% filter(var_source == "v362") %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
var_source var_label_source npos value_n value_label_source value_code survey target_var target_value
v362 Q48 SPORT ACTIVITY: FREQUENCY 1 [1] 3 times a week or more: 4347 [1] 3 times a week or more 1 EB h_ps_exer 1
v362 Q48 SPORT ACTIVITY: FREQUENCY 2 [2] 1 to 2 times a week: 4880 [2] 1 to 2 times a week 2 EB h_ps_exer 2
v362 Q48 SPORT ACTIVITY: FREQUENCY 3 [3] 1 to 3 times a month: 1847 [3] 1 to 3 times a month 3 EB h_ps_exer 3
v362 Q48 SPORT ACTIVITY: FREQUENCY 4 [4] Less often: 3622 [4] Less often 4 EB h_ps_exer 4
v362 Q48 SPORT ACTIVITY: FREQUENCY 5 [5] Never: 9985 [5] Never 5 EB h_ps_exer 5
v362 Q48 SPORT ACTIVITY: FREQUENCY 6 [6] DK: 110 [6] DK 6 EB h_ps_exer NA
v362 Q48 SPORT ACTIVITY: FREQUENCY 7 [9] Inap. (29 to 33 in V6): 4543 [9] Inap. (29 to 33 in V6) 9 EB h_ps_exer 9
Optional

It might be useful to export the crosswalk table as a spreadsheet since it serves as a reference document that visualises the connection between the source and harmonised data set.

write.xlsx(eb04_cwt, paste("data/",  target_var_hrms, "_cwt_eb04.xlsx", sep = ''))

 

4.6. Recode survey data using the crosswalk table

We first convert the wide data format to a long data format, and then merge survey data with the crosswalk table information.

eb04_small_long <- eb04_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(v362, v7), 
               names_to = "var_source", values_to = "value_source")

This is how the first six rows of the eb04_small_long should look like:

v8 v12 v541 caseid var_source value_source
1.0901 0 1000001 1 v362 4
1.0901 0 1000001 1 v7 BE
1.0901 0 1000002 2 v362 2
1.0901 0 1000002 2 v7 BE
0.8159 0 1000003 3 v362 3
0.8159 0 1000003 3 v7 BE

Now we use left_join() to recode source values according to the crosswalk table, eb04_cwt.

eb04_hrmsd <- eb04_small_long %>%
  left_join(eb04_cwt, by = c("value_source" = "value_code", "var_source")) %>%
  select(-c(npos, value_n)) %>%
  mutate(target_value = as.character(target_value)) %>%
  pivot_wider(
    id_cols = c(v541,v12, v8, caseid, survey),    # Columns to keep as unique identifiers
    names_from = target_var,      # Column that will become the new column names
    values_from = target_value         # Column containing the values for those new columns
  ) %>% pivot_longer(
    cols = all_of(target_var_hrms),
    names_to = "target_var", values_to = "target_value") %>%
  rename(caseID_source = v541)

EB 2004 data is ready for harmonisation. This is how the first six rows of the eb04_hrmsd should look like:

head(eb04_hrmsd) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
caseID_source v12 v8 caseid survey country_source target_var target_value
1000001 0 1.0901 1 EB BE h_ps_exer 4
1000002 0 1.0901 2 EB BE h_ps_exer 2
1000003 0 0.8159 3 EB BE h_ps_exer 3
1000004 0 0.6009 4 EB BE h_ps_exer 4
1000005 0 0.7945 5 EB BE h_ps_exer 5
1000006 0 1.2724 6 EB BE h_ps_exer 5
Optional

At this step, the prepared data can be exported as an Rdata file and saved for later re-use.

saveRDS(eb04_hrmsd, paste("data/",  target_var_hrms, "_eb04.rds", sep = ''))

 

5. Prepare Data: EQLS

The EQLS dataset contains both 2012 and 2016 data, and the source variable is consistent across them. Therefore, the data preparation is carried out in a single step rather than in separate sections for each year.

5.1. Import data

eqls <- haven::read_sav("I:/Team_IntUm/Infra4NextGen/Survey_Programmes/EQLS/Data/eqls_integrated_trend_2003-2016.sav",
                         user_na=TRUE)
Check the source item

Use this output to compare it with your output. Check especially if the labels match.

attr(eqls$Y16_Q27c, "label")
[1] "Take part in sports or physical exercise"
eqls %>% count(Y16_Q27c, Wave)
# A tibble: 16 × 3
   Y16_Q27c                           Wave                    n
   <dbl+lbl>                          <dbl+lbl>           <int>
 1  1 [Every day or almost every day] 3 [3rd EQLS (2011)]  6361
 2  1 [Every day or almost every day] 4 [4th EQLS (2016)]  5310
 3  2 [At least once a week]          3 [3rd EQLS (2011)]  9171
 4  2 [At least once a week]          4 [4th EQLS (2016)]  8090
 5  3 [One to three times a month]    3 [3rd EQLS (2011)]  3361
 6  3 [One to three times a month]    4 [4th EQLS (2016)]  3121
 7  4 [Less often]                    3 [3rd EQLS (2011)]  6420
 8  4 [Less often]                    4 [4th EQLS (2016)]  5475
 9  5 [Never]                         3 [3rd EQLS (2011)] 18198
10  5 [Never]                         4 [4th EQLS (2016)] 14749
11 98 (NA) [Don't know]               3 [3rd EQLS (2011)]    86
12 98 (NA) [Don't know]               4 [4th EQLS (2016)]    61
13 99 (NA) [Refusal]                  3 [3rd EQLS (2011)]    39
14 99 (NA) [Refusal]                  4 [4th EQLS (2016)]   102
15 NA                                 1 [1st EQLS (2003)] 26257
16 NA                                 2 [2nd EQLS (2007)] 35634

Note that this item was not administered in 2003 and 2007. Those cases are excluded while subsetting the data in section 5.4).

 

5.2. Create codebook

Protocol variables selected for this harmonisation are the source data’s country, weight, and ID variables.

codebook_eqls <- create_codebook_short(eqls) %>%
  mutate(survey = "EQLS",
         target_var = ifelse(var_source == "Y16_Country", "country_source", NA),
         target_var = ifelse(var_source=="WCalib","w2_poststr" , target_var),
         target_var = ifelse(grepl("unified respondent number|Respondent's identification number|respondent ID", var_label_source, perl = TRUE), "caseID_source", target_var),
         target_var = ifelse(var_source == "Wave", "wave", target_var),
         target_var = ifelse(grepl("Take part in sports or physical exercise", var_label_source), 
                             target_var_hrms, # Find NAME FOR THE TARGET VARIABLE to be harmonised
                             target_var),
         target_var = gsub(" ", "_", target_var),
         target_var = tolower(target_var))

The variable names which will be used in the harmonised data are listed under target_var.

var_source var_label_source survey target_var
Y16_uniqueid Unique respondent ID EQLS caseid_source
Wave EQLS Wave EQLS wave
Y16_Country Country EQLS country_source
WCalib Standardised Final Calibration weight for within country metrics and comparsions between any individual countries EQLS w2_poststr
Y16_Q27c Take part in sports or physical exercise EQLS h_ps_exer

 

5.3. Retrieve names of the chosen source variables

variables <- codebook_eqls %>% drop_na(target_var) %>% pull(var_source)

The retrieved variables are: Y16_uniqueid, Wave, Y16_Country, WCalib, Y16_Q27c.

 

5.4. Select a subset of the survey data containing only the chosen variables

eqls_small <- eqls %>%  select(all_of(variables)) %>%
  filter(Wave %in% c(3, 4)) %>%  # only wave 3 and 4 are included.
  mutate(caseid = row_number()) # this will be used to link this data to the new ones.

You will see that the following data set is a subset of the EQLS with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:

Y16_uniqueid Wave Y16_Country WCalib Y16_Q27c caseid
AT1000001 3 1 0.348660 5 1
AT1000102 3 1 0.949866 3 2
AT1000304 3 1 0.782841 2 3
AT1000607 3 1 0.386083 1 4
AT1000708 3 1 0.394896 3 5
AT1000809 3 1 0.925379 5 6

 

5.5. Create a crosswalk table for the chosen variables

Similar to what was implemented in step 4.5, weight and ID variables are excluded from the crosswalk table. Only country and the substantive variable are used for creating the crosswalk table. Original codes for the country variable are preserved. For the substantive variable, “NA” is assigned to missing values; the other values are kept identical.

eqls_cwt <- create_cwt(eqls_small %>%
                        select(Y16_Country, Y16_Q27c)) %>% 
  left_join(codebook_eqls, by=join_by(var_source, var_label_source)) %>%
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|NA|applicable|Can't choose|]DK|] DK|Na", value_label_source),
                               value_code, 
                               target_value),
         value_code = as.character(value_code)
  )
Important

The survey-specific missing values are recoded into the single missing value “NA”.

Let’s look at the correspondence between h_ps_exer and Y16_Q27c:

eqls_cwt %>% filter(var_source == "Y16_Q27c") %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
var_source var_label_source npos value_n value_label_source value_code survey target_var target_value
Y16_Q27c Take part in sports or physical exercise 1 [1] Every day or almost every day: 11671 [1] Every day or almost every day 1 EQLS h_ps_exer 1
Y16_Q27c Take part in sports or physical exercise 2 [2] At least once a week: 17261 [2] At least once a week 2 EQLS h_ps_exer 2
Y16_Q27c Take part in sports or physical exercise 3 [3] One to three times a month: 6482 [3] One to three times a month 3 EQLS h_ps_exer 3
Y16_Q27c Take part in sports or physical exercise 4 [4] Less often: 11895 [4] Less often 4 EQLS h_ps_exer 4
Y16_Q27c Take part in sports or physical exercise 5 [5] Never: 32947 [5] Never 5 EQLS h_ps_exer 5
Y16_Q27c Take part in sports or physical exercise 6 [98] Don't know: 147 [98] Don't know 98 EQLS h_ps_exer NA
Y16_Q27c Take part in sports or physical exercise 7 [99] Refusal: 141 [99] Refusal 99 EQLS h_ps_exer NA
Optional

It might be useful to export the crosswalk table as a spreadsheet since it serves as a reference document that visualises the connection between the source and harmonised data set.

write.xlsx(eqls_cwt, paste("data/",  target_var_hrms, "_cwt_eqls.xlsx", sep = ''))

 

5.6. Recode survey data using the crosswalk table

We first convert the wide data format to a long data format, and then merge survey data with the crosswalk table information.

eqls_small_long <- eqls_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(Y16_Q27c, Y16_Country),
               names_to = "var_source", values_to = "value_source")

This is how the first six rows of the eqls_small_long should look like:

Y16_uniqueid Wave WCalib caseid var_source value_source
AT1000001 3 0.34866 1 Y16_Q27c 5
AT1000001 3 0.34866 1 Y16_Country 1
AT1000102 3 0.949866 2 Y16_Q27c 3
AT1000102 3 0.949866 2 Y16_Country 1
AT1000304 3 0.782841 3 Y16_Q27c 2
AT1000304 3 0.782841 3 Y16_Country 1

Now we use left_join() to recode source values according to the crosswalk table, eqls_cwt.

eqls_hrmsd <- eqls_small_long %>%
  left_join(eqls_cwt, by = c("value_source" = "value_code", "var_source")) %>%
  select(-c(npos, value_n)) %>%
  mutate(target_value = as.character(target_value)) %>%
  pivot_wider(
    id_cols = c(Y16_uniqueid, WCalib, caseid, survey, Wave),    # Columns to keep as unique identifiers
    names_from = target_var,      # Column that will become the new column names
    values_from = target_value         # Column containing the values for those new columns
  ) %>% pivot_longer(
    cols =all_of(target_var_hrms),
    names_to = "target_var", values_to = "target_value") %>%
  rename(caseID_source = Y16_uniqueid)

EQLS data is ready for harmonisation. This is how the first six rows of the eqls_hrmsd should look like:

head(eqls_hrmsd) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
caseID_source WCalib caseid survey Wave country_source target_var target_value
AT1000001 0.34866 1 EQLS 3 1 h_ps_exer 5
AT1000102 0.949866 2 EQLS 3 1 h_ps_exer 3
AT1000304 0.782841 3 EQLS 3 1 h_ps_exer 2
AT1000607 0.386083 4 EQLS 3 1 h_ps_exer 1
AT1000708 0.394896 5 EQLS 3 1 h_ps_exer 3
AT1000809 0.925379 6 EQLS 3 1 h_ps_exer 5
Optional

At this step, the prepared data can be exported as an Rdata file and saved for later re-use.

saveRDS(eqls_hrmsd, paste("data/",  target_var_hrms, "_eqls.rds", sep = ''))

 

6. Prepare Data: ISSP 2007

We apply the same procedure as outlined above, while accounting for differences across EB, EQLS, and ISSP.

 

6.1. Import data

issp0 <- haven::read_sav("data/ZA4850_v2-0-0.sav", user_na=TRUE)
Check the source item

Use this output to compare it with your output. Check especially if the labels match.

attr(issp0$V15, "label")
[1] "Q1j Frequency of free time activities: Sports, Gym"
issp0 %>% count(V15)
# A tibble: 7 × 2
  V15                                        n
  <dbl+lbl>                              <int>
1 1 [Daily]                               7353
2 2 [Several times a week]               12434
3 3 [Several times a month]               9018
4 4 [Several times a year or less often]  5964
5 5 [Never]                              14440
6 8 (NA) [Can´t choose]                     85
7 9 (NA) [NA]                              435

 

6.2. Create codebook

Protocol variables selected for this harmonisation are the source data’s country, weight, and ID variables.

codebook_issp <- create_codebook_short(issp0) %>%
  mutate(
    survey = "ISSP",
    target_var = ifelse(var_source == "V4", "country_source", NA),
    target_var = ifelse(var_source == "WEIGHT", "w2_poststr", target_var),
    target_var = ifelse(grepl("ID Number", var_label_source), "caseID_source", target_var),
    target_var = ifelse(
      grepl("Frequency of free time activities: Sports, Gym", var_label_source),
      target_var_hrms,
      target_var
    ),
    target_var = gsub(" ", "_", target_var),
    target_var = tolower(target_var)
  )

The variable names which will be used in the harmonised data are listed under target_var. The same names are used.

var_source var_label_source survey target_var
V3 Respondent ID Number ISSP caseid_source
V4 Country/Sample (see V5 for codes for whole nation states) ISSP country_source
V15 Q1j Frequency of free time activities: Sports, Gym ISSP h_ps_exer
WEIGHT Weighting factor ISSP w2_poststr

 

6.3. Retrieve names of the chosen source variables

variables <- codebook_issp %>% drop_na(target_var) %>% pull(var_source)

The retrieved variables are: V3, V4, V15, WEIGHT.

 

6.4. Select a subset of the survey data containing only the chosen variables

# Correct Duplicated IDs
issp <- subset(issp0, !(V5 == 372 & V3 %in% c(5421, 6523, 6909)))
issp_small <- issp %>% select(all_of(variables)) %>% mutate(caseid = row_number())

You will see that the following data set is a subset of the ISSP 2007 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:

V3 V4 V15 WEIGHT caseid
2 32 5 1 1
4 32 2 1 2
6 32 3 1 3
8 32 2 1 4
10 32 2 1 5
12 32 5 1 6

 

6.5. Create a crosswalk table for the chosen variables

Similar to what was implemented in step 1.5, weight and ID variables are excluded from the crosswalk table, only country and the substantive variable are used for creating the crosswalk table. Original codes for the country variable are preserved. For the substantive variable, “NA” is assigned to missing values; the other values are kept identical.

issp_cwt <- create_cwt(issp_small %>% select(V4,V15)) %>%
  left_join(codebook_issp, by=join_by(var_source, var_label_source)) %>% 
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|applicable|Can't choose|Cant Choose|]DK|] DK|NA|Can´t choose", value_label_source), #* CHECK
                               value_code, 
                               target_value),
         value_code = as.character(value_code)
  )
Important

The survey-specific missing values are recoded into the single missing value “NA”.

Let’s look at the correspondence between h_ps_exer and V15:

issp_cwt %>% filter(var_source == "V15") %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
var_source var_label_source npos value_n value_label_source value_code survey target_var target_value
V15 Q1j Frequency of free time activities: Sports, Gym 1 [1] Daily: 7352 [1] Daily 1 ISSP h_ps_exer 1
V15 Q1j Frequency of free time activities: Sports, Gym 2 [2] Several times a week: 12434 [2] Several times a week 2 ISSP h_ps_exer 2
V15 Q1j Frequency of free time activities: Sports, Gym 3 [3] Several times a month: 9018 [3] Several times a month 3 ISSP h_ps_exer 3
V15 Q1j Frequency of free time activities: Sports, Gym 4 [4] Several times a year or less often: 5964 [4] Several times a year or less often 4 ISSP h_ps_exer 4
V15 Q1j Frequency of free time activities: Sports, Gym 5 [5] Never: 14438 [5] Never 5 ISSP h_ps_exer 5
V15 Q1j Frequency of free time activities: Sports, Gym 6 [8] Can´t choose: 85 [8] Can´t choose 8 ISSP h_ps_exer NA
V15 Q1j Frequency of free time activities: Sports, Gym 7 [9] NA: 435 [9] NA 9 ISSP h_ps_exer NA
Optional

It might be useful to export the crosswalk table as a spreadsheet since it serves as a reference document that visualises the connection between the source and harmonised data set.

write.xlsx(issp_cwt, paste("data/",  target_var_hrms, "_cwt_issp.xlsx", sep = ''))

 

6.6. Recode survey data using the crosswalk table

We first convert the wide data format to a long data format, and then merge survey data with the crosswalk table information.

issp_small_long <- issp_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(V15, V4),
               names_to = "var_source", values_to = "value_source")

This is how the first six rows of the issp_small_long should look like:

V3 WEIGHT caseid var_source value_source
2 1 1 V15 5
2 1 1 V4 32
4 1 2 V15 2
4 1 2 V4 32
6 1 3 V15 3
6 1 3 V4 32

Now we use left_join() to recode source values according to the crosswalk table, issp_cwt.

issp_hrmsd <- issp_small_long %>%
  left_join(issp_cwt, by = c("value_source" = "value_code", "var_source")) %>% 
  select(-c(npos, value_n)) %>% 
  mutate(target_value = as.character(target_value)) %>% 
  pivot_wider(
    id_cols = c(V3, WEIGHT, caseid, survey),    # Columns to keep as unique identifiers
    names_from = target_var,      # Column that will become the new column names
    values_from = target_value         # Column containing the values for those new columns
  ) %>% pivot_longer(
    cols = all_of(target_var_hrms), 
    names_to = "target_var", values_to = "target_value") %>% 
  rename(caseID_source = V3)

ISSP 2007 data is ready for harmonisation. This is how the first six rows of the issp_hrmsd should look like:

head(issp_hrmsd) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
caseID_source WEIGHT caseid survey country_source target_var target_value
2 1 1 ISSP 32 h_ps_exer 5
4 1 2 ISSP 32 h_ps_exer 2
6 1 3 ISSP 32 h_ps_exer 3
8 1 4 ISSP 32 h_ps_exer 2
10 1 5 ISSP 32 h_ps_exer 2
12 1 6 ISSP 32 h_ps_exer 5
Optional

At this step, the prepared data can be exported as an Rdata file and saved for later re-use.

saveRDS(issp_hrmsd, paste("data/",  target_var_hrms, "_issp.rds", sep = ''))

 

7. Harmonisation

With the following steps, we will create the harmonised Frequency of Physical Exercise data.

 

7.1. Standardise country names & apply labels

There are functions specifically written to standardise country names and apply labels. Please download the R file containing these functions here . Then save this file in the R project folder and import it into the R project via source("func_recoded_country.R").

How-to

If you cannot download the R-file, please open a new file in your R-Studio project under File -> New File -> R Script and copy the text from the func_recoded_country-file into this new file. Make sure that you save this new file in your project folder under the name “func_recoded_country.R”.

source("func_recoded_country.R")
eb04_1 <- eb04_hrmsd %>%
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

eb09_1 <- eb09_hrmsd %>%
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

eb13_1 <- eb13_hrmsd %>%
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

eb17_1 <- eb17_hrmsd %>%
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

eqls_1 <- eqls_hrmsd %>% 
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

Unlike the other datasets, the country labels must be explicitly specified for the ISSP 2007 data.

country_labels <- c(
  "32" = "AR",
  "36" = "AU",
  "40" = "AT",
  "56.1" = "BE_FLA",
  "100" = "BG",
  "152" = "CL",
  "158" = "TW",
  "191" = "HR",
  "196" = "CY",
  "203" = "CZ",
  "214" = "DO",
  "246" = "FI",
  "250" = "FR",
  "276.1" = "DE_W",
  "276.2" = "DE_E",
  "348" = "HU",
  "372" = "IE",
  "376.1" = "IL_J",
  "376.2" = "IL_A",
  "392" = "JP",
  "410" = "KR",
  "428" = "LV",
  "484" = "MX",
  "554" = "NZ",
  "578" = "NO",
  "608" = "PH",
  "616" = "PL",
  "643" = "RU",
  "703" = "SK",
  "705" = "SI",
  "710" = "ZA",
  "752" = "SE",
  "756" = "CH",
  "826.1" = "GB_GBN",
  "840" = "US",
  "858" = "UY"
)

issp_hrmsd$country_source <- as.character(issp_hrmsd$country_source) # Ensure country is a character before mapping
issp_hrmsd$country_source <- country_labels[issp_hrmsd$country_source]

issp_1 <- issp_hrmsd %>%
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")
Check

You can run the following code to check the country variable:

table(issp_hrmsd$country_source, issp_1$country_new)

 

7.2. Weights

For details on decisions and procedures for including weight variables, please see the Make It Healthy! data documentation page, section Weight Variables.

eb13 <- eb13_1 %>% mutate(w1_design = w3a,
                          w2_poststr = w3a, 
                          w3_combined = as.numeric(w2_poststr))

eb17 <- eb17_1 %>% mutate(w1_design = w3a,
                          w2_poststr = w3a, 
                          w3_combined = as.numeric(w2_poststr))

eqls <- eqls_1 %>% mutate(w1_design = WCalib,
                              w2_poststr = WCalib,
                              w3_combined = as.numeric(w2_poststr))

issp <- issp_1  %>% mutate(w1_design = WEIGHT,
                               w2_poststr = WEIGHT, 
                               w3_combined = as.numeric(w2_poststr))

Specific to the EB 2009 and EB 2004, they do not provide the weight variable treating Germany as united. We manually corrected for an unproportional East-West split in the German data by applying the provided weighting factor. The variables we used for this correction are “v8 - W1 WEIGHT RESULT FROM TARGET” and “v12 - W3 WEIGHT GERMANY”.

Check

You can run the following code to check:

head(eb09_1 %>% count(country_source, v12), n=10)
eb09_1 %>% group_by(country_source) %>% summarise(avr = mean(as.numeric(v8), na.rm=TRUE))
eb09_1 %>% group_by(country_source) %>% summarise(avr = mean(as.numeric(v12), na.rm=TRUE))
# v12 W3 WEIGHT GERMANY: this is only for DE-E and DE-W. The others are 0. 
eb_e <- eb09_1 %>% filter(country_source == "DE-E") %>%  mutate(v12 = as.numeric(v12))
avr_e_09<- mean(eb_e$v12)

eb_w <- eb09_1 %>% filter(country_source == "DE-W") %>% mutate(v12 = as.numeric(v12))
avr_w_09 <- mean(eb_w$v12)

# For DE-E ve DE-W; multiply v8 and mean(v12) to adjust unproportional sample size.
eb09 <- eb09_1 %>% mutate(w1de = as.character(case_when(country_source == 'DE-E' ~ as.numeric(v8)*avr_e_09,
                                                        country_source == 'DE-W' ~ as.numeric(v8)*avr_w_09,
                                                        TRUE ~ as.numeric(v8))),
                          w1_design = w1de,
                          w2_poststr = w1de,
                          w3_combined = as.numeric(w2_poststr))
Check

You can run the following code to check the new variable:

eb09 %>% filter(country_source %in% c("DE-E", "DE-W")) %>% group_by(country_source) %>% 
  summarise(avr = mean(as.numeric(w1de), na.rm=TRUE))
eb09 %>% filter(country_source %in% c("DE-E", "DE-W")) %>% summarise(avr = mean(as.numeric(w1de), na.rm=TRUE))

We apply the same East–West weight correction to EB 2004 after recoding the 0 values to 1.

# Cases with weight = 0 are coded to 1 [Number of cases: CY (1), CZ (6), SK (15)]
eb04_1$v8 <- ifelse(eb04_1$v8 == 0, 1, eb04_1$v8)

# v12 W3 WEIGHT GERMANY: this is only for DE-E and DE-W. The others are 0. 
eb_e <- eb04_1 %>% filter(country_source == "DE-E") %>% mutate(v12 = as.numeric(v12))
avr_e_04 <- mean(eb_e$v12)

eb_w <- eb04_1 %>% filter(country_source == "DE-W") %>% mutate(v12 = as.numeric(v12))
avr_w_04 <- mean(eb_w$v12)

# For DE-E ve DE-W; multiply v8 and mean(v12) to adjust unproportional sample size.
eb04 <- eb04_1 %>% mutate(w1de = as.character(case_when(country_source == 'DE-E' ~ as.numeric(v8)*avr_e_04,
                                                        country_source == 'DE-W' ~ as.numeric(v8)*avr_w_04,
                                                        TRUE ~ as.numeric(v8))),
                          w1_design = w1de,
                          w2_poststr = w1de,
                          w3_combined = as.numeric(w2_poststr))

 

7.3. Import additional information about the source data sets

This file, including additional information, can be downloaded here . Please save it into the “data” folder you generated previously.

add_data <- read_excel("data/from_doi_links_healthy.xlsx") %>% 
  select(-studyno_source)

 

7.4. Combine all data

commons <- c("caseID_source", "caseid", "survey", 
             "target_var","target_value","year", "country_new", "country_source_recoded",
             "w1_design", "w2_poststr", "w3_combined")

eb04$year <- "2004"
eb09$year <- "2009"
eb13$year <- "2013"
eb17$year <- "2017"
issp$year <- "2007"
eqls <- eqls %>% mutate(year = case_when(Wave == 3 ~ "2012", Wave == 4 ~ "2016"))


all_comb <- bind_rows(
  eb04[, commons],
  eb09[, commons],
  eb13[, commons],
  eb17[, commons],
  issp[, commons],
  eqls[, commons]
) %>%
  left_join(add_data, by = c("target_var", "survey", "year")) %>%
  mutate(
    ## variables To Be Added
    studyno_I4NG = NA,
    version_I4NG = NA,
    doi_I4NG = NA,
    caseID_I4NG = paste(survey, year, country_new, caseid, sep = ''),
    #country_year
    country_year = paste(country_new, year, sep = '_'),
    # caseID = NA,
    caseID = row_number(),
    
    # code the lengths of response scales in each project
    npoints = NA 
  ) %>%
  # Rename to avoid SPSS duplicate name error
  rename(caseid_sw = caseid, country_I4NG = country_new)
Check

Let’s check the data set:

head(all_comb) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
caseID_source caseid_sw survey target_var target_value year country_I4NG country_source_recoded w1_design w2_poststr w3_combined title_source wave doi_source studyno_I4NG version_I4NG doi_I4NG caseID_I4NG country_year caseID npoints
1000001 1 EB h_ps_exer 4 2004 BE BE 1.0901 1.0901 1.0901 Public Opinion in the European Union 62.0 https://doi.org/10.4232/1.10962 NA NA NA EB2004BE1 BE_2004 1 NA
1000002 2 EB h_ps_exer 2 2004 BE BE 1.0901 1.0901 1.0901 Public Opinion in the European Union 62.0 https://doi.org/10.4232/1.10962 NA NA NA EB2004BE2 BE_2004 2 NA
1000003 3 EB h_ps_exer 3 2004 BE BE 0.8159 0.8159 0.8159 Public Opinion in the European Union 62.0 https://doi.org/10.4232/1.10962 NA NA NA EB2004BE3 BE_2004 3 NA
1000004 4 EB h_ps_exer 4 2004 BE BE 0.6009 0.6009 0.6009 Public Opinion in the European Union 62.0 https://doi.org/10.4232/1.10962 NA NA NA EB2004BE4 BE_2004 4 NA
1000005 5 EB h_ps_exer 5 2004 BE BE 0.7945 0.7945 0.7945 Public Opinion in the European Union 62.0 https://doi.org/10.4232/1.10962 NA NA NA EB2004BE5 BE_2004 5 NA
1000006 6 EB h_ps_exer 5 2004 BE BE 1.2724 1.2724 1.2724 Public Opinion in the European Union 62.0 https://doi.org/10.4232/1.10962 NA NA NA EB2004BE6 BE_2004 6 NA
distinct(all_comb, target_var, survey, year)
# A tibble: 7 × 3
  target_var survey year 
  <chr>      <chr>  <chr>
1 h_ps_exer  EB     2004 
2 h_ps_exer  EB     2009 
3 h_ps_exer  EB     2013 
4 h_ps_exer  EB     2017 
5 h_ps_exer  ISSP   2007 
6 h_ps_exer  EQLS   2012 
7 h_ps_exer  EQLS   2016 

 

7.5. Find equivalents of the response categories

Response categories are harmonised to a five-point frequency scale:

  • 1: Every day/Almost every day, 2: At least once a week, 3: One to three times a month, 4: Less often, 5: Never.

Survey-specific recoding maps original categories onto this scale:

  • EB 2004: 1 and 2 into 1, 3 into 3, 4 into 4, 5 into 5.
  • EB 2009, 2013, and 2017 item: 1 into 1, 2 and 3 into 2, 4 into 3, 5 into 4 and 6 into 5.

The item is not administered in some countries (EB 2004: Bulgaria, Cyprus (TCC), Croatia, Romania, Türkiye; EB 2009: Cyprus (TCC), Croatia, North Macedonia, Türkiye). These cases are coded as -999.

The recoding schemes are implemented as follows:

scale_source_eb04 <- c(1, 2, 3, 4, 5, 9)  # EB 2004
scale_target_eb04 <- c(2, 2, 3, 4, 5, -999)


scale_source_eb <- c(1, 2, 3, 4, 5, 6, 9)  # EB 2009, 2013, 2017
scale_target_eb <- c(1, 2, 2, 3, 4, 5, -999)

In the subsequent step, EB item responses are recoded according to these mappings. No transformation is applied to EQLS or ISSP, as their response categories are already aligned with the harmonised scale.

 

7.6. Apply transformation

all_hrmsd <- all_comb %>%
  mutate(value_hrmsd = case_when(
    survey == "EB" & year == "2004" ~ as.numeric(plyr::mapvalues(target_value, 
                                                                 scale_source_eb04, 
                                                                 scale_target_eb04, warn_missing = FALSE)),
    survey == "EB" & year %in% c("2009", "2013", "2017") ~ as.numeric(plyr::mapvalues(target_value, 
                                                                                      scale_source_eb, 
                                                                                      scale_target_eb, warn_missing = FALSE)),
    survey == "EQLS" ~ as.numeric (target_value),
    survey == "ISSP" ~  as.numeric (target_value),
    TRUE ~ NA_real_
    )
  ) %>%
  rename(var_hrmsd = target_var) %>%
  select(-var_hrmsd, var_hrmsd, value_hrmsd, -caseID, caseID, -ends_with("_source"), ends_with("_source"), -target_value, -npoints) %>%
  pivot_wider(id_cols = c(doi_source, title_source, caseID_source, caseid_sw, survey, country_I4NG, country_source_recoded, year, country_year, w1_design, w2_poststr, w3_combined, caseID_I4NG),    
    names_from = var_hrmsd,      # Column that will become the new column names
    values_from = value_hrmsd # Column containing the values for those new columns
    )

Now the harmonised Frequency of Physical Exercise data are ready. This is how the first six rows of the all_hrmsd should look like:

doi_source title_source caseID_source caseid_sw survey country_I4NG country_source_recoded year country_year w1_design w2_poststr w3_combined caseID_I4NG h_ps_exer
https://doi.org/10.4232/1.10962 Public Opinion in the European Union 1000001 1 EB BE BE 2004 BE_2004 1.0901 1.0901 1.0901 EB2004BE1 4
https://doi.org/10.4232/1.10962 Public Opinion in the European Union 1000002 2 EB BE BE 2004 BE_2004 1.0901 1.0901 1.0901 EB2004BE2 2
https://doi.org/10.4232/1.10962 Public Opinion in the European Union 1000003 3 EB BE BE 2004 BE_2004 0.8159 0.8159 0.8159 EB2004BE3 3
https://doi.org/10.4232/1.10962 Public Opinion in the European Union 1000004 4 EB BE BE 2004 BE_2004 0.6009 0.6009 0.6009 EB2004BE4 4
https://doi.org/10.4232/1.10962 Public Opinion in the European Union 1000005 5 EB BE BE 2004 BE_2004 0.7945 0.7945 0.7945 EB2004BE5 5
https://doi.org/10.4232/1.10962 Public Opinion in the European Union 1000006 6 EB BE BE 2004 BE_2004 1.2724 1.2724 1.2724 EB2004BE6 5

 

7.7. Export data

# Rdata
saveRDS(all_hrmsd, paste("data/",  target_var_hrms, "_hrmsd.rds", sep = ''))

# SPSS file
write_sav(all_hrmsd, paste("data/",  target_var_hrms, "_hrmsd.sav", sep = ''))

# STATA file
write_dta(all_hrmsd, paste("data/",  target_var_hrms, "_hrmsd.dta", sep = ''))

# CSV file
write.csv(all_hrmsd, paste("data/",  target_var_hrms, "_hrmsd.csv", sep = ''), row.names = F, quote = T)

 

Summary

Frequency of Physical Exercise was administered in EB 2017, 2013, 2009, 2004, EQLS 2016, 2012 and ISSP 2007. Our script, first, prepares these two data sets for harmonisation so that they are consistent in format via codebooks and crosswalk tables. Then, the response categories are harmonised using the identity linking/linear stretch approach. After this step, the item is ready for subsequent analysis!

To go back to the Make it Healthy! Toolbox page, please click here!

Back to top

References

Kołczyńska, M. (2022). Combining multiple survey sources: A reproducible workflow and toolbox for survey data harmonization. Methodological Innovations, 15(1), 62–72. https://doi.org/10.1177/20597991221077923
R Core Team. (2024). R: A language and environment for statistical computing. R Foundation for Statistical Computing. https://www.R-project.org/
RStudio Team. (2023). RStudio: Integrated development environment for R. https://www.rstudio.com/

© EU Funded Project 101131118 — Infra4NextGen

 

Subject to Terms of Use | Privacy notice | Cookie policy | Built with R and Quarto