Merge different LISS modules and select information we need to construct the repeated risk dataset.
#load packages
library(dplyr)
library(purrr)
library(tidyr)
library(tidyselect)
library(haven)
library(magrittr)
#disable the scientific notation in R (else all the id's will be in scientific notation)
options(scipen = 999)
Import the raw liss files.
#import the different liss files from their directory.
liss_files <-
list.files(path = "datafiles/data-raw/leisure_integ_data", full.names = T) %>%
map(read_sav)
#For a full outer join.
liss_merged <- liss_files %>%
reduce(full_join, by = 'nomem_encr') %>%
arrange(nomem_encr)
df with 14040 observations of 4909 variables.
liss_files <-
list.files("datafiles/data-raw/alter_data/", full.names = T) %>%
map(read_sav)
#just to be sure, order the files on nomem_encr and add suffixes to the data.
#Then we can correctly identify the different waves.
liss_files <- lapply(1:11, function(i) {
data <- liss_files[[i]]
#Now I add suffixes to all the variables except the ID var, so we can correctly Identify the wave to which a variable belongs in the merged data. Otherwise we will have 11 sets of the same variables with a random .x or .y.
names(data)[-1] <- paste0(names(data)[-1], sep = ".", c(1:11)[i])
return(data)
})
#merge the data
liss_alter <- liss_files %>%
reduce(full_join, by = 'nomem_encr') %>%
arrange(nomem_encr)
#import the background variable data.
#import data files.
liss_files <-
list.files("datafiles/data-raw/avars/", full.names = T) %>%
map(read_sav)
#just to be sure, order the files on nomem_encr and add suffixes to the data
liss_files <- lapply(1:11, function(i) {
data <- liss_files[[i]][base::order(liss_files[[i]]$nomem_encr), ]
names(data)[-1] <- paste0(names(data)[-1], sep = ".", c(1:11)[i])
return(data)
})
#merge the data.
liss_background <- liss_files %>%
reduce(full_join, by = 'nomem_encr') %>%
arrange(nomem_encr)
#import the background variable data.
#import data files from directory.
liss_files <-
list.files("datafiles/data-raw/housing/", full.names = T) %>%
map(read_sav)
#merge the data.
liss_housing <- liss_files %>%
reduce(full_join, by = 'nomem_encr') %>%
arrange(nomem_encr)
#import the background variable data.
#import data files from directory.
liss_files <-
list.files("datafiles/data-raw/family/", full.names = T) %>%
map(read_sav)
#merge the data.
liss_family <- liss_files %>%
reduce(full_join, by = 'nomem_encr') %>%
arrange(nomem_encr)
#merge all the data with an full outer join into one file.
#okay, let's merge the liss_merged, liss_alter and the politics and values waves.
liss <- liss_merged %>%
full_join(liss_alter, by = "nomem_encr") %>%
full_join(liss_background, by = "nomem_encr") %>%
full_join(liss_housing, by = "nomem_encr") %>%
full_join(liss_family, by = "nomem_encr") %>%
arrange(nomem_encr)
#clean the global environment.
rm(file_names,
liss_files,
liss_merged,
i,
liss_pol,
liss_background,
liss_family)
We want cases that participated at least once in the leisure and integration (LI) module of the LISS. So, let’s create a filter variable and filter out respondents who did not participate in the LI module.
#first create a subset of the data, so we can use rowwise to create a selection id.
liss <- liss %>%
rowwise() %>%
#create filter variable
mutate(na_lei_int = sum(is.na(
c(
cs08a_m,
cs09b_m,
cs10c_m,
cs11d_m,
cs12e_m,
cs13f_m,
cs14g_m,
cs15h_m,
cs16i_m,
cs17j_m,
cs18k_m
)
))) %>%
#use only the observations that have participated in at least one wave of the leisure and integration data. We can of course change this later on.
filter(na_lei_int < 11) %>%
ungroup()
#set all haven labelled into double format
liss <- liss %>%
mutate(across(.cols = 1:10645,
.fns = ~as.numeric(.x)))
We go from 24469 cases to 14473 cases.
Now we turn to selecting the variables we need from the LISS core files
Select and rename variables we need from the background variables module
#get the background data and rename the columns.
liss_avars <- liss %>%
select(
nomem_encr,
geslacht.1,
positie.1,
gebjaar.1,
leeftijd.1,
lftdcat.1,
aantalhh.1,
aantalki.1,
partner.1,
burgstat.1,
woonvorm.1,
woning.1,
sted.1,
belbezig.1,
brutoink.1,
nettoink.1,
brutocat.1,
nettocat.1,
oplzon.1,
oplmet.1,
oplcat.1,
nohouse_encr.1,
geslacht.2,
positie.2,
gebjaar.2,
leeftijd.2,
lftdcat.2,
aantalhh.2,
aantalki.2,
partner.2,
burgstat.2,
woonvorm.2,
woning.2,
sted.2,
belbezig.2,
brutoink.2,
nettoink.2,
brutocat.2,
nettocat.2,
oplzon.2,
oplmet.2,
oplcat.2,
nohouse_encr.2,
geslacht.3,
positie.3,
gebjaar.3,
leeftijd.3,
lftdcat.3,
aantalhh.3,
aantalki.3,
partner.3,
burgstat.3,
woonvorm.3,
woning.3,
sted.3,
belbezig.3,
brutoink.3,
nettoink.3,
brutocat.3,
nettocat.3,
oplzon.3,
oplmet.3,
oplcat.3,
nohouse_encr.3,
geslacht.4,
positie.4,
gebjaar.4,
leeftijd.4,
lftdcat.4,
aantalhh.4,
aantalki.4,
partner.4,
burgstat.4,
woonvorm.4,
woning.4,
sted.4,
belbezig.4,
brutoink.4,
nettoink.4,
brutocat.4,
nettocat.4,
oplzon.4,
oplmet.4,
oplcat.4,
nohouse_encr.4,
geslacht.5,
positie.5,
gebjaar.5,
leeftijd.5,
lftdcat.5,
aantalhh.5,
aantalki.5,
partner.5,
burgstat.5,
woonvorm.5,
woning.5,
sted.5,
belbezig.5,
brutoink.5,
nettoink.5,
brutocat.5,
nettocat.5,
oplzon.5,
oplmet.5,
oplcat.5,
nohouse_encr.5,
geslacht.6,
positie.6,
gebjaar.6,
leeftijd.6,
lftdcat.6,
aantalhh.6,
aantalki.6,
partner.6,
burgstat.6,
woonvorm.6,
woning.6,
sted.6,
belbezig.6,
brutoink.6,
nettoink.6,
brutocat.6,
nettocat.6,
oplzon.6,
oplmet.6,
oplcat.6,
nohouse_encr.6,
geslacht.7,
positie.7,
gebjaar.7,
leeftijd.7,
lftdcat.7,
aantalhh.7,
aantalki.7,
partner.7,
burgstat.7,
woonvorm.7,
woning.7,
sted.7,
belbezig.7,
brutoink.7,
nettoink.7,
brutocat.7,
nettocat.7,
oplzon.7,
oplmet.7,
oplcat.7,
nohouse_encr.7,
geslacht.8,
positie.8,
gebjaar.8,
leeftijd.8,
lftdcat.8,
aantalhh.8,
aantalki.8,
partner.8,
burgstat.8,
woonvorm.8,
woning.8,
sted.8,
belbezig.8,
brutoink.8,
nettoink.8,
brutocat.8,
nettocat.8,
oplzon.8,
oplmet.8,
oplcat.8,
nohouse_encr.8,
geslacht.9,
positie.9,
gebjaar.9,
leeftijd.9,
lftdcat.9,
aantalhh.9,
aantalki.9,
partner.9,
burgstat.9,
woonvorm.9,
woning.9,
sted.9,
belbezig.9,
brutoink.9,
nettoink.9,
brutocat.9,
nettocat.9,
oplzon.9,
oplmet.9,
oplcat.9,
nohouse_encr.9,
geslacht.10,
positie.10,
gebjaar.10,
leeftijd.10,
lftdcat.10,
aantalhh.10,
aantalki.10,
partner.10,
burgstat.10,
woonvorm.10,
woning.10,
sted.10,
belbezig.10,
brutoink.10,
nettoink.10,
brutocat.10,
nettocat.10,
oplzon.10,
oplmet.10,
oplcat.10,
nohouse_encr.10,
geslacht.11,
positie.11,
gebjaar.11,
leeftijd.11,
lftdcat.11,
aantalhh.11,
aantalki.11,
partner.11,
burgstat.11,
woonvorm.11,
woning.11,
sted.11,
belbezig.11,
brutoink.11,
nettoink.11,
brutocat.11,
nettocat.11,
oplzon.11,
oplmet.11,
oplcat.11,
nohouse_encr.11
)
#get the background data and rename the columns.
#For the first three waves there are is no data on this variable
liss_origin <- liss %>%
select(
nomem_encr,
herkomstgroep.4,
herkomstgroep.5,
herkomstgroep.6,
herkomstgroep.7,
herkomstgroep.8,
herkomstgroep.9,
herkomstgroep.10,
herkomstgroep.11
)
names(liss_origin) <-
c(
"nomem_encr",
"origin.4",
"origin.5",
"origin.6",
"origin.7",
"origin.8",
"origin.9",
"origin.10",
"origin.11"
)
#create ego origin 1-3 with NA's so we can later merge them into a long file.
liss_origin$origin.1 <- NA
liss_origin$origin.2 <- NA
liss_origin$origin.3 <- NA
#For some reason the reshape command bugs when the ordering is not correct.
liss_origin <- liss_origin[, c(1, 10:12, 2:9)] %>%
mutate(across(.cols = 2:4,
.fns = ~as.numeric(.x)))
Rename the alter id variables.
#alter ids
liss_alter_id <- liss %>%
select(
nomem_encr,
name1_rec.1,
name2_rec.1,
name3_rec.1,
name4_rec.1,
name5_rec.1,
name1_rec.2,
name2_rec.2,
name3_rec.2,
name4_rec.2,
name5_rec.2,
name1_rec.3,
name2_rec.3,
name3_rec.3,
name4_rec.3,
name5_rec.3,
name1_rec.4,
name2_rec.4,
name3_rec.4,
name4_rec.4,
name5_rec.4,
name1_rec.5,
name2_rec.5,
name3_rec.5,
name4_rec.5,
name5_rec.5,
name1_rec.6,
name2_rec.6,
name3_rec.6,
name4_rec.6,
name5_rec.6,
name1_rec.7,
name2_rec.7,
name3_rec.7,
name4_rec.7,
name5_rec.7,
name1_rec.8,
name2_rec.8,
name3_rec.8,
name4_rec.8,
name5_rec.8,
name1_rec.9,
name2_rec.9,
name3_rec.9,
name4_rec.9,
name5_rec.9,
name1_rec.10,
name2_rec.10,
name3_rec.10,
name4_rec.10,
name5_rec.10,
name1_rec.11,
name2_rec.11,
name3_rec.11,
name4_rec.11,
name5_rec.11
)
#rename the alter id's
names(liss_alter_id) <-
c(
"nomem_encr",
"alter_id_1.1",
"alter_id_2.1",
"alter_id_3.1",
"alter_id_4.1",
"alter_id_5.1",
"alter_id_1.2",
"alter_id_2.2",
"alter_id_3.2",
"alter_id_4.2",
"alter_id_5.2",
"alter_id_1.3",
"alter_id_2.3",
"alter_id_3.3",
"alter_id_4.3",
"alter_id_5.3",
"alter_id_1.4",
"alter_id_2.4",
"alter_id_3.4",
"alter_id_4.4",
"alter_id_5.4",
"alter_id_1.5",
"alter_id_2.5",
"alter_id_3.5",
"alter_id_4.5",
"alter_id_5.5",
"alter_id_1.6",
"alter_id_2.6",
"alter_id_3.6",
"alter_id_4.6",
"alter_id_5.6",
"alter_id_1.7",
"alter_id_2.7",
"alter_id_3.7",
"alter_id_4.7",
"alter_id_5.7",
"alter_id_1.8",
"alter_id_2.8",
"alter_id_3.8",
"alter_id_4.8",
"alter_id_5.8",
"alter_id_1.9",
"alter_id_2.9",
"alter_id_3.9",
"alter_id_4.9",
"alter_id_5.9",
"alter_id_1.10",
"alter_id_2.10",
"alter_id_3.10",
"alter_id_4.10",
"alter_id_5.10",
"alter_id_1.11",
"alter_id_2.11",
"alter_id_3.11",
"alter_id_4.11",
"alter_id_5.11"
)
Extract and rename the alter variables
#selecting the alter data.
liss_alters <- liss %>%
select(nomem_encr,cs08a326, cs08a315, cs08a320, cs08a328, cs08a329, cs08a324, cs08a323, cs08a321, cs08a300, cs08a327,
cs08a337, cs08a316, cs08a331, cs08a339, cs08a340, cs08a335, cs08a334, cs08a332, cs08a301, cs08a338,
cs08a348, cs08a317, cs08a342, cs08a350, cs08a351, cs08a346, cs08a345, cs08a343, cs08a302, cs08a349,
cs08a359, cs08a318, cs08a353, cs08a361, cs08a362, cs08a357, cs08a356, cs08a354, cs08a303, cs08a360,
cs08a370, cs08a319, cs08a364, cs08a372, cs08a373, cs08a368, cs08a367, cs08a365, cs08a304, cs08a371,
cs09b326, cs09b315, cs09b320, cs09b328, cs09b329, cs09b324, cs09b323, cs09b321, cs09b300, cs09b327,
cs09b337, cs09b316, cs09b331, cs09b339, cs09b340, cs09b335, cs09b334, cs09b332, cs09b301, cs09b338,
cs09b348, cs09b317, cs09b342, cs09b350, cs09b351, cs09b346, cs09b345, cs09b343, cs09b302, cs09b349,
cs09b359, cs09b318, cs09b353, cs09b361, cs09b362, cs09b357, cs09b356, cs09b354, cs09b303, cs09b360,
cs09b370, cs09b319, cs09b364, cs09b372, cs09b373, cs09b368, cs09b367, cs09b365, cs09b304, cs09b371,
cs10c326, cs10c315, cs10c320, cs10c328, cs10c329, cs10c324, cs10c323, cs10c321, cs10c300, cs10c327,
cs10c337, cs10c316, cs10c331, cs10c339, cs10c340, cs10c335, cs10c334, cs10c332, cs10c301, cs10c338,
cs10c348, cs10c317, cs10c342, cs10c350, cs10c351, cs10c346, cs10c345, cs10c343, cs10c302, cs10c349,
cs10c359, cs10c318, cs10c353, cs10c361, cs10c362, cs10c357, cs10c356, cs10c354, cs10c303, cs10c360,
cs10c370, cs10c319, cs10c364, cs10c372, cs10c373, cs10c368, cs10c367, cs10c365, cs10c304, cs10c371,
cs11d326, cs11d315, cs11d320, cs11d328, cs11d329, cs11d324, cs11d323, cs11d321, cs11d300, cs11d327,
cs11d337, cs11d316, cs11d331, cs11d339, cs11d340, cs11d335, cs11d334, cs11d332, cs11d301, cs11d338,
cs11d348, cs11d317, cs11d342, cs11d350, cs11d351, cs11d346, cs11d345, cs11d343, cs11d302, cs11d349,
cs11d359, cs11d318, cs11d353, cs11d361, cs11d362, cs11d357, cs11d356, cs11d354, cs11d303, cs11d360,
cs11d370, cs11d319, cs11d364, cs11d372, cs11d373, cs11d368, cs11d367, cs11d365, cs11d304, cs11d371,
cs12e326, cs12e315, cs12e320, cs12e328, cs12e329, cs12e324, cs12e323, cs12e321, cs12e300, cs12e327,
cs12e337, cs12e316, cs12e331, cs12e339, cs12e340, cs12e335, cs12e334, cs12e332, cs12e301, cs12e338,
cs12e348, cs12e317, cs12e342, cs12e350, cs12e351, cs12e346, cs12e345, cs12e343, cs12e302, cs12e349,
cs12e359, cs12e318, cs12e353, cs12e361, cs12e362, cs12e357, cs12e356, cs12e354, cs12e303, cs12e360,
cs12e370, cs12e319, cs12e364, cs12e372, cs12e373, cs12e368, cs12e367, cs12e365, cs12e304, cs12e371,
cs13f326, cs13f315, cs13f320, cs13f328, cs13f329, cs13f324, cs13f323, cs13f321, cs13f300, cs13f327,
cs13f337, cs13f316, cs13f331, cs13f339, cs13f340, cs13f335, cs13f334, cs13f332, cs13f301, cs13f338,
cs13f348, cs13f317, cs13f342, cs13f350, cs13f351, cs13f346, cs13f345, cs13f343, cs13f302, cs13f349,
cs13f359, cs13f318, cs13f353, cs13f361, cs13f362, cs13f357, cs13f356, cs13f354, cs13f303, cs13f360,
cs13f370, cs13f319, cs13f364, cs13f372, cs13f373, cs13f368, cs13f367, cs13f365, cs13f304, cs13f371,
cs14g326, cs14g315, cs14g320, cs14g328, cs14g329, cs14g324, cs14g323, cs14g321, cs14g300, cs14g327,
cs14g337, cs14g316, cs14g331, cs14g339, cs14g340, cs14g335, cs14g334, cs14g332, cs14g301, cs14g338,
cs14g348, cs14g317, cs14g342, cs14g350, cs14g351, cs14g346, cs14g345, cs14g343, cs14g302, cs14g349,
cs14g359, cs14g318, cs14g353, cs14g361, cs14g362, cs14g357, cs14g356, cs14g354, cs14g303, cs14g360,
cs14g370, cs14g319, cs14g364, cs14g372, cs14g373, cs14g368, cs14g367, cs14g365, cs14g304, cs14g371,
cs15h326, cs15h315, cs15h320, cs15h328, cs15h329, cs15h324, cs15h323, cs15h321, cs15h300, cs15h327,
cs15h337, cs15h316, cs15h331, cs15h339, cs15h340, cs15h335, cs15h334, cs15h332, cs15h301, cs15h338,
cs15h348, cs15h317, cs15h342, cs15h350, cs15h351, cs15h346, cs15h345, cs15h343, cs15h302, cs15h349,
cs15h359, cs15h318, cs15h353, cs15h361, cs15h362, cs15h357, cs15h356, cs15h354, cs15h303, cs15h360,
cs15h370, cs15h319, cs15h364, cs15h372, cs15h373, cs15h368, cs15h367, cs15h365, cs15h304, cs15h371,
cs16i326, cs16i315, cs16i320, cs16i328, cs16i329, cs16i324, cs16i323, cs16i321, cs16i300, cs16i327,
cs16i337, cs16i316, cs16i331, cs16i339, cs16i340, cs16i335, cs16i334, cs16i332, cs16i301, cs16i338,
cs16i348, cs16i317, cs16i342, cs16i350, cs16i351, cs16i346, cs16i345, cs16i343, cs16i302, cs16i349,
cs16i359, cs16i318, cs16i353, cs16i361, cs16i362, cs16i357, cs16i356, cs16i354, cs16i303, cs16i360,
cs16i370, cs16i319, cs16i364, cs16i372, cs16i373, cs16i368, cs16i367, cs16i365, cs16i304, cs16i371,
cs17j326, cs17j315, cs17j320, cs17j328, cs17j329, cs17j324, cs17j323, cs17j321, cs17j300, cs17j327,
cs17j337, cs17j316, cs17j331, cs17j339, cs17j340, cs17j335, cs17j334, cs17j332, cs17j301, cs17j338,
cs17j348, cs17j317, cs17j342, cs17j350, cs17j351, cs17j346, cs17j345, cs17j343, cs17j302, cs17j349,
cs17j359, cs17j318, cs17j353, cs17j361, cs17j362, cs17j357, cs17j356, cs17j354, cs17j303, cs17j360,
cs17j370, cs17j319, cs17j364, cs17j372, cs17j373, cs17j368, cs17j367, cs17j365, cs17j304, cs17j371,
cs18k326, cs18k315, cs18k320, cs18k328, cs18k329, cs18k324, cs18k323, cs18k321, cs18k300, cs18k327,
cs18k337, cs18k316, cs18k331, cs18k339, cs18k340, cs18k335, cs18k334, cs18k332, cs18k301, cs18k338,
cs18k348, cs18k317, cs18k342, cs18k350, cs18k351, cs18k346, cs18k345, cs18k343, cs18k302, cs18k349,
cs18k359, cs18k318, cs18k353, cs18k361, cs18k362, cs18k357, cs18k356, cs18k354, cs18k303, cs18k360,
cs18k370, cs18k319, cs18k364, cs18k372, cs18k373, cs18k368, cs18k367, cs18k365, cs18k304, cs18k371,
cs08a305, cs08a306, cs08a307, cs08a308, cs08a309, cs08a310, cs08a311, cs08a312,
cs08a313, cs08a314,
cs09b305, cs09b306, cs09b307, cs09b308, cs09b309, cs09b310, cs09b311, cs09b312,
cs09b313, cs09b314,
cs10c305, cs10c306, cs10c307, cs10c308, cs10c309, cs10c310, cs10c311, cs10c312,
cs10c313, cs10c314,
cs11d305, cs11d306, cs11d307, cs11d308, cs11d309, cs11d310, cs11d311, cs11d312,
cs11d313, cs11d314,
cs12e305, cs12e306, cs12e307, cs12e308, cs12e309, cs12e310, cs12e311, cs12e312,
cs12e313, cs12e314,
cs13f305, cs13f306, cs13f307, cs13f308, cs13f309, cs13f310, cs13f311, cs13f312,
cs13f313, cs13f314,
cs14g305, cs14g306, cs14g307, cs14g308, cs14g309, cs14g310, cs14g311, cs14g312,
cs14g313, cs14g314,
cs15h305, cs15h306, cs15h307, cs15h308, cs15h309, cs15h310, cs15h311, cs15h312,
cs15h313, cs15h314,
cs16i305, cs16i306, cs16i307, cs16i308, cs16i309, cs16i310, cs16i311, cs16i312,
cs16i313, cs16i314,
cs17j305, cs17j306, cs17j307, cs17j308, cs17j309, cs17j310, cs17j311, cs17j312,
cs17j313, cs17j314,
cs18k305, cs18k306, cs18k307, cs18k308, cs18k309, cs18k310, cs18k311, cs18k312,
cs18k313, cs18k314,
cs08a325, cs08a336, cs08a347, cs08a358, cs08a369,
cs09b325, cs09b336, cs09b347, cs09b358, cs09b369,
cs10c325, cs10c336, cs10c347, cs10c358, cs10c369,
cs11d325, cs11d336, cs11d347, cs11d358, cs11d369,
cs12e325, cs12e336, cs12e347, cs12e358, cs12e369,
cs13f325, cs13f336, cs13f347, cs13f358, cs13f369,
cs14g325, cs14g336, cs14g347, cs14g358, cs14g369,
cs15h325, cs15h336, cs15h347, cs15h358, cs15h369,
cs16i325, cs16i336, cs16i347, cs16i358, cs16i369,
cs17j325, cs17j336, cs17j347, cs17j358, cs17j369,
cs18k325, cs18k336, cs18k347, cs18k358, cs18k369,
cs08a_m, cs09b_m, cs10c_m, cs11d_m, cs12e_m, cs13f_m, cs14g_m, cs15h_m, cs16i_m, cs17j_m, cs18k_m
)
#Rename the alter variables.
names(liss_alters) <- c("nomem_encr", "educ_alter1.1","gender_alter1.1", "origin_alter1.1", "prof_alter1.1", "age_alter1.1", "poltalk_alter1.1", "talk_alter1.1", "rel_alter1.1", "dear_alter1.1", "work_a1.1",
"educ_alter2.1","gender_alter2.1", "origin_alter2.1", "prof_alter2.1", "age_alter2.1", "poltalk_alter2.1", "talk_alter2.1", "rel_alter2.1", "dear_alter2.1", "work_a2.1",
"educ_alter3.1","gender_alter3.1", "origin_alter3.1", "prof_alter3.1", "age_alter3.1", "poltalk_alter3.1", "talk_alter3.1", "rel_alter3.1", "dear_alter3.1", "work_a3.1",
"educ_alter4.1","gender_alter4.1", "origin_alter4.1", "prof_alter4.1", "age_alter4.1", "poltalk_alter4.1", "talk_alter4.1", "rel_alter4.1", "dear_alter4.1", "work_a4.1",
"educ_alter5.1","gender_alter5.1", "origin_alter5.1", "prof_alter5.1", "age_alter5.1", "poltalk_alter5.1", "talk_alter5.1", "rel_alter5.1", "dear_alter5.1", "work_a5.1",
"educ_alter1.2","gender_alter1.2", "origin_alter1.2", "prof_alter1.2", "age_alter1.2", "poltalk_alter1.2", "talk_alter1.2", "rel_alter1.2", "dear_alter1.2", "work_a1.2",
"educ_alter2.2","gender_alter2.2", "origin_alter2.2", "prof_alter2.2", "age_alter2.2", "poltalk_alter2.2", "talk_alter2.2", "rel_alter2.2", "dear_alter2.2", "work_a2.2",
"educ_alter3.2","gender_alter3.2", "origin_alter3.2", "prof_alter3.2", "age_alter3.2", "poltalk_alter3.2", "talk_alter3.2", "rel_alter3.2", "dear_alter3.2", "work_a3.2",
"educ_alter4.2","gender_alter4.2", "origin_alter4.2", "prof_alter4.2", "age_alter4.2", "poltalk_alter4.2", "talk_alter4.2", "rel_alter4.2", "dear_alter4.2", "work_a4.2",
"educ_alter5.2","gender_alter5.2", "origin_alter5.2", "prof_alter5.2", "age_alter5.2", "poltalk_alter5.2", "talk_alter5.2", "rel_alter5.2", "dear_alter5.2", "work_a5.2",
"educ_alter1.3","gender_alter1.3", "origin_alter1.3", "prof_alter1.3", "age_alter1.3", "poltalk_alter1.3", "talk_alter1.3", "rel_alter1.3", "dear_alter1.3", "work_a1.3",
"educ_alter2.3","gender_alter2.3", "origin_alter2.3", "prof_alter2.3", "age_alter2.3", "poltalk_alter2.3", "talk_alter2.3", "rel_alter2.3", "dear_alter2.3", "work_a2.3",
"educ_alter3.3","gender_alter3.3", "origin_alter3.3", "prof_alter3.3", "age_alter3.3", "poltalk_alter3.3", "talk_alter3.3", "rel_alter3.3", "dear_alter3.3", "work_a3.3",
"educ_alter4.3","gender_alter4.3", "origin_alter4.3", "prof_alter4.3", "age_alter4.3", "poltalk_alter4.3", "talk_alter4.3", "rel_alter4.3", "dear_alter4.3", "work_a4.3",
"educ_alter5.3","gender_alter5.3", "origin_alter5.3", "prof_alter5.3", "age_alter5.3", "poltalk_alter5.3", "talk_alter5.3", "rel_alter5.3", "dear_alter5.3", "work_a5.3",
"educ_alter1.4","gender_alter1.4", "origin_alter1.4", "prof_alter1.4", "age_alter1.4", "poltalk_alter1.4", "talk_alter1.4", "rel_alter1.4", "dear_alter1.4", "work_a1.4",
"educ_alter2.4","gender_alter2.4", "origin_alter2.4", "prof_alter2.4", "age_alter2.4", "poltalk_alter2.4", "talk_alter2.4", "rel_alter2.4", "dear_alter2.4", "work_a2.4",
"educ_alter3.4","gender_alter3.4", "origin_alter3.4", "prof_alter3.4", "age_alter3.4", "poltalk_alter3.4", "talk_alter3.4", "rel_alter3.4", "dear_alter3.4", "work_a3.4",
"educ_alter4.4","gender_alter4.4", "origin_alter4.4", "prof_alter4.4", "age_alter4.4", "poltalk_alter4.4", "talk_alter4.4", "rel_alter4.4", "dear_alter4.4", "work_a4.4",
"educ_alter5.4","gender_alter5.4", "origin_alter5.4", "prof_alter5.4", "age_alter5.4", "poltalk_alter5.4", "talk_alter5.4", "rel_alter5.4", "dear_alter5.4", "work_a5.4",
"educ_alter1.5","gender_alter1.5", "origin_alter1.5", "prof_alter1.5", "age_alter1.5", "poltalk_alter1.5", "talk_alter1.5", "rel_alter1.5", "dear_alter1.5", "work_a1.5",
"educ_alter2.5","gender_alter2.5", "origin_alter2.5", "prof_alter2.5", "age_alter2.5", "poltalk_alter2.5", "talk_alter2.5", "rel_alter2.5", "dear_alter2.5", "work_a2.5",
"educ_alter3.5","gender_alter3.5", "origin_alter3.5", "prof_alter3.5", "age_alter3.5", "poltalk_alter3.5", "talk_alter3.5", "rel_alter3.5", "dear_alter3.5", "work_a3.5",
"educ_alter4.5","gender_alter4.5", "origin_alter4.5", "prof_alter4.5", "age_alter4.5", "poltalk_alter4.5", "talk_alter4.5", "rel_alter4.5", "dear_alter4.5", "work_a4.5",
"educ_alter5.5","gender_alter5.5", "origin_alter5.5", "prof_alter5.5", "age_alter5.5", "poltalk_alter5.5", "talk_alter5.5", "rel_alter5.5", "dear_alter5.5", "work_a5.5",
"educ_alter1.6","gender_alter1.6", "origin_alter1.6", "prof_alter1.6", "age_alter1.6", "poltalk_alter1.6", "talk_alter1.6", "rel_alter1.6", "dear_alter1.6", "work_a1.6",
"educ_alter2.6","gender_alter2.6", "origin_alter2.6", "prof_alter2.6", "age_alter2.6", "poltalk_alter2.6", "talk_alter2.6", "rel_alter2.6", "dear_alter2.6", "work_a2.6",
"educ_alter3.6","gender_alter3.6", "origin_alter3.6", "prof_alter3.6", "age_alter3.6", "poltalk_alter3.6", "talk_alter3.6", "rel_alter3.6", "dear_alter3.6", "work_a3.6",
"educ_alter4.6","gender_alter4.6", "origin_alter4.6", "prof_alter4.6", "age_alter4.6", "poltalk_alter4.6", "talk_alter4.6", "rel_alter4.6", "dear_alter4.6", "work_a4.6",
"educ_alter5.6","gender_alter5.6", "origin_alter5.6", "prof_alter5.6", "age_alter5.6", "poltalk_alter5.6", "talk_alter5.6", "rel_alter5.6", "dear_alter5.6", "work_a5.6",
"educ_alter1.7","gender_alter1.7", "origin_alter1.7", "prof_alter1.7", "age_alter1.7", "poltalk_alter1.7", "talk_alter1.7", "rel_alter1.7", "dear_alter1.7", "work_a1.7",
"educ_alter2.7","gender_alter2.7", "origin_alter2.7", "prof_alter2.7", "age_alter2.7", "poltalk_alter2.7", "talk_alter2.7", "rel_alter2.7", "dear_alter2.7", "work_a2.7",
"educ_alter3.7","gender_alter3.7", "origin_alter3.7", "prof_alter3.7", "age_alter3.7", "poltalk_alter3.7", "talk_alter3.7", "rel_alter3.7", "dear_alter3.7", "work_a3.7",
"educ_alter4.7","gender_alter4.7", "origin_alter4.7", "prof_alter4.7", "age_alter4.7", "poltalk_alter4.7", "talk_alter4.7", "rel_alter4.7", "dear_alter4.7", "work_a4.7",
"educ_alter5.7","gender_alter5.7", "origin_alter5.7", "prof_alter5.7", "age_alter5.7", "poltalk_alter5.7", "talk_alter5.7", "rel_alter5.7", "dear_alter5.7", "work_a5.7",
"educ_alter1.8","gender_alter1.8", "origin_alter1.8", "prof_alter1.8", "age_alter1.8", "poltalk_alter1.8", "talk_alter1.8", "rel_alter1.8", "dear_alter1.8", "work_a1.8",
"educ_alter2.8","gender_alter2.8", "origin_alter2.8", "prof_alter2.8", "age_alter2.8", "poltalk_alter2.8", "talk_alter2.8", "rel_alter2.8", "dear_alter2.8", "work_a2.8",
"educ_alter3.8","gender_alter3.8", "origin_alter3.8", "prof_alter3.8", "age_alter3.8", "poltalk_alter3.8", "talk_alter3.8", "rel_alter3.8", "dear_alter3.8", "work_a3.8",
"educ_alter4.8","gender_alter4.8", "origin_alter4.8", "prof_alter4.8", "age_alter4.8", "poltalk_alter4.8", "talk_alter4.8", "rel_alter4.8", "dear_alter4.8", "work_a4.8",
"educ_alter5.8","gender_alter5.8", "origin_alter5.8", "prof_alter5.8", "age_alter5.8", "poltalk_alter5.8", "talk_alter5.8", "rel_alter5.8", "dear_alter5.8", "work_a5.8",
"educ_alter1.9","gender_alter1.9", "origin_alter1.9", "prof_alter1.9", "age_alter1.9", "poltalk_alter1.9", "talk_alter1.9", "rel_alter1.9", "dear_alter1.9", "work_a1.9",
"educ_alter2.9","gender_alter2.9", "origin_alter2.9", "prof_alter2.9", "age_alter2.9", "poltalk_alter2.9", "talk_alter2.9", "rel_alter2.9", "dear_alter2.9", "work_a2.9",
"educ_alter3.9","gender_alter3.9", "origin_alter3.9", "prof_alter3.9", "age_alter3.9", "poltalk_alter3.9", "talk_alter3.9", "rel_alter3.9", "dear_alter3.9", "work_a3.9",
"educ_alter4.9","gender_alter4.9", "origin_alter4.9", "prof_alter4.9", "age_alter4.9", "poltalk_alter4.9", "talk_alter4.9", "rel_alter4.9", "dear_alter4.9", "work_a4.9",
"educ_alter5.9","gender_alter5.9", "origin_alter5.9", "prof_alter5.9", "age_alter5.9", "poltalk_alter5.9", "talk_alter5.9", "rel_alter5.9", "dear_alter5.9", "work_a5.9",
"educ_alter1.10","gender_alter1.10", "origin_alter1.10", "prof_alter1.10", "age_alter1.10", "poltalk_alter1.10", "talk_alter1.10", "rel_alter1.10", "dear_alter1.10", "work_a1.10",
"educ_alter2.10","gender_alter2.10", "origin_alter2.10", "prof_alter2.10", "age_alter2.10", "poltalk_alter2.10", "talk_alter2.10", "rel_alter2.10", "dear_alter2.10", "work_a2.10",
"educ_alter3.10","gender_alter3.10", "origin_alter3.10", "prof_alter3.10", "age_alter3.10", "poltalk_alter3.10", "talk_alter3.10", "rel_alter3.10", "dear_alter3.10", "work_a3.10",
"educ_alter4.10","gender_alter4.10", "origin_alter4.10", "prof_alter4.10", "age_alter4.10", "poltalk_alter4.10", "talk_alter4.10", "rel_alter4.10", "dear_alter4.10", "work_a4.10",
"educ_alter5.10","gender_alter5.10", "origin_alter5.10", "prof_alter5.10", "age_alter5.10", "poltalk_alter5.10", "talk_alter5.10", "rel_alter5.10", "dear_alter5.10", "work_a5.10",
"educ_alter1.11","gender_alter1.11", "origin_alter1.11", "prof_alter1.11", "age_alter1.11", "poltalk_alter1.11", "talk_alter1.11", "rel_alter1.11", "dear_alter1.11", "work_a1.11",
"educ_alter2.11","gender_alter2.11", "origin_alter2.11", "prof_alter2.11", "age_alter2.11", "poltalk_alter2.11", "talk_alter2.11", "rel_alter2.11", "dear_alter2.11", "work_a2.11",
"educ_alter3.11","gender_alter3.11", "origin_alter3.11", "prof_alter3.11", "age_alter3.11", "poltalk_alter3.11", "talk_alter3.11", "rel_alter3.11", "dear_alter3.11", "work_a3.11",
"educ_alter4.11","gender_alter4.11", "origin_alter4.11", "prof_alter4.11", "age_alter4.11", "poltalk_alter4.11", "talk_alter4.11", "rel_alter4.11", "dear_alter4.11", "work_a4.11",
"educ_alter5.11","gender_alter5.11", "origin_alter5.11", "prof_alter5.11", "age_alter5.11", "poltalk_alter5.11", "talk_alter5.11", "rel_alter5.11", "dear_alter5.11", "work_a5.11",
"close_12.1", "close_13.1", "close_14.1", "close_15.1", "close_23.1", "close_24.1", "close_25.1", "close_34.1", "close_35.1", "close_45.1",
"close_12.2", "close_13.2", "close_14.2", "close_15.2", "close_23.2", "close_24.2", "close_25.2", "close_34.2", "close_35.2", "close_45.2",
"close_12.3", "close_13.3", "close_14.3", "close_15.3", "close_23.3", "close_24.3", "close_25.3", "close_34.3", "close_35.3", "close_45.3",
"close_12.4", "close_13.4", "close_14.4", "close_15.4", "close_23.4", "close_24.4", "close_25.4", "close_34.4", "close_35.4", "close_45.4",
"close_12.5", "close_13.5", "close_14.5", "close_15.5", "close_23.5", "close_24.5", "close_25.5", "close_34.5", "close_35.5", "close_45.5",
"close_12.6", "close_13.6", "close_14.6", "close_15.6", "close_23.6", "close_24.6", "close_25.6", "close_34.6", "close_35.6", "close_45.6",
"close_12.7", "close_13.7", "close_14.7", "close_15.7", "close_23.7", "close_24.7", "close_25.7", "close_34.7", "close_35.7", "close_45.7",
"close_12.8", "close_13.8", "close_14.8", "close_15.8", "close_23.8", "close_24.8", "close_25.8", "close_34.8", "close_35.8", "close_45.8",
"close_12.9", "close_13.9", "close_14.9", "close_15.9", "close_23.9", "close_24.9", "close_25.9", "close_34.9", "close_35.9", "close_45.9",
"close_12.10", "close_13.10", "close_14.10", "close_15.10", "close_23.10", "close_24.10", "close_25.10", "close_34.10", "close_35.10", "close_45.10",
"close_12.11", "close_13.11", "close_14.11", "close_15.11", "close_23.11", "close_24.11", "close_25.11", "close_34.11", "close_35.11", "close_45.11",
"length_1.1", "length_2.1", "length_3.1", "length_4.1", "length_5.1",
"length_1.2", "length_2.2", "length_3.2", "length_4.2", "length_5.2",
"length_1.3", "length_2.3", "length_3.3", "length_4.3", "length_5.3",
"length_1.4", "length_2.4", "length_3.4", "length_4.4", "length_5.4",
"length_1.5", "length_2.5", "length_3.5", "length_4.5", "length_5.5",
"length_1.6", "length_2.6", "length_3.6", "length_4.6", "length_5.6",
"length_1.7", "length_2.7", "length_3.7", "length_4.7", "length_5.7",
"length_1.8", "length_2.8", "length_3.8", "length_4.8", "length_5.8",
"length_1.9", "length_2.9", "length_3.9", "length_4.9", "length_5.9",
"length_1.10", "length_2.10", "length_3.10", "length_4.10", "length_5.10",
"length_1.11", "length_2.11", "length_3.11", "length_4.11", "length_5.11", "leisure_part.1", "leisure_part.2","leisure_part.3","leisure_part.4", "leisure_part.5",
"leisure_part.6", "leisure_part.7","leisure_part.8", "leisure_part.9", "leisure_part.10","leisure_part.11")
Extract and rename the housing data
#LISS housing
liss_housing <- liss %>%
select(nomem_encr, matches("036"), matches("037")) %>%
select(nomem_encr, matches("cd"))
names(liss_housing) <-
c(
"nomem_encr",
"year_residence.1",
"year_residence.2",
"year_residence.3",
"year_residence.4",
"year_residence.5",
"year_residence.6",
"year_residence.7",
"year_residence.8",
"year_residence.9",
"year_residence.10",
"year_residence.11",
"year_municipality.1",
"year_municipality.2",
"year_municipality.3",
"year_municipality.4",
"year_municipality.5",
"year_municipality.6",
"year_municipality.7",
"year_municipality.8",
"year_municipality.9",
"year_municipality.10",
"year_municipality.11"
)
liss_family <- liss %>%
select(nomem_encr,
matches("024"),
matches("402"),
matches("403"),
matches("404"),
matches("035"),
matches("454"),
matches("037"),
matches("456")
) %>%
select(nomem_encr, matches("cf"))
names(liss_family) <-
c(
"nomem_encr",
"partner_current.1",
"partner_current.2",
"partner_current.3",
"partner_current.4",
"partner_current.5",
"partner_current.6",
"partner_current.7",
"partner_current.8",
"partner_current.9",
"partner_current.10",
"partner_current.11",
"partner_same.2",
"partner_same.3",
"partner_same.4",
"partner_same.5",
"partner_same.6",
"partner_same.7",
"partner_same.8",
"partner_same.9",
"partner_same.10",
"partner_same.11",
"partner_different_reason.2",
"partner_different_reason.3",
"partner_different_reason.4",
"partner_different_reason.5",
"partner_different_reason.6",
"partner_different_reason.7",
"partner_different_reason.8",
"partner_different_reason.9",
"partner_different_reason.10",
"partner_different_reason.11",
"partner_none_reason.2",
"partner_none_reason.3",
"partner_none_reason.4",
"partner_none_reason.5",
"partner_none_reason.6",
"partner_none_reason.7",
"partner_none_reason.8",
"partner_none_reason.9",
"partner_none_reason.10",
"partner_none_reason.11",
"has_children.1",
"has_children.2",
"has_children.3",
"has_children.4",
"has_children.5",
"has_children.6",
"has_children.7",
"has_children.8",
"has_children.9",
"has_children.10",
"has_children.11",
"birthyear_firstchild.1",
"birthyear_firstchild.2",
"birthyear_firstchild.3",
"birthyear_firstchild.4",
"birthyear_firstchild.5",
"birthyear_firstchild.6",
"birthyear_firstchild.7",
"birthyear_firstchild.8",
"birthyear_firstchild.9",
"birthyear_firstchild.10",
"birthyear_firstchild.11"
)
#combine the different data sources into one wide data file.
liss_wide <- liss_avars %>%
left_join(liss_alters, by = "nomem_encr") %>%
left_join(liss_alter_id, by = "nomem_encr") %>%
left_join(liss_origin, by = "nomem_encr") %>%
left_join(liss_housing, by = "nomem_encr") %>%
left_join(liss_family, by = "nomem_encr")
Reshape the data to a long file and export the data fo a rds file.
#create a long file.
liss_long <- liss_wide %>%
pivot_longer(cols = 2:1109,
names_to = c("measure", "survey_wave"),
names_pattern = "(.+)\\.(.+)",
values_to = "value") %>%
pivot_wider(names_from = measure,
values_from = value)
#set -9 to missing value
liss_long <- liss_long %>%
mutate(across(.fns = ~ ifelse(.x == -9, NA, .x)))
liss_wide <- liss_wide %>%
mutate(across(.fns = ~ ifelse(.x == -9, NA, .x)))
#clean the environment.
rm(list=ls()[! ls() %in% c("liss_wide", "liss_long")])
#Export the data #
#save RData.
save.image("datafiles/data-processed/common_data/0623_v5_liss_merged_core_file.rds")
Copyright © 2023 Jeroense Thijmen