This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shielding_new_variables.R
105 lines (79 loc) · 3.9 KB
/
shielding_new_variables.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Making new variables for survey
library(openxlsx)
library(ggplot2)
library(magrittr)
library(tidyr)
library(dplyr)
library(janitor)
setwd("~/shielding-survey")
# Confidential answers in separate file
# Contains the vectors of answers
# - no_children_answers
# - children_answers
# - household_size_one
# - household_size_two
# - household_size_threeplus
source("new_var_answers.R")
# Getting cleaned data
cs <- read.xlsx("cleaned_survey.xlsx")
cs %<>%
### Age groups
mutate(AgeGroup3 = case_when(is.na(AgeGroup) ~ "unknown",
AgeGroup %in% c("Under 16", "16-24", "25-44", "45-64") ~ "<65",
AgeGroup %in% c("65-69", "70-74", "75-79", "80+") ~ "65+"
)
) %>%
mutate(AgeGroup2 = case_when(is.na(AgeGroup) ~ "unknown",
AgeGroup == "Under 16" ~ "0-15",
AgeGroup %in% c("16-24", "25-44", "45-64") ~ "16-64",
AgeGroup %in% c("65-69", "70-74", "75-79", "80+") ~ "65+"
)
) %>%
### Impairment
mutate(Impairment = case_when(VisualImpairment == "Yes" ~ "any impairment",
HearingImpairment == "Yes" ~ "any impairment",
OtherSensoryImpairment == "Yes" ~ "any impairment",
MobilityImpairment == "Yes" ~ "any impairment",
OtherPhysicalImpairment == "Yes" ~ "any impairment",
LearningDifficulty == "Yes" ~ "any impairment",
NoListedImpairment == "Yes" ~ "no impairment",
TRUE ~ "unknown"
)
) %>%
### Children in household
mutate(ChildrenInHousehold = case_when(HouseholdChildren %in% no_children_answers ~ "no children",
HouseholdChildren %in% children_answers ~ "children",
TRUE ~ "unknown"
)
) %>%
### Number in household
mutate(NumberInHousehold = case_when(HouseholdSize %in% household_size_one ~ "1",
HouseholdSize %in% household_size_two ~ "2",
HouseholdSize %in% household_size_threeplus ~ "3+",
TRUE ~ "unknown"
)) %>%
### Severely immunosuppressed
mutate(SeverelyImmunosuppressed = case_when(
AdvisedGPImmunosuppressed == "Yes - I am severely immunosuppressed or severely immunocompromised" ~ "Yes",
grepl("No", AdvisedGPImmunosuppressed) ~ "No",
TRUE ~ "unknown"
)) %>%
### Worried by no longer at highest risk
mutate(WorriedButNoLongerHighestRisk = case_when(
(grepl("I still", CurrentApproachToManagingRisk) & (SeverelyImmunosuppressed != "Yes")) ~ "Yes",
TRUE ~ "No"
)) %>%
### Employment
mutate(Employment = case_when(
EmploymentEmployed == "Yes" ~ "Employed",
EmploymentSelfEmployed == "Yes" ~ "Self employed",
EmploymentEducation == "Yes" ~ "Education",
EmploymentRetired == "Yes" ~ "Retired",
EmploymentLookingAfterHomeOrFamily == "Yes" ~ "Looking after home or family",
EmploymentNotWorkingDisabilityOrCondition == "Yes" ~ "Not working due to disability or condition",
EmploymentOther == "Yes" ~ "Other",
EmploymentUnemployed == "Yes" ~ "Unemployed",
TRUE ~ "unknown"
))
## Write new survey
openxlsx::write.xlsx(cs, "survey_with_new_vars.xlsx")