File: Data_Prep_S1S2.R

Comment:  Create dummy variable for ethnicity: 0  option 4 only (Anglo/White), 1  any other option / combination of options 
Category: Data Variable
Code:
table(survey$ethnic_group[!duplicated(survey$id)], useNA = "ifany") survey$ethnicity <- ifelse(survey$ethnic_group == "4", 0, 1) table(survey$ethnicity[!duplicated(survey$id)], useNA = "ifany")

Comment:  Create dummy variable for SES: 1  mother or father completed at least some college (4  some college), 0  otherwise 
Category: Data Variable
Code:
table(survey$mother_educationlevel[!duplicated(survey$id)], useNA = "ifany") table(survey$father_educationlevel[!duplicated(survey$id)], useNA = "ifany") survey$SES <- ifelse(survey$mother_educationlevel >= 4 | survey$father_educationlevel >= 4, 1, 0) table(survey$SES[!duplicated(survey$id)], useNA = "ifany")

Comment:  Weekend  Create dummy variable for weekend: 1  weekend, 0  weekday 
Category: Data Variable
Code:
survey$weekend <- ifelse(weekdays(survey$StartDate, abbr = TRUE) %in% c("Sat", "Sun"), 1, 0)

Comment: Create dummy variable for mixed interaction partners
Category: Data Variable
Code:
survey$no_partners <- apply(survey[c("close_peers", "family", "weak_ties")], 1, sum) survey$mixed_partner <- ifelse(survey$no_partners > 1, 1, 0) table(survey$mixed_partner, useNA = "ifany") # number of observations with mixed interaction partners: 11479 (S1) / 5797 (S2) table(apply(survey[c("close_peers", "family", "weak_ties")], 1, sum), useNA = "ifany") survey$close_peers_all <- survey$close_peers survey$family_all <- survey$family survey$weak_ties_all <- survey$weak_ties survey$close_peers <- ifelse(survey$mixed_partner == 1, NA, survey$close_peers) survey$family <- ifelse(survey$mixed_partner == 1, NA, survey$family) survey$weak_ties <- ifelse(survey$mixed_partner == 1, NA, survey$weak_ties) table(survey$close_peers, useNA = "ifany") # number of observations with interactions with close peers ONLY: 17194 (S1) / 9406 (S2) table(survey$interacting_people[survey$close_peers == 1]) table(survey$family, useNA = "ifany") # number of observations with interactions with family ONLY: 2450 (S1) / 1946 (S2) table(survey$interacting_people[survey$family == 1]) table(survey$weak_ties, useNA = "ifany") # number of observations with interactions with weak ties ONLY: 4336 (S1) / 2823 (S2) table(survey$interacting_people[survey$weak_ties == 1]) table(apply(survey[c("close_peers", "family", "weak_ties")], 1, sum), useNA = "ifany") # 23980 (S1) / 14175 (S2) length(which(survey$mixed_mode == 1 | survey$SKIP2 == 1 | survey$OTHER2 == 1 | is.na(survey$interacting_people) | survey$mixed_partner == 1)) table(apply(survey[c("close_peers_all", "family_all", "weak_ties_all")], 1, sum), useNA = "ifany") # 23980, 10176, 1303 (S1) / 14175, 5116, 681 (S2) length(which(survey$mixed_mode == 1 | survey$SKIP2 == 1 | survey$OTHER2 == 1 | is.na(survey$interacting_people))) survey$no_partners2 <- apply(survey[c("friends_roommates", "significant_other", "family_all", "weak_ties_all")], 1, sum) survey$mixed_partner2 <- ifelse(survey$no_partners2 > 1, 1, 0) table(survey$mixed_partner2, useNA = "ifany") # number of observations with mixed interaction partners: 13456 (S1) / 6847 (S2) table(apply(survey[c("friends_roommates", "significant_other", "family_all", "weak_ties_all")], 1, sum), useNA = "ifany") survey$friends_roommates2 <- ifelse(survey$mixed_partner2 == 1, NA, survey$friends_roommates) survey$significant_other2 <- ifelse(survey$mixed_partner2 == 1, NA, survey$significant_other) survey$family2 <- ifelse(survey$mixed_partner2 == 1, NA, survey$family_all) survey$weak_ties2 <- ifelse(survey$mixed_partner2 == 1, NA, survey$weak_ties_all) table(survey$friends_roommates2, useNA = "ifany") # number of observations with interactions with friends and roommates ONLY: 12882 (S1) / 6865 (S2) table(survey$interacting_people[survey$friends_roommates2 == 1]) table(survey$significant_other2, useNA = "ifany") # number of observations with interactions with significant others ONLY: 2335 (S1) / 1491 (S2) table(survey$interacting_people[survey$significant_other2 == 1]) table(survey$family2, useNA = "ifany") # number of observations with interactions with family ONLY: 2450 (S1) / 1946 (S2) table(survey$interacting_people[survey$family2 == 1]) table(survey$weak_ties2, useNA = "ifany") # number of observations with interactions with weak ties ONLY: 4336 (S1) / 2823 (S2) table(survey$interacting_people[survey$weak_ties2 == 1]) table(apply(survey[c("friends_roommates2", "significant_other2", "family2", "weak_ties2")], 1, sum), useNA = "ifany") # 22003 (S1) / 13125 (S2) length(which(survey$mixed_mode == 1 | survey$SKIP2 == 1 | survey$OTHER2 == 1 | is.na(survey$interacting_people) | survey$mixed_partner2 == 1))

Comment: Create dummy variable for significant others
Category: Data Variable
Code:
survey$significant_other <- ifelse(survey$mixed_mode == 1 | survey$SKIP2 == 1 | survey$OTHER2 == 1 | is.na(survey$interacting_people), NA, ifelse(survey$Significant_other == 1, 1, 0)) table(survey$significant_other, useNA = "ifany") # number of observations with interactions with significant others: 6681 (S1) / 3822 (S2) table(survey$interacting_people[survey$significant_other == 1])