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])Support for Homosexuals Adoption Rights
This page guides you through the harmonisation process of the Support for Homosexuals Adoption Rights item.
The item was administered in EVS 2008 and ESS 2016, 2018, 2020 and 2023. 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 Equal! data documentation page, in the section devoted to Support for Homosexuals Adoption 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.
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").
If you can not 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 “e_pc_adop”. The name is a combination of “e” representing the main topic “equal”, the concept “Parenthood, Children and Marriage” and the variable label “Support for Homosexuals Adoption Rights”.
target_var_hrms <- "e_pc_adop"Before we can harmonise any data, we need to prepare the source data sets:
1. Prepare Data: EVS 2008
Six steps must be carried out in the following coding section:
1.1 Import data
evs <- haven::read_sav("data/ZA4800_v5-0-0.sav", user_na=TRUE, encoding = "ISO-8859-1")Use this output to compare it with your output. Check especially if the labels match.
evs %>% count(v154)# A tibble: 8 × 2
v154 n
<dbl+lbl> <int>
1 -5 (NA) [other missing] 1
2 -2 (NA) [no answer] 581
3 -1 (NA) [don't know] 3522
4 1 [agree strongly] 4510
5 2 [agree] 9570
6 3 [agree nor disagree] 8884
7 4 [disagree] 17484
8 5 [disagree strongly] 21728
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_evs <- create_codebook_short(evs) %>%
mutate(survey = "EVS",
target_var = ifelse(var_source == "c_abrv", "country_source", NA),
target_var = ifelse(var_source == "weight_g", "w2_poststr", target_var),
target_var = ifelse(grepl("unified respondent number", var_label_source, perl = TRUE), "caseID_source", target_var),
target_var = ifelse(grepl("homosexual couples - adopt children", 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))codebook_evs 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 |
|---|---|---|---|
| id_cocas | unified respondent number | EVS | caseid_source |
| c_abrv | country abbreviation | EVS | country_source |
| weight_g | weight | EVS | w2_poststr |
| v154 | homosexual couples - adopt children | EVS | e_pc_adop |
1.3. Retrieve names of the chosen source variables
variables <- codebook_evs %>% drop_na(target_var) %>% pull(var_source)The retrieved variables are: id_cocas, c_abrv, weight_g, v154.
1.4. Select a subset of the survey data containing only the chosen variables
evs_small <- evs %>% select(all_of(variables)) %>% mutate(caseid = row_number())You will see that the following data set is a subset of the EVS 2008 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:
| id_cocas | c_abrv | weight_g | v154 | caseid |
|---|---|---|---|---|
| 200800800001 | AL | 0.9623360 | -1 | 1 |
| 200800800002 | AL | 0.7617063 | -1 | 2 |
| 200800800003 | AL | 0.7617063 | 5 | 3 |
| 200800800004 | AL | 1.0642812 | 5 | 4 |
| 200800800005 | AL | 0.9859014 | 3 | 5 |
| 200800800006 | AL | 0.7617063 | 4 | 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.
evs_cwt <- create_cwt(evs_small %>% select(c_abrv, v154)) %>%
left_join(codebook_evs, by=join_by(var_source, var_label_source)) %>%
mutate(target_value = NA,
target_value = ifelse(!grepl("not asked|know|efusal|answer|NA|applicable|Can't choose|]DK|] DK|Na| other missing", value_label_source), value_code, target_value),
value_code = as.character(value_code)
)There are decisions about the substantive variable made by taking into account all datasets. 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: Definitions of missing values differ across EVS and ESS. Missing values are not harmonised but recoded into the single missing value “NA”.
Let’s look at the correspondence between e_pc_adop and v154:
evs_cwt %>% filter(var_source == "v154") %>%
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 |
|---|---|---|---|---|---|---|---|---|
| v154 | homosexual couples - adopt children | 1 | [-5] other missing: 1 | [-5] other missing | -5 | EVS | e_pc_adop | NA |
| v154 | homosexual couples - adopt children | 2 | [-4] question not asked: 0 | [-4] question not asked | -4 | EVS | e_pc_adop | NA |
| v154 | homosexual couples - adopt children | 3 | [-3] not applicable: 0 | [-3] not applicable | -3 | EVS | e_pc_adop | NA |
| v154 | homosexual couples - adopt children | 4 | [-2] no answer: 581 | [-2] no answer | -2 | EVS | e_pc_adop | NA |
| v154 | homosexual couples - adopt children | 5 | [-1] don't know: 3522 | [-1] don't know | -1 | EVS | e_pc_adop | NA |
| v154 | homosexual couples - adopt children | 6 | [1] agree strongly: 4510 | [1] agree strongly | 1 | EVS | e_pc_adop | 1 |
| v154 | homosexual couples - adopt children | 7 | [2] agree: 9570 | [2] agree | 2 | EVS | e_pc_adop | 2 |
| v154 | homosexual couples - adopt children | 8 | [3] agree nor disagree: 8884 | [3] agree nor disagree | 3 | EVS | e_pc_adop | 3 |
| v154 | homosexual couples - adopt children | 9 | [4] disagree: 17484 | [4] disagree | 4 | EVS | e_pc_adop | 4 |
| v154 | homosexual couples - adopt children | 10 | [5] disagree strongly: 21728 | [5] disagree strongly | 5 | EVS | e_pc_adop | 5 |
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(evs_cwt, paste("data/", target_var_hrms, "_cwt_evs.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.
evs_small_long <- evs_small %>%
mutate(across(everything(), as.character)) %>%
pivot_longer(cols = c(v154, c_abrv),
names_to = "var_source", values_to = "value_source") This is how the first six rows of the evs_small_long should look like:
| id_cocas | weight_g | caseid | var_source | value_source |
|---|---|---|---|---|
| 200800800001 | 0.962336045594876 | 1 | v154 | -1 |
| 200800800001 | 0.962336045594876 | 1 | c_abrv | AL |
| 200800800002 | 0.761706287022894 | 2 | v154 | -1 |
| 200800800002 | 0.761706287022894 | 2 | c_abrv | AL |
| 200800800003 | 0.761706287022894 | 3 | v154 | 5 |
| 200800800003 | 0.761706287022894 | 3 | c_abrv | AL |
Now we use left_join() to recode source values according to the crosswalk table, evs_cwt.
evs_hrmsd <- evs_small_long %>%
left_join(evs_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(id_cocas, weight_g, 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 = id_cocas)Now, EVS 2008 data is ready for harmonisation. This is how the first six rows of the evs_hrmsd should look like:
| caseID_source | weight_g | caseid | survey | country_source | target_var | target_value |
|---|---|---|---|---|---|---|
| 200800800001 | 0.962336045594876 | 1 | EVS | AL | e_pc_adop | NA |
| 200800800002 | 0.761706287022894 | 2 | EVS | AL | e_pc_adop | NA |
| 200800800003 | 0.761706287022894 | 3 | EVS | AL | e_pc_adop | 5 |
| 200800800004 | 1.06428124468104 | 4 | EVS | AL | e_pc_adop | 5 |
| 200800800005 | 0.985901445634828 | 5 | EVS | AL | e_pc_adop | 3 |
| 200800800006 | 0.761706287022894 | 6 | EVS | AL | e_pc_adop | 4 |
At this step, the prepared data can be exported as an Rdata file and saved for later re-use.
saveRDS(evs_hrmsd, paste("data/", target_var_hrms, "_evs.rds", sep = ''))
2. Prepare Data: ESS 2016
We will follow the same steps used for preparing the EVS 2008 item. As expected, EVS and ESS data have differences, and they are taken into account in implementing these steps.
2.1. Import data
ess16 <- haven::read_sav("data/ESS8e02_3.sav", user_na=TRUE)Use this output to compare it with your output. Check especially if the labels match.
ess16 %>% count(hmsacld)# A tibble: 8 × 2
hmsacld n
<dbl+lbl> <int>
1 1 [Agree strongly] 8879
2 2 [Agree] 10197
3 3 [Neither agree nor disagree] 6959
4 4 [Disagree] 8079
5 5 [Disagree strongly] 8823
6 7 (NA) [Refusal] 322
7 8 (NA) [Don't know] 1123
8 9 (NA) [No answer] 5
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_ess16 <- create_codebook_short(ess16) %>%
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("Gay and lesbian couples right to adopt children", 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. The same names are used except for the weight variables because there are two weight variables.
| 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 |
| hmsacld | Gay and lesbian couples right to adopt children | ESS | e_pc_adop |
2.3. Retrieve names of the chosen source variables
variables <- codebook_ess16 %>% drop_na(target_var) %>% pull(var_source)The retrieved variables are: idno, cntry, dweight, pspwght, hmsacld.
2.4. Select a subset of the survey data containing only the chosen variables
ess16_small <- ess16 %>% select(all_of(variables)) %>% mutate(caseid = row_number())You will see that the following data set is a subset of the ESS 2016 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:
| idno | cntry | dweight | pspwght | hmsacld | caseid |
|---|---|---|---|---|---|
| 1 | AT | 0.6116771 | 1.1784955 | 1 | 1 |
| 2 | AT | 1.2233541 | 0.8994715 | 1 | 2 |
| 4 | AT | 0.3890577 | 0.3157533 | 3 | 3 |
| 6 | AT | 0.6425940 | 0.4724674 | 2 | 4 |
| 10 | AT | 3.4324021 | 2.2467055 | 1 | 5 |
| 11 | AT | 1.1805793 | 1.0113790 | 4 | 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.
ess16_cwt <- create_cwt(ess16_small %>% select(cntry, hmsacld)) %>%
left_join(codebook_ess16, 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)
)The survey-specific missing values are recoded into the single missing value “NA”.
Let’s look at the correspondence between e_pc_adop and hmsacld:
ess16_cwt %>% filter(var_source == "hmsacld") %>%
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 |
|---|---|---|---|---|---|---|---|---|
| hmsacld | Gay and lesbian couples right to adopt children | 1 | [1] Agree strongly: 8879 | [1] Agree strongly | 1 | ESS | e_pc_adop | 1 |
| hmsacld | Gay and lesbian couples right to adopt children | 2 | [2] Agree: 10197 | [2] Agree | 2 | ESS | e_pc_adop | 2 |
| hmsacld | Gay and lesbian couples right to adopt children | 3 | [3] Neither agree nor disagree: 6959 | [3] Neither agree nor disagree | 3 | ESS | e_pc_adop | 3 |
| hmsacld | Gay and lesbian couples right to adopt children | 4 | [4] Disagree: 8079 | [4] Disagree | 4 | ESS | e_pc_adop | 4 |
| hmsacld | Gay and lesbian couples right to adopt children | 5 | [5] Disagree strongly: 8823 | [5] Disagree strongly | 5 | ESS | e_pc_adop | 5 |
| hmsacld | Gay and lesbian couples right to adopt children | 6 | [7] Refusal: 322 | [7] Refusal | 7 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 7 | [8] Don't know: 1123 | [8] Don't know | 8 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 8 | [9] No answer: 5 | [9] No answer | 9 | ESS | e_pc_adop | NA |
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(ess16_cwt, paste("data/", target_var_hrms, "_cwt_ess16.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.
ess16_small_long <- ess16_small %>%
mutate(across(everything(), as.character)) %>%
pivot_longer(cols = c(hmsacld, cntry),
names_to = "var_source", values_to = "value_source")This is how the first six rows of the ess16_small_long should look like:
| idno | dweight | pspwght | caseid | var_source | value_source |
|---|---|---|---|---|---|
| 1 | 0.611677050590515 | 1.17849552631378 | 1 | hmsacld | 1 |
| 1 | 0.611677050590515 | 1.17849552631378 | 1 | cntry | AT |
| 2 | 1.22335410118103 | 0.899471521377563 | 2 | hmsacld | 1 |
| 2 | 1.22335410118103 | 0.899471521377563 | 2 | cntry | AT |
| 4 | 0.389057725667953 | 0.31575334072113 | 3 | hmsacld | 3 |
| 4 | 0.389057725667953 | 0.31575334072113 | 3 | cntry | AT |
Now we use left_join() to recode source values according to the crosswalk table, ess16_cwt.
ess16_hrmsd <- ess16_small_long %>%
left_join(ess16_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 2016 data is ready for harmonisation. This is how the first six rows of the ess16_hrmsd should look like:
head(ess16_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.611677050590515 | 1.17849552631378 | 1 | 1 | ESS | AT | e_pc_adop | 1 |
| 1.22335410118103 | 0.899471521377563 | 2 | 2 | ESS | AT | e_pc_adop | 1 |
| 0.389057725667953 | 0.31575334072113 | 4 | 3 | ESS | AT | e_pc_adop | 3 |
| 0.64259397983551 | 0.472467392683029 | 6 | 4 | ESS | AT | e_pc_adop | 2 |
| 3.43240213394165 | 2.24670553207397 | 10 | 5 | ESS | AT | e_pc_adop | 1 |
| 1.18057930469513 | 1.01137900352478 | 11 | 6 | ESS | AT | e_pc_adop | 4 |
At this step, the prepared data can be exported as an Rdata file and saved for later re-use.
saveRDS(ess16_hrmsd, paste("data/", target_var_hrms, "_ess16.rds", sep = ''))
3. Prepare Data: ESS 2018
We will follow the same steps used before.
3.1. Import data
ess18 <- haven::read_sav("data/ESS9e03_2.sav", user_na=TRUE)Use this output to compare it with your output. Check especially if the labels match.
ess18 %>% count(hmsacld)# A tibble: 8 × 2
hmsacld n
<dbl+lbl> <int>
1 1 [Agree strongly] 9884
2 2 [Agree] 10804
3 3 [Neither agree nor disagree] 7837
4 4 [Disagree] 8845
5 5 [Disagree strongly] 10136
6 7 (NA) [Refusal] 421
7 8 (NA) [Don't know] 1589
8 9 (NA) [No answer] 3
3.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_ess18 <- create_codebook_short(ess18) %>%
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("Gay and lesbian couples right to adopt children", 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 the target_var. The same names are used except for the weight variables because there are two weight variables.
| 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 |
| hmsacld | Gay and lesbian couples right to adopt children | ESS | e_pc_adop |
3.3. Retrieve names of the chosen source variables
variables <- codebook_ess18 %>% drop_na(target_var) %>% pull(var_source)The retrieved variables are: idno, cntry, dweight, pspwght, hmsacld.
3.4. Select a subset of the survey data containing only the chosen variables
ess18_small <- ess18 %>% select(all_of(variables)) %>% mutate(caseid = row_number())You will see that the following data set is a subset of the ESS 2018 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:
| idno | cntry | dweight | pspwght | hmsacld | caseid |
|---|---|---|---|---|---|
| 27 | AT | 0.5811743 | 0.2181114 | 1 | 1 |
| 137 | AT | 1.0627724 | 0.4134733 | 4 | 2 |
| 194 | AT | 1.3765086 | 2.2702928 | 3 | 3 |
| 208 | AT | 0.9933993 | 0.3864834 | 1 | 4 |
| 220 | AT | 0.3773534 | 1.0321022 | 4 | 5 |
| 254 | AT | 1.4793528 | 0.5755447 | 3 | 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.
pattern_na <- "know|efusal|answer|NA|applicable|not asked| missing|]DK|] DK"
ess18_cwt <- create_cwt(ess18_small %>% select(cntry, hmsacld)) %>%
left_join(codebook_ess18, by = join_by(var_source, var_label_source)) %>%
mutate(target_value = NA,
target_value = ifelse(!grepl(pattern_na, value_label_source), value_code, target_value),
value_code = as.character(value_code))Missing values are recoded into the single missing value “NA”.
Let’s look at the correspondence between e_pc_adop and hmsacld:
ess18_cwt %>% filter(var_source == "hmsacld") %>%
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 |
|---|---|---|---|---|---|---|---|---|
| hmsacld | Gay and lesbian couples right to adopt children | 1 | [1] Agree strongly: 9884 | [1] Agree strongly | 1 | ESS | e_pc_adop | 1 |
| hmsacld | Gay and lesbian couples right to adopt children | 2 | [2] Agree: 10804 | [2] Agree | 2 | ESS | e_pc_adop | 2 |
| hmsacld | Gay and lesbian couples right to adopt children | 3 | [3] Neither agree nor disagree: 7837 | [3] Neither agree nor disagree | 3 | ESS | e_pc_adop | 3 |
| hmsacld | Gay and lesbian couples right to adopt children | 4 | [4] Disagree: 8845 | [4] Disagree | 4 | ESS | e_pc_adop | 4 |
| hmsacld | Gay and lesbian couples right to adopt children | 5 | [5] Disagree strongly: 10136 | [5] Disagree strongly | 5 | ESS | e_pc_adop | 5 |
| hmsacld | Gay and lesbian couples right to adopt children | 6 | [7] Refusal: 421 | [7] Refusal | 7 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 7 | [8] Don't know: 1589 | [8] Don't know | 8 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 8 | [9] No answer: 3 | [9] No answer | 9 | ESS | e_pc_adop | NA |
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(ess18_cwt, paste("data/", target_var_hrms, "_cwt_ess18.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.
ess18_small_long <- ess18_small %>%
mutate(across(everything(), as.character)) %>%
pivot_longer(cols = c(hmsacld, cntry),
names_to = "var_source", values_to = "value_source")This is how the first six rows of the ess18_small_long should look like:
| idno | dweight | pspwght | caseid | var_source | value_source |
|---|---|---|---|---|---|
| 27 | 0.581174314022064 | 0.218111366033554 | 1 | hmsacld | 1 |
| 27 | 0.581174314022064 | 0.218111366033554 | 1 | cntry | AT |
| 137 | 1.06277239322662 | 0.413473278284073 | 2 | hmsacld | 4 |
| 137 | 1.06277239322662 | 0.413473278284073 | 2 | cntry | AT |
| 194 | 1.37650859355927 | 2.27029275894165 | 3 | hmsacld | 3 |
| 194 | 1.37650859355927 | 2.27029275894165 | 3 | cntry | AT |
Now we use left_join() to recode source values according to the crosswalk table, ess18_cwt.
ess18_hrmsd <- ess18_small_long %>%
left_join(ess18_cwt, by = c("value_source" = "value_code", "var_source")) %>%
select(-npos, -value_n) %>%
mutate(target_value = as.character(target_value)) %>%
pivot_wider(id_cols = c(idno, ends_with("weight"), pspwght, 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 = idno)ESS 2018 data is ready for harmonisation. This is how the first six rows of the ess18_hrmsd should look like:
head(ess18_hrmsd) %>%
kable(row.names = FALSE) %>%
kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))| caseID_source | dweight | pspwght | caseid | survey | country_source | target_var | target_value |
|---|---|---|---|---|---|---|---|
| 27 | 0.581174314022064 | 0.218111366033554 | 1 | ESS | AT | e_pc_adop | 1 |
| 137 | 1.06277239322662 | 0.413473278284073 | 2 | ESS | AT | e_pc_adop | 4 |
| 194 | 1.37650859355927 | 2.27029275894165 | 3 | ESS | AT | e_pc_adop | 3 |
| 208 | 0.993399322032928 | 0.386483430862427 | 4 | ESS | AT | e_pc_adop | 1 |
| 220 | 0.377353370189667 | 1.032102227211 | 5 | ESS | AT | e_pc_adop | 4 |
| 254 | 1.47935283184052 | 0.575544655323029 | 6 | ESS | AT | e_pc_adop | 3 |
At this step, the prepared data can be exported as an Rdata file and saved for later re-use.
saveRDS(ess18_hrmsd, paste("data/", target_var_hrms, "_ess18.rds", sep = ''))
4. Prepare Data: ESS 2020
We will follow the same steps used before.
4.1. Import data
ess20 <- haven::read_sav("data/ESS10.sav", user_na=TRUE)Use this output to compare it with your output. Check especially if the labels match.
ess20 %>% count(hmsacld)# A tibble: 8 × 2
hmsacld n
<dbl+lbl> <int>
1 1 [Agree strongly] 7740
2 2 [Agree] 7727
3 3 [Neither agree nor disagree] 6584
4 4 [Disagree] 6514
5 5 [Disagree strongly] 7766
6 7 (NA) [Refusal] 270
7 8 (NA) [Don't know] 894
8 9 (NA) [No answer] 116
4.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_ess20 <- create_codebook_short(ess20) %>%
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("Gay and lesbian couples right to adopt children", 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. The same names are used except for the weight variables because there are two weight variables.
| 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 |
| hmsacld | Gay and lesbian couples right to adopt children | ESS | e_pc_adop |
4.3. Retrieve names of the chosen source variables
variables <- codebook_ess20 %>% drop_na(target_var) %>% pull(var_source)The retrieved variables are: idno, cntry, dweight, pspwght, hmsacld.
4.4. Select a subset of the survey data containing only the chosen variables
ess20_small <- ess20 %>% select(all_of(variables)) %>% mutate(caseid = row_number())You will see that the following data set is a subset of the ESS 2020 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:
| idno | cntry | dweight | pspwght | hmsacld | caseid |
|---|---|---|---|---|---|
| 10038 | BE | 0.8822203 | 0.9722756 | 1 | 1 |
| 10053 | BE | 1.0476425 | 0.8886350 | 3 | 2 |
| 10055 | BE | 1.0877413 | 0.7228110 | 2 | 3 |
| 10062 | BE | 0.9099100 | 1.0055653 | 3 | 4 |
| 10064 | BE | 0.9189489 | 0.6387054 | 1 | 5 |
| 10077 | BE | 0.9137402 | 0.7061659 | 2 | 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.
ess20_cwt <- create_cwt(ess20_small %>% select(cntry, hmsacld)) %>%
left_join(codebook_ess20, 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)
)The survey-specific missing values are recoded into the single missing value “NA”.
Let’s look at the correspondence between e_pc_adop and hmsacld:
ess20_cwt %>% filter(var_source == "hmsacld") %>%
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 |
|---|---|---|---|---|---|---|---|---|
| hmsacld | Gay and lesbian couples right to adopt children | 1 | [1] Agree strongly: 7740 | [1] Agree strongly | 1 | ESS | e_pc_adop | 1 |
| hmsacld | Gay and lesbian couples right to adopt children | 2 | [2] Agree: 7727 | [2] Agree | 2 | ESS | e_pc_adop | 2 |
| hmsacld | Gay and lesbian couples right to adopt children | 3 | [3] Neither agree nor disagree: 6584 | [3] Neither agree nor disagree | 3 | ESS | e_pc_adop | 3 |
| hmsacld | Gay and lesbian couples right to adopt children | 4 | [4] Disagree: 6514 | [4] Disagree | 4 | ESS | e_pc_adop | 4 |
| hmsacld | Gay and lesbian couples right to adopt children | 5 | [5] Disagree strongly: 7766 | [5] Disagree strongly | 5 | ESS | e_pc_adop | 5 |
| hmsacld | Gay and lesbian couples right to adopt children | 6 | [7] Refusal: 270 | [7] Refusal | 7 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 7 | [8] Don't know: 894 | [8] Don't know | 8 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 8 | [9] No answer: 116 | [9] No answer | 9 | ESS | e_pc_adop | NA |
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(ess20_cwt, paste("data/", target_var_hrms, "_cwt_ess20.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.
ess20_small_long <- ess20_small %>%
mutate(across(everything(), as.character)) %>%
pivot_longer(cols = c(hmsacld, cntry),
names_to = "var_source", values_to = "value_source")This is how the first six rows of the ess20_small_long should look like:
| idno | dweight | pspwght | caseid | var_source | value_source |
|---|---|---|---|---|---|
| 10038 | 0.882220268249512 | 0.97227555513382 | 1 | hmsacld | 1 |
| 10038 | 0.882220268249512 | 0.97227555513382 | 1 | cntry | BE |
| 10053 | 1.04764246940613 | 0.888634979724884 | 2 | hmsacld | 3 |
| 10053 | 1.04764246940613 | 0.888634979724884 | 2 | cntry | BE |
| 10055 | 1.08774125576019 | 0.722811043262482 | 3 | hmsacld | 2 |
| 10055 | 1.08774125576019 | 0.722811043262482 | 3 | cntry | BE |
Now we use left_join() to recode source values according to the crosswalk table, ess20_cwt.
ess20_hrmsd <- ess20_small_long %>%
left_join(ess20_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 2020 data is ready for harmonisation. This is how the first six rows of the ess20_hrmsd should look like:
head(ess20_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.882220268249512 | 0.97227555513382 | 10038 | 1 | ESS | BE | e_pc_adop | 1 |
| 1.04764246940613 | 0.888634979724884 | 10053 | 2 | ESS | BE | e_pc_adop | 3 |
| 1.08774125576019 | 0.722811043262482 | 10055 | 3 | ESS | BE | e_pc_adop | 2 |
| 0.909909963607788 | 1.00556528568268 | 10062 | 4 | ESS | BE | e_pc_adop | 3 |
| 0.918948888778687 | 0.638705432415009 | 10064 | 5 | ESS | BE | e_pc_adop | 1 |
| 0.913740217685699 | 0.706165909767151 | 10077 | 6 | ESS | BE | e_pc_adop | 2 |
At this step, the prepared data can be exported as an Rdata file and saved for later re-use.
saveRDS(ess20_hrmsd, paste("data/", target_var_hrms, "_ess20.rds", sep = ''))
5. Prepare Data: ESS 2023
Again, we will follow the same steps used before.
5.1. Import data
ess23 <- haven::read_sav("data/ESS11.sav", user_na=TRUE)Use this output to compare it with your output. Check especially if the labels match.
ess23 %>% count(hmsacld)# A tibble: 8 × 2
hmsacld n
<dbl+lbl> <int>
1 1 [Agree strongly] 5738
2 2 [Agree] 5868
3 3 [Neither agree nor disagree] 3441
4 4 [Disagree] 3412
5 5 [Disagree strongly] 3061
6 7 (NA) [Refusal] 142
7 8 (NA) [Don't know] 526
8 9 (NA) [No answer] 2
5.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_ess23 <- create_codebook_short(ess23) %>%
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(var_source == "pweight", "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("Gay and lesbian couples right to adopt children", 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. The same names are used except for the weight variables because there are two weight variables.
| 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 |
| pweight | Population size weight (must be combined with dweight or pspwght) | ESS | w2_poststr |
| hmsacld | Gay and lesbian couples right to adopt children | ESS | e_pc_adop |
5.3. Retrieve names of the chosen source variables
variables <- codebook_ess23 %>% drop_na(target_var) %>% pull(var_source)The retrieved variables are: idno, cntry, dweight, pweight, hmsacld.
5.4. Select a subset of the survey data containing only the chosen variables
ess23_small <- ess23 %>% select(all_of(variables)) %>% mutate(caseid = row_number())You will see that the following data set is a subset of the ESS 2023 with the chosen variables for the harmonised data. The first six rows of the dataset are as follows:
| idno | cntry | dweight | pweight | hmsacld | caseid |
|---|---|---|---|---|---|
| 50014 | AT | 1.1851145 | 0.3309145 | 3 | 1 |
| 50030 | AT | 0.6098981 | 0.3309145 | 1 | 2 |
| 50057 | AT | 1.3923296 | 0.3309145 | 1 | 3 |
| 50106 | AT | 0.5560615 | 0.3309145 | 3 | 4 |
| 50145 | AT | 0.7227953 | 0.3309145 | 2 | 5 |
| 50158 | AT | 0.9926053 | 0.3309145 | 2 | 6 |
5.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.
ess23_cwt <- create_cwt(ess23_small %>% select(cntry, hmsacld)) %>%
left_join(codebook_ess23, 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)
)The survey-specific missing values are recoded into the single missing value “NA”.
Let’s look at the correspondence between e_pc_adop and hmsacld:
ess23_cwt %>% filter(var_source == "hmsacld") %>%
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 |
|---|---|---|---|---|---|---|---|---|
| hmsacld | Gay and lesbian couples right to adopt children | 1 | [1] Agree strongly: 5738 | [1] Agree strongly | 1 | ESS | e_pc_adop | 1 |
| hmsacld | Gay and lesbian couples right to adopt children | 2 | [2] Agree: 5868 | [2] Agree | 2 | ESS | e_pc_adop | 2 |
| hmsacld | Gay and lesbian couples right to adopt children | 3 | [3] Neither agree nor disagree: 3441 | [3] Neither agree nor disagree | 3 | ESS | e_pc_adop | 3 |
| hmsacld | Gay and lesbian couples right to adopt children | 4 | [4] Disagree: 3412 | [4] Disagree | 4 | ESS | e_pc_adop | 4 |
| hmsacld | Gay and lesbian couples right to adopt children | 5 | [5] Disagree strongly: 3061 | [5] Disagree strongly | 5 | ESS | e_pc_adop | 5 |
| hmsacld | Gay and lesbian couples right to adopt children | 6 | [7] Refusal: 142 | [7] Refusal | 7 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 7 | [8] Don't know: 526 | [8] Don't know | 8 | ESS | e_pc_adop | NA |
| hmsacld | Gay and lesbian couples right to adopt children | 8 | [9] No answer: 2 | [9] No answer | 9 | ESS | e_pc_adop | NA |
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(ess23_cwt, paste("data/", target_var_hrms, "_cwt_ess23.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.
ess23_small_long <- ess23_small %>%
mutate(across(everything(), as.character)) %>%
pivot_longer(cols = c(hmsacld, cntry),
names_to = "var_source", values_to = "value_source")This is how the first six rows of the ess23_small_long should look like:
| idno | dweight | pweight | caseid | var_source | value_source |
|---|---|---|---|---|---|
| 50014 | 1.1851145029068 | 0.330914527177811 | 1 | hmsacld | 3 |
| 50014 | 1.1851145029068 | 0.330914527177811 | 1 | cntry | AT |
| 50030 | 0.609898090362549 | 0.330914527177811 | 2 | hmsacld | 1 |
| 50030 | 0.609898090362549 | 0.330914527177811 | 2 | cntry | AT |
| 50057 | 1.39232957363129 | 0.330914527177811 | 3 | hmsacld | 1 |
| 50057 | 1.39232957363129 | 0.330914527177811 | 3 | cntry | AT |
Now we use left_join() to recode source values according to the crosswalk table, ess23_cwt.
ess23_hrmsd <- ess23_small_long %>%
left_join(ess23_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, pweight, 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 2023 data is ready for harmonisation. This is how the first six rows of the ess23_hrmsd should look like:
head(ess23_hrmsd) %>%
kable(row.names = FALSE) %>%
kable_styling(full_width = FALSE, bootstrap_options = c("striped", "hover"))| dweight | pweight | caseID_source | caseid | survey | country_source | target_var | target_value |
|---|---|---|---|---|---|---|---|
| 1.1851145029068 | 0.330914527177811 | 50014 | 1 | ESS | AT | e_pc_adop | 3 |
| 0.609898090362549 | 0.330914527177811 | 50030 | 2 | ESS | AT | e_pc_adop | 1 |
| 1.39232957363129 | 0.330914527177811 | 50057 | 3 | ESS | AT | e_pc_adop | 1 |
| 0.556061506271362 | 0.330914527177811 | 50106 | 4 | ESS | AT | e_pc_adop | 3 |
| 0.722795307636261 | 0.330914527177811 | 50145 | 5 | ESS | AT | e_pc_adop | 2 |
| 0.992605328559875 | 0.330914527177811 | 50158 | 6 | ESS | AT | e_pc_adop | 2 |
At this step, the prepared data can be exported as an Rdata file and saved for later re-use.
saveRDS(ess23_hrmsd, paste("data/", target_var_hrms, "_ess23.rds", sep = ''))
6. Harmonisation
With the following steps we will create the harmonised Support for Homosexuals Adoption Rights data.
6.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").
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")evs_1 <- evs_hrmsd %>%
recoded_country("country_source") %>%
country_new_labels("country_new") %>%
func_country_sample("country_source") %>%
country_source_recoded_labels("country_source_recoded")
ess16_1 <- ess16_hrmsd %>%
recoded_country("country_source") %>%
country_new_labels("country_new") %>%
func_country_sample("country_source") %>%
country_source_recoded_labels("country_source_recoded")
ess18_1 <- ess18_hrmsd %>%
recoded_country("country_source") %>%
country_new_labels("country_new") %>%
func_country_sample("country_source") %>%
country_source_recoded_labels("country_source_recoded")
ess20_1 <- ess20_hrmsd %>%
recoded_country("country_source") %>%
country_new_labels("country_new") %>%
func_country_sample("country_source") %>%
country_source_recoded_labels("country_source_recoded")
ess23_1 <- ess23_hrmsd %>%
recoded_country("country_source") %>%
country_new_labels("country_new") %>%
func_country_sample("country_source") %>%
country_source_recoded_labels("country_source_recoded")You can run the following code to check the country variable:
table(evs_hrmsd$country_source, evs_1$country_new)
6.2. Weights
For details on decisions and procedures for including weight variables, please see the Make It Equal! data documentation page, section Weight Variables.
evs_2 <- evs_1 %>% mutate(weight_g = ifelse(weight_g == 0,1,weight_g))
evs_fnl <- evs_2 %>% mutate(w1_design = weight_g,
w2_poststr = weight_g,
w3_combined = as.numeric(w2_poststr))
ess16_fnl <- ess16_1 %>% mutate(w1_design = dweight,
w2_poststr = pspwght,
w3_combined = as.numeric(w2_poststr))
ess18_fnl <- ess18_1 %>% mutate(w1_design = dweight,
w2_poststr = pspwght,
w3_combined = as.numeric(w2_poststr))
ess20_fnl <- ess20_1 %>% mutate(w1_design = dweight,
w2_poststr = pspwght,
w3_combined = as.numeric(w2_poststr))
ess23_fnl <- ess23_1 %>% mutate(w1_design = dweight,
w2_poststr = pweight,
w3_combined = as.numeric(w2_poststr))
6.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_equal.xlsx") %>%
select(-studyno_source, -wave)
6.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")
evs_fnl$year <- "2008"
ess16_fnl$year <- "2016"
ess18_fnl$year <- "2018"
ess20_fnl$year <- "2020"
ess23_fnl$year <- "2023"
all_comb <- bind_rows(ess16_fnl[, commons],
ess18_fnl[, commons],
ess20_fnl[, commons],
ess23_fnl[, commons],
evs_fnl[, 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 = 5
) %>%
# Rename to avoid SPSS duplicate name error
rename(caseid_sw = caseid, country_I4NG = country_new)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 | doi_source | studyno_I4NG | version_I4NG | doi_I4NG | caseID_I4NG | country_year | caseID | npoints |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 1 | ESS | e_pc_adop | 1 | 2016 | AT | AT | 0.611677050590515 | 1.17849552631378 | 1.1784955 | Welfare attitudes, Attitudes to climate change | https://doi.org/10.21338/ess8e02_3 | NA | NA | NA | ESS2016AT1 | AT_2016 | 1 | 5 |
| 2 | 2 | ESS | e_pc_adop | 1 | 2016 | AT | AT | 1.22335410118103 | 0.899471521377563 | 0.8994715 | Welfare attitudes, Attitudes to climate change | https://doi.org/10.21338/ess8e02_3 | NA | NA | NA | ESS2016AT2 | AT_2016 | 2 | 5 |
| 4 | 3 | ESS | e_pc_adop | 3 | 2016 | AT | AT | 0.389057725667953 | 0.31575334072113 | 0.3157533 | Welfare attitudes, Attitudes to climate change | https://doi.org/10.21338/ess8e02_3 | NA | NA | NA | ESS2016AT3 | AT_2016 | 3 | 5 |
| 6 | 4 | ESS | e_pc_adop | 2 | 2016 | AT | AT | 0.64259397983551 | 0.472467392683029 | 0.4724674 | Welfare attitudes, Attitudes to climate change | https://doi.org/10.21338/ess8e02_3 | NA | NA | NA | ESS2016AT4 | AT_2016 | 4 | 5 |
| 10 | 5 | ESS | e_pc_adop | 1 | 2016 | AT | AT | 3.43240213394165 | 2.24670553207397 | 2.2467055 | Welfare attitudes, Attitudes to climate change | https://doi.org/10.21338/ess8e02_3 | NA | NA | NA | ESS2016AT5 | AT_2016 | 5 | 5 |
| 11 | 6 | ESS | e_pc_adop | 4 | 2016 | AT | AT | 1.18057930469513 | 1.01137900352478 | 1.0113790 | Welfare attitudes, Attitudes to climate change | https://doi.org/10.21338/ess8e02_3 | NA | NA | NA | ESS2016AT6 | AT_2016 | 6 | 5 |
count(all_comb, target_var, survey, year)# A tibble: 5 × 4
target_var survey year n
<chr> <chr> <chr> <int>
1 e_pc_adop ESS 2016 44387
2 e_pc_adop ESS 2018 49519
3 e_pc_adop ESS 2020 37611
4 e_pc_adop ESS 2023 22190
5 e_pc_adop EVS 2008 66280
6.5. Find equivalents of the response categories
Response categories are the same across source data. Therefore, no transformation is applied.
all_hrmsd <- all_comb %>%
mutate(value_hrmsd = 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 Support for Homosexuals Adoption 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 | e_pc_adop |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| https://doi.org/10.21338/ess8e02_3 | Welfare attitudes, Attitudes to climate change | 1 | 1 | ESS | AT | AT | 2016 | AT_2016 | 0.611677050590515 | 1.17849552631378 | 1.1784955 | ESS2016AT1 | 1 |
| https://doi.org/10.21338/ess8e02_3 | Welfare attitudes, Attitudes to climate change | 2 | 2 | ESS | AT | AT | 2016 | AT_2016 | 1.22335410118103 | 0.899471521377563 | 0.8994715 | ESS2016AT2 | 1 |
| https://doi.org/10.21338/ess8e02_3 | Welfare attitudes, Attitudes to climate change | 4 | 3 | ESS | AT | AT | 2016 | AT_2016 | 0.389057725667953 | 0.31575334072113 | 0.3157533 | ESS2016AT3 | 3 |
| https://doi.org/10.21338/ess8e02_3 | Welfare attitudes, Attitudes to climate change | 6 | 4 | ESS | AT | AT | 2016 | AT_2016 | 0.64259397983551 | 0.472467392683029 | 0.4724674 | ESS2016AT4 | 2 |
| https://doi.org/10.21338/ess8e02_3 | Welfare attitudes, Attitudes to climate change | 10 | 5 | ESS | AT | AT | 2016 | AT_2016 | 3.43240213394165 | 2.24670553207397 | 2.2467055 | ESS2016AT5 | 1 |
| https://doi.org/10.21338/ess8e02_3 | Welfare attitudes, Attitudes to climate change | 11 | 6 | ESS | AT | AT | 2016 | AT_2016 | 1.18057930469513 | 1.01137900352478 | 1.0113790 | ESS2016AT6 | 4 |
6.6. 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
Support for Homosexuals Adoption Rights was administered in EVS 2008 and ESS 2016, 2018, 2020 and 2023. Our script, first, prepares these five data sets for harmonisation so that they are consistent in format via codebooks and crosswalk tables. Then, the response categories were aligned. After this step, the item is ready for subsequent analysis!
To go back to the Make it Equal! Toolbox page, please click here!