Skip to content

Commit 43b7d25

Browse files
authored
Merge pull request #1278 from cmu-delphi/update-codebook-wave-12
Update qsf tools to work with experimental wave 12
2 parents 20eee56 + 6071a9d commit 43b7d25

File tree

5 files changed

+36
-11
lines changed

5 files changed

+36
-11
lines changed

facebook/qsf-tools/generate-codebook.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ process_qsf <- function(path_to_qsf,
326326

327327
if (any(is.na(qdf$description))) {
328328
nonlabelled_items <- qdf$variable[is.na(qdf$description)]
329-
stop(sprintf("items %s do not have a short name assigned",
329+
stop(sprintf("items %s do not have a description provided",
330330
paste(nonlabelled_items, collapse=", "))
331331
)
332332
}
@@ -396,7 +396,14 @@ add_static_fields <- function(codebook,
396396
path_to_static_fields="./static/static_microdata_fields.csv") {
397397
static_fields <- get_static_fields(wave, path_to_static_fields)
398398

399-
return(bind_rows(codebook, static_fields))
399+
codebook <- bind_rows(codebook, static_fields) %>%
400+
filter(!(variable == "module" & wave < 11), # module field is only available for wave >= 11
401+
!(variable %in% c("wave", "UserLanguage", "fips") & wave < 4), # wave, UserLangauge, and fips fields are only available for wave >= 4
402+
!(variable == "w12_treatment" & wave == 12.5), # experimental arm field is only available for wave == 12.5
403+
variable != "Random_Number"
404+
)
405+
406+
return(codebook)
400407
}
401408

402409
#' Load dataframe of non-Qualtrics data fields
@@ -417,8 +424,7 @@ get_static_fields <- function(wave,
417424
response_option_randomization = col_character()
418425
)) %>%
419426
mutate(wave = wave) %>%
420-
select(wave, everything()) %>%
421-
filter(!(variable == "module" & wave < 11))
427+
select(wave, everything())
422428

423429
return(static_fields)
424430
}

facebook/qsf-tools/qsf-utils.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,21 @@ get_block_item_map <- function(qsf) {
4646

4747

4848
#' Get wave number from qsf filename
49+
#'
50+
#' Wave number as provided in the qsf name should be an integer or a float with
51+
#' one decimal place.
4952
#'
5053
#' @param path_to_qsf
5154
#'
52-
#' @return integer wave number
55+
#' @return (mostly) integer wave number
5356
get_wave <- function(path_to_qsf) {
54-
qsf_name_pattern <- "(.*Wave_)([0-9]*)([.]qsf)$"
57+
qsf_name_pattern <- "(.*Wave_)([0-9]*([.][0-9])?)([.]qsf)$"
5558
if (!grepl(qsf_name_pattern, path_to_qsf)) {
5659
stop("qsf filename should be of the format 'Survey_of_COVID-Like_Illness_-_Wave_XX.qsf'")
5760
}
5861

59-
wave <- as.integer(sub(
60-
"(.*Wave_)([0-9]*)([.]qsf)$",
61-
"\\2",
62-
path_to_qsf)
62+
wave <- as.numeric(
63+
sub(qsf_name_pattern, "\\2", path_to_qsf)
6364
)
6465

6566
return(wave)

facebook/qsf-tools/static/item_replacement_map.csv

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ V11a,V11
3535
V12a,V12
3636
C7a,C7
3737
B10c,B10a
38+
V15c,V15a
39+
V1alt,V1
40+
B13a,B13
41+
P1,E1
42+
P2,E1
43+
P3,E4
44+
P5,E2
45+
P6,E3

facebook/qsf-tools/static/item_shortquestion_map.csv

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,13 @@ V12a,"tried get vaccine"
126126
V15a,"vaccine access barriers vaccinated"
127127
V15b,"vaccine access barriers unvaccinated"
128128
V16,"when try vaccinated"
129-
V3a,"vaccine accepting"
129+
V3a,"vaccine accepting"
130+
V15c,"vaccine access barriers vaccinated"
131+
V1alt,"know anyone vaccinated"
132+
B13a,"COVID ever"
133+
P1,"have children <18"
134+
P2,"oldest child age"
135+
P3,"vaccinate oldest child"
136+
P4,"oldest child school type"
137+
P5,"oldest child school remote type"
138+
P6,"oldest child school safety measures"

facebook/qsf-tools/static/static_microdata_fields.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ UserLanguage,NA,"survey language",NA,NA,NA,NA
66
fips,NA,"county FIPS code",NA,NA,NA,NA
77
weight,NA,"Facebook respondent weight",NA,NA,NA,NA
88
module,NA,"question set respondent was assigned to",NA,NA,NA,NA
9+
w12_treatment,NA,"experimental treatment respondent was assigned to",NA,NA,NA,NA

0 commit comments

Comments
 (0)