Skip to contents

Create a codebook table for a variable or several variables.

Usage

codebook_create(
  df,
  var_labels = TRUE,
  val_labels = TRUE,
  freq = FALSE,
  directory = NULL
)

var_code_table(
  df,
  var_name,
  var_labels = TRUE,
  val_labels = TRUE,
  freq = FALSE
)

codebooks_create(directory, var_labels = TRUE, val_labels = TRUE, freq = FALSE)

Arguments

df

A survey dataset

var_labels

Should the variable labels be included in the codebook? Defaults to TRUE.

val_labels

Should the value labels be included in the codebook? Defaults to TRUE.

freq

Should a label frequency table be included in the codebook? Defaults to FALSE.

directory

For multiple surveys, use codebook_create(directory) with placing the survey files into directory. Defaults to NULL (single data.frame case.)

var_name

A variable name in df

Value

A dataset (data frame) containing the original survey identifier, the variable names, the variable and value labels, and further metadata among the dataset attributes.

Details

Use var_code_table for a single variable and codebook_create for a dataset.
Use codebook_create(df, ...) for a survey dataset (or data.frame)
Use codebook_create(df, directory='my_directory') for multiple surveys in a file directory.

Examples

sample_data <- read_sav_gesis(
file = system.file("extdata", "ZA5933_sample.sav",
                   package = "eurobarometer"))

var_code_table(sample_data, "d7")
#>             survey  ZACAT var_name_orig var_label_orig val_code_orig
#> 1  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             1
#> 2  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             2
#> 3  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             3
#> 4  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             4
#> 5  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             5
#> 6  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             6
#> 7  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             7
#> 8  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             8
#> 9  10.4232/1.13044 ZA5933            d7 MARITAL STATUS             9
#> 10 10.4232/1.13044 ZA5933            d7 MARITAL STATUS            10
#> 11 10.4232/1.13044 ZA5933            d7 MARITAL STATUS            11
#> 12 10.4232/1.13044 ZA5933            d7 MARITAL STATUS            12
#> 13 10.4232/1.13044 ZA5933            d7 MARITAL STATUS            13
#> 14 10.4232/1.13044 ZA5933            d7 MARITAL STATUS            14
#> 15 10.4232/1.13044 ZA5933            d7 MARITAL STATUS            15
#> 16 10.4232/1.13044 ZA5933            d7 MARITAL STATUS            97
#>                                                    val_label_orig
#> 1                           (Re-)Married: living without children
#> 2                       (Re-)Married: w children of this marriage
#> 3                   (Re-)Married: w children of previous marriage
#> 4          (Re-)Married: w children of this and previous marriage
#> 5                       Single living w partner: without children
#> 6               Single living w partner: w children of this union
#> 7           Single living w partner: w children of previous union
#> 8  Single living w partner: w children of this and previous union
#> 9                                 Single: living without children
#> 10                                          Single: with children
#> 11                    Divorced/Separated: living without children
#> 12                       Divorced/Separated: living with children
#> 13                              Widow/er: living without children
#> 14                                 Widow/er: living with children
#> 15                                                 Other (SPONT.)
#> 16                                               Refusal (SPONT.)
codebook_create(sample_data[, c("d25", "d60")], freq=TRUE)
#> Codebook for Eurobarometer 82.4 (November-December 2014) (subset) [10.4232/1.13044] 
#>            survey var_name_orig                        var_label_orig
#> 1 10.4232/1.13044           d25                     TYPE OF COMMUNITY
#> 2 10.4232/1.13044           d25                     TYPE OF COMMUNITY
#> 3 10.4232/1.13044           d25                     TYPE OF COMMUNITY
#> 4 10.4232/1.13044           d25                     TYPE OF COMMUNITY
#> 5 10.4232/1.13044           d60 DIFFICULTIES PAYING BILLS - LAST YEAR
#> 6 10.4232/1.13044           d60 DIFFICULTIES PAYING BILLS - LAST YEAR
#> 7 10.4232/1.13044           d60 DIFFICULTIES PAYING BILLS - LAST YEAR
#> 8 10.4232/1.13044           d60 DIFFICULTIES PAYING BILLS - LAST YEAR
#>   val_code_orig             val_label_orig
#> 1             1      Rural area or village
#> 2             2 Small or middle sized town
#> 3             3                 Large town
#> 4             8                         DK
#> 5             1           Most of the time
#> 6             2          From time to time
#> 7             3         Almost never/never
#> 8             7           Refusal (SPONT.)