Skip to content

Commit 9eb588b

Browse files
authored
Merge pull request #1109 from cmu-delphi/fb-package-codebook-feedback
Improve on initial version of survey codebook and incorporate feedback
2 parents 22dc189 + 69fcb6a commit 9eb588b

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

facebook/qsf-tools/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ questions. These mapping files are created manually and need to be updated for
2020
every new survey wave.
2121

2222
* `item_replacement_map.csv`: Lists in-survey name of an `new_item` and the
23-
in-survey name of the `old_item` it replaces. `new_item` should be the name
24-
of a single item and be unique, but the `old_item` column has no formatting
25-
requirements. It can hold a list of items, if the corresponding new survey
26-
item is replacing multiple old questions, and a given item name can appear
27-
in multiple rows of the `old_item` field.
23+
in-survey name(s) of the `old_item`(s) it replaces. `new_item` should be the
24+
name of a single item and be unique; the `old_item` column should be a
25+
string. However, `old_item` has no other formatting requirements. For
26+
example, it can list several item names (e.g. "A1, A2"), if the
27+
corresponding new survey item is replacing multiple old questions. A given
28+
item name can also appear in multiple rows of the `old_item` field.
2829
* `item_shortquestion_map.csv`: Lists in-survey name of an `item` and a short
2930
description of the contents of the question. `item` should be the name of a
3031
single item and be unique, but the `description` column has no formatting
@@ -83,4 +84,4 @@ which can contain any subset of the following fields:
8384
The meaning of "Answers" and "Choices" differs for matrix vs non-matrix
8485
items. "Choices" list the vertical components -- subquestions for matrix
8586
items and answer choices for non-matrix items. "Answers" list the answer
86-
choices for matrix items and are missing for non-matrix items.
87+
choices for matrix items and are missing for non-matrix items.

facebook/qsf-tools/generate-codebook.R

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
suppressPackageStartupMessages({
1010
library(tidyverse)
1111
library(jsonlite)
12+
library(rjson)
1213
library(stringr)
1314
library(gsubfn)
1415
source("qsf-utils.R")
@@ -265,7 +266,24 @@ process_qsf <- function(path_to_qsf,
265266
NA_character_),
266267
wave = get_wave(path_to_qsf)
267268
) %>%
268-
select(wave, variable, replaces, description, question, matrix_subquestion, type, display_logic, response_option_randomization, group_of_respondents_item_was_shown_to)
269+
select(wave,
270+
variable,
271+
replaces,
272+
description,
273+
question,
274+
matrix_subquestion,
275+
choices,
276+
type,
277+
display_logic,
278+
response_option_randomization,
279+
group_of_respondents_item_was_shown_to)
280+
281+
# Format choices as json string
282+
qdf$choices <- map(qdf$choices, function(x) {
283+
if (is_empty(x)) { NA }
284+
else { toJSON(x) }
285+
}) %>%
286+
unlist()
269287

270288
# add free text response options
271289
other_text_items <- qdf %>%
@@ -276,6 +294,7 @@ process_qsf <- function(path_to_qsf,
276294
description = paste0(description, " other text")
277295
)
278296
qdf <- rbind(qdf, other_text_items)
297+
qdf$choices[qdf$type == "Text"] <- NA
279298

280299
# Quality checks
281300
stopifnot(length(qdf$variable) == length(unique(qdf$variable)))
@@ -388,7 +407,7 @@ get_static_fields <- function(wave,
388407
add_qsf_to_codebook <- function(path_to_qsf, path_to_codebook) {
389408
qdf <- process_qsf(path_to_qsf)
390409
codebook <- add_qdf_to_codebook(qdf, path_to_codebook)
391-
write_csv(codebook, path_to_codebook)
410+
write_excel_csv(codebook, path_to_codebook)
392411
}
393412

394413

facebook/qsf-tools/static/item_replacement_map.csv

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ C15,Q36
2222
C13b,C13
2323
C13c,C13a
2424
C14a,C14
25+
C17,C2
2526
C17a,C17
2627
V2a,V2
2728
V3a,V3
@@ -32,4 +33,5 @@ V4a_4,V4_4
3233
V4a_5,V4_5
3334
V11a,V11
3435
V12a,V12
35-
C7a,C7
36+
C7a,C7
37+
B10c,B10a

facebook/qsf-tools/static/static_microdata_fields.csv

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
variable,replaces,description,question,matrix_subquestion,type,response_option_randomization
2-
StartDatetime,NA,"survey start timestamp",NA,NA,NA,NA
3-
EndDatetime,NA,"survey end timestamp",NA,NA,NA,NA
2+
StartDatetime,NA,"survey start timestamp in Pacific time (UTC-7)",NA,NA,NA,NA
3+
EndDatetime,NA,"survey end timestamp in Pacific time (UTC-7)",NA,NA,NA,NA
44
wave,NA,"survey version",NA,NA,NA,NA
55
UserLanguage,NA,"survey language",NA,NA,NA,NA
66
fips,NA,"county FIPS code",NA,NA,NA,NA

0 commit comments

Comments
 (0)