Skip to contents

Create a codebook from one or more survey data files.

Usage

create_codebook(metadata = NULL, survey = NULL)

codebook_waves_create(waves)

codebook_surveys_create(survey_list)

Arguments

metadata

A metadata table created by metadata_create. Defaults to NULL.

survey

A survey data frame, defaults to NULL. If the survey is given as parameter, the metadata will be set to the metadata of this particular survey by metadata_create.

waves

A list of surveys.

survey_list

A list containing surveys of class survey.

Value

A codebook for the survey as a data frame, including the metadata, and all found SPSS-type valid or missing labels.

Details

For a list of survey waves, use codebook_waves_create. The returned codebook contains only labelled variables, i.e., numeric and character types are not included, because they do not require coding.

See also

Examples

create_codebook (
 survey = read_rds (
          system.file("examples", "ZA7576.rds",
                      package = "retroharmonize")
          )
)
#> # A tibble: 535 × 12
#>    entry id     filename   var_name_orig var_label_orig    val_code_orig
#>    <int> <chr>  <chr>      <chr>         <chr>             <chr>        
#>  1     8 ZA7576 ZA7576.rds p1            date_of_interview 1            
#>  2     8 ZA7576 ZA7576.rds p1            date_of_interview 10           
#>  3     8 ZA7576 ZA7576.rds p1            date_of_interview 11           
#>  4     8 ZA7576 ZA7576.rds p1            date_of_interview 12           
#>  5     8 ZA7576 ZA7576.rds p1            date_of_interview 13           
#>  6     8 ZA7576 ZA7576.rds p1            date_of_interview 14           
#>  7     8 ZA7576 ZA7576.rds p1            date_of_interview 15           
#>  8     8 ZA7576 ZA7576.rds p1            date_of_interview 16           
#>  9     8 ZA7576 ZA7576.rds p1            date_of_interview 17           
#> 10     8 ZA7576 ZA7576.rds p1            date_of_interview 18           
#> # … with 525 more rows, and 6 more variables: val_label_orig <chr>,
#> #   label_range <chr>, na_range <named list>, n_labels <dbl>,
#> #   n_valid_labels <dbl>, n_na_labels <dbl>
# \donttest{
examples_dir <- system.file("examples", package = "retroharmonize")
survey_list <- dir(examples_dir)[grepl("\\.rds", dir(examples_dir))]

example_surveys <- read_surveys(
  file.path( examples_dir, survey_list), 
  save_to_rds = FALSE)     
#> Error in read_surveys(file.path(examples_dir, survey_list), save_to_rds = FALSE): unused argument (save_to_rds = FALSE)

codebook_surveys_create (example_surveys)
#> Error in inherits(survey_list, "list"): object 'example_surveys' not found
# }