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 2003
  • 2. Prepare Data: ESS 2002
  • 3. Prepare Data: ISSP 2003
  • 4. Prepare Data: ISSP 2013
  • 5. Harmonisation
  • Summary

Immigrant Rights

This page guides you through the harmonisation process of the Immigrant Rights item.

The item was administered in EB 2003, ESS 2002 and ISSP 2003 and 2013. 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 Strong! data documentation page in the section devoted to Immigrant Rights. 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 ESS and EB 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 “s_mc_immi”. The name is a combination of “s” representing the main topic “Strong”, the concept “Migration and Social Cohesion” and the variable label “Immigrant Rights”.

target_var_hrms <- "s_mc_immi"

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

1. Prepare Data: EB 2003

Six steps must be carried out in the following section:

1.1 Import data

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

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

eb %>% count(v176)
# A tibble: 5 × 2
  v176                        n
  <dbl+lbl>               <int>
1 1 [Completely agree]     5025
2 2 [Tend to agree]        5707
3 3 [Tend to disagree]     3053
4 4 [Completely disagree]  1601
5 5 (NA) [DK]               775

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_eb <- create_codebook_short(eb) %>%
  mutate(survey = "EB",
         target_var = ifelse(var_source == "v7", "country_source", NA),
         target_var = ifelse(var_source == "v12", "w_poststr", target_var),
         target_var = ifelse(grepl("ORIGINAL RESPONDENT ID", var_label_source, perl = TRUE), "caseID_source", target_var),
         target_var = ifelse(grepl("IMMIGR VIEWS: LEGAL HAVE SAME RIGHTS", 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))

codebook_eb 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
v7 NATION - ALL SAMPLES ISO 3166 EB country_source
v12 W3 WEIGHT SPECIAL GERMANY EB w_poststr
v176 Q14 IMMIGR VIEWS: LEGAL HAVE SAME RIGHTS EB s_mc_immi
v580 ORIGINAL RESPONDENT ID EB caseid_source

 

1.3. Retrieve names of the chosen source variables

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

The retrieved variables are: v7, v12, v176, v580.

 

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

eb_small <- eb %>% select(all_of(variables)) %>% mutate(caseid = row_number())

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

v7 v12 v176 v580 caseid
BE 0.9258 2 15028 1
BE 0.9732 1 15029 2
BE 1.0828 3 15030 3
BE 0.9794 1 15031 4
BE 1.0912 3 15032 5
BE 0.9914 2 15044 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.

eb_cwt <- create_cwt(eb_small %>%
                        select(v7, v176)) %>%
  left_join(codebook_eb, by=join_by(var_source, var_label_source)) %>%
  mutate(target_value = NA,
         target_value = ifelse(!grepl("5] DK|know|efusal|answer|NA|applicable|Can't choose|Na|3] DK", 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, ESS 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, ESS and ISSP. Missing values are not harmonised but recoded into the single missing value “NA”.

Let’s look at the correspondence between s_mc_immi and v176:

eb_cwt %>% filter(var_source == "v176") %>% 
  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
v176 Q14 IMMIGR VIEWS: LEGAL HAVE SAME RIGHTS 1 [1] Completely agree: 5025 [1] Completely agree 1 EB s_mc_immi 1
v176 Q14 IMMIGR VIEWS: LEGAL HAVE SAME RIGHTS 2 [2] Tend to agree: 5707 [2] Tend to agree 2 EB s_mc_immi 2
v176 Q14 IMMIGR VIEWS: LEGAL HAVE SAME RIGHTS 3 [3] Tend to disagree: 3053 [3] Tend to disagree 3 EB s_mc_immi 3
v176 Q14 IMMIGR VIEWS: LEGAL HAVE SAME RIGHTS 4 [4] Completely disagree: 1601 [4] Completely disagree 4 EB s_mc_immi 4
v176 Q14 IMMIGR VIEWS: LEGAL HAVE SAME RIGHTS 5 [5] DK: 775 [5] DK 5 EB s_mc_immi 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(eb_cwt, paste("data/",  target_var_hrms, "_cwt_eb.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.

eb_small_long <- eb_small %>% 
  mutate(across(everything(), as.character)) %>% 
  pivot_longer(cols = c(v176, v7),
               names_to = "var_source", values_to = "value_source") 

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

v12 v580 caseid var_source value_source
0.9258 15028 1 v176 2
0.9258 15028 1 v7 BE
0.9732 15029 2 v176 1
0.9732 15029 2 v7 BE
1.0828 15030 3 v176 3
1.0828 15030 3 v7 BE

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

eb_hrmsd <- eb_small_long %>%
  left_join(eb_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(v12, v580 , caseid, survey),    # Columns to keep as unique identifiers   # WEIGHT SPECIAL GERMANY, rest of weight ( not must), ORIGINAL RESPONDENT ID,caseid, survey 
    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 = v580)

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

v12 caseID_source caseid survey country_source target_var target_value
0.9258 15028 1 EB BE s_mc_immi 2
0.9732 15029 2 EB BE s_mc_immi 1
1.0828 15030 3 EB BE s_mc_immi 3
0.9794 15031 4 EB BE s_mc_immi 1
1.0912 15032 5 EB BE s_mc_immi 3
0.9914 15044 6 EB BE s_mc_immi 2
Optional

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

saveRDS(eb_hrmsd, paste("data/",  target_var_hrms, "_eb.rds", sep = ''))

 

2. Prepare Data: ESS 2002

We will follow the same steps used for the EB 2003 item. As expected, ESS and EB data have differences, and they are taken into account in implementing these steps.

 

2.1. Import data

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

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

ess %>% count(imsmrgt)
# A tibble: 8 × 2
  imsmrgt                            n
  <dbl+lbl>                      <int>
1 1 [Agree strongly]              7409
2 2 [Agree]                      19662
3 3 [Neither agree nor disagree]  6669
4 4 [Disagree]                    6009
5 5 [Disagree strongly]           1499
6 7 (NA) [Refusal]                  26
7 8 (NA) [Don't know]              990
8 9 (NA) [No answer]                95

 

2.2. Create codebook

Protocol variables selected for this harmonisation are the source data’s country, weight, and ID variables. Note that there are two weight variables: design and post-stratification weights. Both of them are included.

codebook_ess <- create_codebook_short(ess) %>%
  mutate(survey = "ESS",
         target_var = ifelse(var_source == "cntry", "country_source", NA),
         target_var = ifelse(grepl("Design weight", var_label_source), "w1_design", target_var),
         target_var = ifelse(grepl("Post-stratification weight", var_label_source), "w2_poststr", target_var),
         target_var = ifelse(grepl("unified respondent number|Respondent's identification number|ID SERIAL NUMBER|RESPONDENT ID", var_label_source, perl = TRUE), "caseID_source", target_var),
         target_var = ifelse(grepl("Immigrants should be given same rights as everyone else", 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
idno Respondent's identification number ESS caseid_source
cntry Country ESS country_source
dweight Design weight ESS w1_design
pspwght Post-stratification weight including design weight ESS w2_poststr
imsmrgt Immigrants should be given same rights as everyone else ESS s_mc_immi

 

2.3. Retrieve names of the chosen source variables

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

The retrieved variables are: idno, cntry, dweight, pspwght, imsmrgt.

 

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

ess_small <- ess %>% select(all_of(variables)) %>% mutate(caseid = row_number())

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

idno cntry dweight pspwght imsmrgt caseid
1 AT 0.9452 0.9409328 1 1
2 AT 0.4726 0.4704664 1 2
3 AT 0.9452 1.3921549 2 3
4 AT 0.9452 1.3821629 1 4
6 AT 1.8905 1.4377663 8 5
7 AT 0.9452 1.3921549 1 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.

ess_cwt <- create_cwt(ess_small %>% 
                         select(cntry, imsmrgt)) %>%
  left_join(codebook_ess, 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 s_mc_immi and imsmrgt:

ess_cwt %>% filter(var_source == "imsmrgt") %>%
  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
imsmrgt Immigrants should be given same rights as everyone else 1 [1] Agree strongly: 7409 [1] Agree strongly 1 ESS s_mc_immi 1
imsmrgt Immigrants should be given same rights as everyone else 2 [2] Agree: 19662 [2] Agree 2 ESS s_mc_immi 2
imsmrgt Immigrants should be given same rights as everyone else 3 [3] Neither agree nor disagree: 6669 [3] Neither agree nor disagree 3 ESS s_mc_immi 3
imsmrgt Immigrants should be given same rights as everyone else 4 [4] Disagree: 6009 [4] Disagree 4 ESS s_mc_immi 4
imsmrgt Immigrants should be given same rights as everyone else 5 [5] Disagree strongly: 1499 [5] Disagree strongly 5 ESS s_mc_immi 5
imsmrgt Immigrants should be given same rights as everyone else 6 [7] Refusal: 26 [7] Refusal 7 ESS s_mc_immi NA
imsmrgt Immigrants should be given same rights as everyone else 7 [8] Don't know: 990 [8] Don't know 8 ESS s_mc_immi NA
imsmrgt Immigrants should be given same rights as everyone else 8 [9] No answer: 95 [9] No answer 9 ESS s_mc_immi 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(ess_cwt, paste("data/",  target_var_hrms, "_cwt_ess.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.

ess_small_long <- ess_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(imsmrgt, cntry),
               names_to = "var_source", values_to = "value_source")

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

idno dweight pspwght caseid var_source value_source
1 0.945200026035309 0.940932810306549 1 imsmrgt 1
1 0.945200026035309 0.940932810306549 1 cntry AT
2 0.472600013017654 0.470466405153275 2 imsmrgt 1
2 0.472600013017654 0.470466405153275 2 cntry AT
3 0.945200026035309 1.39215493202209 3 imsmrgt 2
3 0.945200026035309 1.39215493202209 3 cntry AT

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

ess_hrmsd <- ess_small_long %>%
  left_join(ess_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(dweight, pspwght, idno, 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 = idno) 

ESS 2002 data is ready for harmonisation. This is how the first six rows of the ess_hrmsd should look like:

head(ess_hrmsd) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
dweight pspwght caseID_source caseid survey country_source target_var target_value
0.945200026035309 0.940932810306549 1 1 ESS AT s_mc_immi 1
0.472600013017654 0.470466405153275 2 2 ESS AT s_mc_immi 1
0.945200026035309 1.39215493202209 3 3 ESS AT s_mc_immi 2
0.945200026035309 1.38216292858124 4 4 ESS AT s_mc_immi 1
1.89049994945526 1.43776631355286 6 5 ESS AT s_mc_immi NA
0.945200026035309 1.39215493202209 7 6 ESS AT s_mc_immi 1
Optional

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

saveRDS(ess_hrmsd, paste("data/",  target_var_hrms, "_ess.rds", sep = ''))

 

3. Prepare Data: ISSP 2003

We will follow the same steps used before. As expected, ISSP, ESS and EB data have differences, and they are taken into account in implementing these steps.

 

3.1. Import data

issp03 <- haven::read_sav("data/ZA3910_v2-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.

issp03 %>% count(v61)
# A tibble: 7 × 2
  v61                                n
  <dbl+lbl>                      <int>
1 1 [Agree strongly]              6262
2 2 [Agree]                      14559
3 3 [Neither agree nor disagree]  7592
4 4 [Disagree]                   10948
5 5 [Disagree strongly]           4012
6 8 (NA) [Can't choose]           2128
7 9 (NA) [NA]                      492

 

3.2. Create codebook

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

codebook_issp03 <- create_codebook_short(issp03) %>%
  mutate(survey = "ISSP",
         target_var = ifelse(var_source == "C_ALPHAN", "country_source", NA),
         target_var = ifelse(var_source == "weight", "w2_poststr", target_var),
         target_var = ifelse(grepl("Respondent Number", var_label_source), "caseID_source", target_var),
         target_var = ifelse(grepl("Q15c Legal immigrants", var_label_source), 
                             target_var_hrms, # 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. The same names are used.

var_source var_label_source survey target_var
V3 Respondent Number ISSP caseid_source
C_ALPHAN Sample Prefix ISO 3166 Code - alphanumeric ISSP country_source
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. ISSP s_mc_immi
weight Weighting factor ISSP w2_poststr

 

3.3. Retrieve names of the chosen source variables

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

The retrieved variables are: V3, C_ALPHAN, v61, weight.

 

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

issp03_small <- issp03 %>% select(all_of(variables)) %>% mutate(caseid = row_number())

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

V3 C_ALPHAN v61 weight caseid
1006001 AU 3 1 1
1006002 AU 2 1 2
1006003 AU 4 1 3
1006004 AU 4 1 4
1006005 AU 2 1 5
1006006 AU 4 1 6

 

3.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.

issp03_cwt <- create_cwt(issp03_small %>% 
                          select(C_ALPHAN, v61)) %>% 
  mutate(value_code = ifelse(grepl("C_ALPHAN.IL", value_code), value_label_source, value_code)) %>%
  left_join(codebook_issp03, by=join_by(var_source, var_label_source)) %>% 
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|NA|applicable|Can't choose|Cant Choose|]DK|] DK|Na|Cant 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 s_mc_immi and v61:

issp03_cwt %>% filter(var_source == "v61") %>%
  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
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. 1 [1] Agree strongly: 6262 [1] Agree strongly 1 ISSP s_mc_immi 1
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. 2 [2] Agree: 14559 [2] Agree 2 ISSP s_mc_immi 2
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. 3 [3] Neither agree nor disagree: 7592 [3] Neither agree nor disagree 3 ISSP s_mc_immi 3
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. 4 [4] Disagree: 10948 [4] Disagree 4 ISSP s_mc_immi 4
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. 5 [5] Disagree strongly: 4012 [5] Disagree strongly 5 ISSP s_mc_immi 5
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. 6 [8] Can't choose: 2128 [8] Can't choose 8 ISSP s_mc_immi NA
v61 Q15c Legal immigrants to [Country] who are not citizens should have the same rights as [Country Nationality] citizens. 7 [9] NA: 492 [9] NA 9 ISSP s_mc_immi 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(issp03_cwt, paste("data/",  target_var_hrms, "_cwt_issp03.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.

issp03_small_long <- issp03_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(v61, C_ALPHAN),
               names_to = "var_source", values_to = "value_source")

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

V3 weight caseid var_source value_source
1006001 1 1 v61 3
1006001 1 1 C_ALPHAN AU
1006002 1 2 v61 2
1006002 1 2 C_ALPHAN AU
1006003 1 3 v61 4
1006003 1 3 C_ALPHAN AU

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

issp03_hrmsd <- issp03_small_long %>%
  left_join(issp03_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(weight, V3, caseid, survey),    # Columns to keep as unique identifiers # WEIGHT , ORIGINAL RESPONDENT ID,caseid, survey 
    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 2003 data is ready for harmonisation. This is how the first six rows of the issp03_hrmsd should look like:

head(issp03_hrmsd) %>%
  kable(row.names = FALSE) %>%
  kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))
weight caseID_source caseid survey country_source target_var target_value
1 1006001 1 ISSP AU s_mc_immi 3
1 1006002 2 ISSP AU s_mc_immi 2
1 1006003 3 ISSP AU s_mc_immi 4
1 1006004 4 ISSP AU s_mc_immi 4
1 1006005 5 ISSP AU s_mc_immi 2
1 1006006 6 ISSP AU s_mc_immi 4
Optional

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

saveRDS(issp03_hrmsd, paste("data/",  target_var_hrms, "_issp03.rds", sep = ''))

 

4. Prepare Data: ISSP 2013

We will follow the same steps used before.

 

4.1. Import data

issp13 <- haven::read_sav("data/ZA5950_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.

issp13 %>% count(V53)
# A tibble: 7 × 2
  V53                                n
  <dbl+lbl>                      <int>
1 1 [Agree strongly]              4686
2 2 [Agree]                      13196
3 3 [Neither agree nor disagree]  8987
4 4 [Disagree]                   11251
5 5 [Disagree strongly]           4911
6 8 (NA) [Can't choose]           1858
7 9 (NA) [No answer]               408

 

4.2. Create codebook

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

codebook_issp13 <- create_codebook_short(issp13) %>%
  mutate(survey = "ISSP",
         target_var = ifelse(var_source == "C_ALPHAN", "country_source", NA),
         target_var = ifelse(var_source == "WEIGHT", "w2_poststr", target_var),
         target_var = ifelse(grepl("RESPONDENT ID|identi |RESPONDENT NUMBER|ID Number", var_label_source), "caseID_source", target_var),
         target_var = ifelse(grepl("Q9f Legal immigrants should have same rights", var_label_source), 
                             target_var_hrms, # 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. The same names are used.

var_source var_label_source survey target_var
C_ALPHAN Country/ Sample Prefix ISO 3166 code - alphanumeric ISSP country_source
V53 Q9f Legal immigrants should have same rights ISSP s_mc_immi
CASEID ID Number of Respondent ISSP caseid_source
WEIGHT Weight ISSP w2_poststr

 

4.3. Retrieve names of the chosen source variables

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

The retrieved variables are: C_ALPHAN, V53, CASEID, WEIGHT.

 

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

issp13_small <- issp13 %>% select(all_of(variables)) %>% mutate(caseid = row_number())

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

C_ALPHAN V53 CASEID WEIGHT caseid
TW 2 201301581000502 0.9257463 1
TW 4 201301581000504 0.8983557 2
TW 4 201301581000514 0.7975731 3
TW 4 201301581000515 0.9257463 4
TW 2 201301581000516 0.8374400 5
TW 2 201301581000519 0.9635107 6

 

4.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.

issp13_cwt <- create_cwt(issp13_small %>% 
                          select(C_ALPHAN, V53)) %>%
  left_join(codebook_issp13, by=join_by(var_source, var_label_source)) %>% 
  mutate(target_value = NA,
         target_value = ifelse(!grepl("know|efusal|answer|No answer|NA|applicable|Can't choose|Cant Choose|]DK|] DK|Na|CANT 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 s_mc_immi and V53:

issp13_cwt %>% filter(var_source == "V53") %>%
  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
V53 Q9f Legal immigrants should have same rights 1 [1] Agree strongly: 4686 [1] Agree strongly 1 ISSP s_mc_immi 1
V53 Q9f Legal immigrants should have same rights 2 [2] Agree: 13196 [2] Agree 2 ISSP s_mc_immi 2
V53 Q9f Legal immigrants should have same rights 3 [3] Neither agree nor disagree: 8987 [3] Neither agree nor disagree 3 ISSP s_mc_immi 3
V53 Q9f Legal immigrants should have same rights 4 [4] Disagree: 11251 [4] Disagree 4 ISSP s_mc_immi 4
V53 Q9f Legal immigrants should have same rights 5 [5] Disagree strongly: 4911 [5] Disagree strongly 5 ISSP s_mc_immi 5
V53 Q9f Legal immigrants should have same rights 6 [8] Can't choose: 1858 [8] Can't choose 8 ISSP s_mc_immi NA
V53 Q9f Legal immigrants should have same rights 7 [9] No answer: 408 [9] No answer 9 ISSP s_mc_immi 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(issp13_cwt, paste("data/",  target_var_hrms, "_cwt_issp13.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.

issp13_small_long <- issp13_small %>%
  mutate(across(everything(), as.character)) %>%
  pivot_longer(cols = c(V53, C_ALPHAN),
               names_to = "var_source", values_to = "value_source")

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

CASEID WEIGHT caseid var_source value_source
201301581000502 0.925746346545582 1 V53 2
201301581000502 0.925746346545582 1 C_ALPHAN TW
201301581000504 0.898355653574965 2 V53 4
201301581000504 0.898355653574965 2 C_ALPHAN TW
201301581000514 0.79757306883069 3 V53 4
201301581000514 0.79757306883069 3 C_ALPHAN TW

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

issp13_hrmsd <- issp13_small_long %>%
  left_join(issp13_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(CASEID, 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 = CASEID)

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

head(issp13_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
201301581000502 0.925746346545582 1 ISSP TW s_mc_immi 2
201301581000504 0.898355653574965 2 ISSP TW s_mc_immi 4
201301581000514 0.79757306883069 3 ISSP TW s_mc_immi 4
201301581000515 0.925746346545582 4 ISSP TW s_mc_immi 4
201301581000516 0.8374399756542 5 ISSP TW s_mc_immi 2
201301581000519 0.963510665374475 6 ISSP TW s_mc_immi 2
Optional

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

saveRDS(issp13_hrmsd, paste("data/",  target_var_hrms, "_issp13.rds", sep = ''))

 

5. Harmonisation

Linear stretch (de Jonge et al., 2014) or identity linking is used to harmonise items. Kolen & Brennan (2014) and Albano (2016) provide extensive information about identity linking as well as other methodological approaches. Interested users are encouraged to consult these sources for further details.

With the following steps, we will create the harmonised Immigrant Rights data.

 

5.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")
eb_1 <- eb_hrmsd %>% 
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

ess_1 <- ess_hrmsd %>% 
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

issp03_1 <- issp03_hrmsd %>% 
  recoded_country("country_source") %>%
  country_new_labels("country_new") %>%
  func_country_sample("country_source") %>%
  country_source_recoded_labels("country_source_recoded")

issp13_1 <- issp13_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(eb_hrmsd$country_source, eb_1$country_new)

 

5.2. Weights

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

eb_fnl <- eb_1 %>% mutate(w1_design = v12, 
                          w2_poststr = v12,
                          w3_combined = as.numeric(w2_poststr))

ess_fnl <- ess_1 %>% mutate(w1_design = dweight,
                            w2_poststr = pspwght, 
                            w3_combined = as.numeric(w2_poststr))

issp03_fnl <- issp03_1 %>%  mutate(w1_design = weight,
                                  w2_poststr = weight,
                                  w3_combined = as.numeric(w2_poststr))

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

 

5.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_strong.xlsx") %>%  
  select(-studyno_source, -wave)

 

5.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", "doi_source")

eb_fnl$year <- "2003"
ess_fnl$year <- "2002"
issp03_fnl$year <- "2003"
issp13_fnl$year <- "2013"

eb_fnl$doi_source <- "https://doi.org/10.4232/1.10956"
ess_fnl$doi_source <- "https://doi.org/10.21338/ess1e06_7"
issp03_fnl$doi_source <- "https://doi.org/10.4232/1.11449"
issp13_fnl$doi_source <- "https://doi.org/10.4232/1.12312"


all_comb <- bind_rows(
  eb_fnl[, commons],
  ess_fnl[, commons],
  issp03_fnl[, commons],
  issp13_fnl[, commons]
) %>%
  left_join(add_data, by = c("target_var", "survey", "year", "doi_source")) %>%  # Added doi_source to join
  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(),  # reassign caseID
    
    # code the lengths of response scales in each data
    npoints = case_when(survey %in% c("ISSP", "ESS") ~ 5, 
                        survey == "EB" ~ 4,
                        TRUE ~ NA_real_ 
                        )
    ) %>%
  # 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 doi_source title_source studyno_I4NG version_I4NG doi_I4NG caseID_I4NG country_year caseID npoints
15028 1 EB s_mc_immi 2 2003 BE BE 0.9258 0.9258 0.9258 https://doi.org/10.4232/1.10956 Consumer Protection NA NA NA EB2003BE1 BE_2003 1 4
15029 2 EB s_mc_immi 1 2003 BE BE 0.9732 0.9732 0.9732 https://doi.org/10.4232/1.10956 Consumer Protection NA NA NA EB2003BE2 BE_2003 2 4
15030 3 EB s_mc_immi 3 2003 BE BE 1.0828 1.0828 1.0828 https://doi.org/10.4232/1.10956 Consumer Protection NA NA NA EB2003BE3 BE_2003 3 4
15031 4 EB s_mc_immi 1 2003 BE BE 0.9794 0.9794 0.9794 https://doi.org/10.4232/1.10956 Consumer Protection NA NA NA EB2003BE4 BE_2003 4 4
15032 5 EB s_mc_immi 3 2003 BE BE 1.0912 1.0912 1.0912 https://doi.org/10.4232/1.10956 Consumer Protection NA NA NA EB2003BE5 BE_2003 5 4
15044 6 EB s_mc_immi 2 2003 BE BE 0.9914 0.9914 0.9914 https://doi.org/10.4232/1.10956 Consumer Protection NA NA NA EB2003BE6 BE_2003 6 4
distinct(all_comb, target_var, survey, year)
# A tibble: 4 × 3
  target_var survey year 
  <chr>      <chr>  <chr>
1 s_mc_immi  EB     2003 
2 s_mc_immi  ESS    2002 
3 s_mc_immi  ISSP   2003 
4 s_mc_immi  ISSP   2013 

 

5.5. Find equivalents of the response categories

transformation <- function(x, x_min, x_max, y_min, y_max){
  # rescale x from [x_min, x_max] to [y_min, y_max]
  ((x - x_min) / (x_max - x_min)) * (y_max - y_min) + y_min
}

scale_source_eb4 <- 1:4
scale_target_eb4 <- transformation(
   x = scale_source_eb4,
  x_min = min(scale_source_eb4), 
  x_max = max(scale_source_eb4),
  y_min = 1, y_max = 5
)

Equivalents of 1, 2, 3, 4 on the target scale are 1, 2.33, 3.67, 5. In the following step, EB item scores are recoded according to this correspondence between the source scale and the target scale.

 

5.6. Apply transformation

all_hrmsd <- all_comb %>%
  mutate(
    value_hrmsd = case_when(survey == "EB" & doi_source == "https://doi.org/10.4232/1.10956" ~ plyr::mapvalues(target_value,
                                                                                                               scale_source_eb4,
                                                                                                               scale_target_eb4),
                            # Keep 5-point scales unchanged
                            npoints == 5 ~ as.character(target_value)
                            )
  ) %>%
  rename(var_hrmsd = target_var) %>%
  select(
    -var_hrmsd, -value_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 Immigrant Rights 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 s_mc_immi
https://doi.org/10.4232/1.10956 Consumer Protection 15028 1 EB BE BE 2003 BE_2003 0.9258 0.9258 0.9258 EB2003BE1 2.33333333333333
https://doi.org/10.4232/1.10956 Consumer Protection 15029 2 EB BE BE 2003 BE_2003 0.9732 0.9732 0.9732 EB2003BE2 1
https://doi.org/10.4232/1.10956 Consumer Protection 15030 3 EB BE BE 2003 BE_2003 1.0828 1.0828 1.0828 EB2003BE3 3.66666666666667
https://doi.org/10.4232/1.10956 Consumer Protection 15031 4 EB BE BE 2003 BE_2003 0.9794 0.9794 0.9794 EB2003BE4 1
https://doi.org/10.4232/1.10956 Consumer Protection 15032 5 EB BE BE 2003 BE_2003 1.0912 1.0912 1.0912 EB2003BE5 3.66666666666667
https://doi.org/10.4232/1.10956 Consumer Protection 15044 6 EB BE BE 2003 BE_2003 0.9914 0.9914 0.9914 EB2003BE6 2.33333333333333

 

5.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

Immigrant Rights was administered in EB 2003, ESS 2002 and ISSP 2003 and 2013. 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 Strong! Toolbox page, please click here!

Back to top

References

Albano, A. D. (2016). equate: An R package for observed-score linking and equating. Journal of Statistical Software, 74(8), 1–36. https://doi.org/10.18637/jss.v074.i08
de Jonge, T., Veenhoven, R., & Arends, L. (2014). Homogenizing responses to different survey questions on the same topic: Proposal of a scale homogenization method using a reference distribution. Social Indicators Research, 117, 375–300. https://doi.org/10.1007/s11205-013-0335-6
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
Kolen, M. J., & Brennan, R. L. (2014). Test equating, scaling, and linking. Springer. https://doi.org/10.1007/978-1-4939-0317-7
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