# Codebook example with SPSS dataset

#### Ruben Arslan

#### 2024-12-23

    knit_by_pkgdown <- !is.null(knitr::opts_chunk$get("fig.retina"))
    ggplot2::theme_set(ggplot2::theme_bw())
    knitr::opts_chunk$set(warning = TRUE, message = TRUE, error = FALSE, echo = TRUE)
    library(dplyr)
    library(codebook)

In this vignette, you can see how to use the metadata that is often already stored in SPSS and Stata files. It’s easy. All we need is the `rio::import` function. For files with the right file extension, we can automatically pick the right way to import the data. Here, we’re downloading straight from the Open Science Framework, so we have to specify the file extension.

We select a subset of variables, just to keep it short. The data were shared by Emanuel Jauk in a project called How alluring are dark personalities? The Dark Triad and attractiveness in speed dating.

Often, files imported from SPSS or Stata to R will not have their missings coded properly. Here, that is not the case, but if you find yourself with such a dataset, the `detect_missing` function makes it easy to recognise common ways to specify missing data (e.g. negative values, labelled values, 99/999).

    darktriad <- rio::import("https://osf.io/j4fcb/download", format = "sav")
    if (!knit_by_pkgdown) {
      darktriad <- darktriad %>%
      select(DG, sex, relStat, education, NPI_avg)
    }

    metadata(darktriad)$name <- "How alluring are dark personalities? The Dark Triad and attractiveness in speed dating"
    metadata(darktriad)$description <- paste0("The data to this speed dating study comes in two different formats: Personwise (one record for each individual) and dyadic (pairwise; one record for each date). The respective SPSS files are named \"DarkTriadDate_person.sav\" and \"DarkTriadDate_dyad.sav\".

    ### Download link
    [Open Science Framework](https://osf.io/j4fcb/download)

    ### Personwise datafile
    The personwise datafile contains individual differences variables and perceiver and target effects according to the social relations model. These are centered marginal means that were calculated according to the formulae provided by Kenny, Kashy, and Cook (2006). These effects are not (!) based on multilevel analyses.

    ### Preprocessing
    All rating variables (i.e., actual choice, friendship, short-term relationship etc.) were corrected for prior acquaintance, which means that dates wih prior acquaintance were excluded (set to missing) on a dyadic basis.

    Variables are labeled in SPSS.

    ### A list of important abbreviations, prefixes and suffixes:

    * _acq = acquaintance (i.e., variables with this suffix are controlled for prior * acquaintance)
    * avg = average
    * _rat = rating variable
    * _z = z-standardized score
    * BC = booty call
    * DG = dating group (three groups in this study)
    * FIPI = five item personality inventory
    * FS = friendship
    * FWB = friends-with-benefits
    * Int = Intelligence
    * Like = Likeability
    * LTR = long-term relationship
    * MACHIV = mach-iv machiavellianism questionnaire
    * N, E, O, A, C = Big5
    * NPI = narcissistic personality inventory
    * ONS = one night stand
    * P = perceiver
    * PA = physical attractiveness
    * PercEff = perceiver effect
    * SD = speed dating
    * SRM = social relations model
    * SRP = self-report psychopathy scale
    * STR = short-term relationship
    * T = target
    * TargEff = target effect

    ")
    metadata(darktriad)$identifier <- "https://osf.io/jvk3u/"
    metadata(darktriad)$datePublished <- "2015-10-07"
    metadata(darktriad)$creator <- list(
          "@type" = "Person",
          givenName = "Emanuel", familyName = "Jauk",
          email = "emanuel.jauk@uni‐graz.at",
          affiliation = list("@type" = "Organization",
            name = "Karl‐Franzens‐Universität Graz, Austria"))
    metadata(darktriad)$citation <- "Jauk, E., Neubauer, A. C., Mairunteregger, T., Pemp, S., Sieber, K. P., & Rauthmann, J. F. (2016). How alluring are dark personalities? The Dark Triad and attractiveness in speed dating. European Journal of Personality, 30(2), 125-138."
    metadata(darktriad)$url <- "https://osf.io/j4fcb/"
    metadata(darktriad)$temporalCoverage <- "2015"
    metadata(darktriad)$spatialCoverage <- "Graz, Austria"
    metadata(darktriad)$distribution = list(
      list("@type" = "DataDownload",
           "requiresSubscription" = "https://schema.org/True",
           "encodingFormat" = "https://www.loc.gov/preservation/digital/formats/fdd/fdd000469.shtml",
           contentUrl = "https://osf.io/j4fcb/download")
    )

    # We don't want to look at the code in the codebook.
    knitr::opts_chunk$set(warning = TRUE, message = TRUE, echo = FALSE)

Now, we can immediately generate a codebook.

### Metadata

#### Description

Dataset name: How alluring are dark personalities? The Dark Triad and attractiveness in speed dating

The data to this speed dating study comes in two different formats: Personwise (one record for each individual) and dyadic (pairwise; one record for each date). The respective SPSS files are named “DarkTriadDate_person.sav” and “DarkTriadDate_dyad.sav”.

### Download link

Open Science Framework

### Personwise datafile

The personwise datafile contains individual differences variables and perceiver and target effects according to the social relations model. These are centered marginal means that were calculated according to the formulae provided by Kenny, Kashy, and Cook (2006). These effects are not (!) based on multilevel analyses.

### Preprocessing

All rating variables (i.e., actual choice, friendship, short-term relationship etc.) were corrected for prior acquaintance, which means that dates wih prior acquaintance were excluded (set to missing) on a dyadic basis.

Variables are labeled in SPSS.

### A list of important abbreviations, prefixes and suffixes:

- _acq = acquaintance (i.e., variables with this suffix are controlled for prior * acquaintance)
- avg = average
- _rat = rating variable
- _z = z-standardized score
- BC = booty call
- DG = dating group (three groups in this study)
- FIPI = five item personality inventory
- FS = friendship
- FWB = friends-with-benefits
- Int = Intelligence
- Like = Likeability
- LTR = long-term relationship
- MACHIV = mach-iv machiavellianism questionnaire
- N, E, O, A, C = Big5
- NPI = narcissistic personality inventory
- ONS = one night stand
- P = perceiver
- PA = physical attractiveness
- PercEff = perceiver effect
- SD = speed dating
- SRM = social relations model
- SRP = self-report psychopathy scale
- STR = short-term relationship
- T = target
- TargEff = target effect

Metadata for search engines

- Temporal Coverage: 2015

- Spatial Coverage: Graz, Austria

- Citation: Jauk, E., Neubauer, A. C., Mairunteregger, T., Pemp, S., Sieber, K. P., & Rauthmann, J. F. (2016). How alluring are dark personalities? The Dark Triad and attractiveness in speed dating. European Journal of Personality, 30(2), 125-138.

- URL: https://osf.io/j4fcb/

- Identifier: https://osf.io/jvk3u/

- Date published: 2015-10-07

- Creator:

name | value
--- | ---
@type | Person
givenName | Emanuel
familyName | Jauk
email | emanuel.jauk@uni‐graz.at
affiliation | Organization , Karl‐Franzens‐Universität Graz, Austria

x
DataDownload
x
https://schema.org/True
x
https://www.loc.gov/preservation/digital/formats/fdd/fdd000469.shtml
x
https://osf.io/j4fcb/download
x
DG
sex
relStat
education
NPI_avg

## Variables

### DG

dating group

#### Distribution

Distribution of values for DG

0 missing values.

#### Summary statistics

name | label | data_type | n_missing | complete_rate | min | median | max | mean | sd | hist | format.spss
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
DG | dating group | numeric | 0 | 1 | 1 | 2 | 3 | 2.033333 | 0.7709618 | ▆▁▇▁▆ | F8.0

### sex

sex

#### Distribution

Distribution of values for sex

0 missing values.

#### Summary statistics

name | label | data_type | n_missing | complete_rate | min | median | max | mean | sd | hist | format.spss | display_width
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
sex | sex | numeric | 0 | 1 | 1 | 1 | 2 | 1.488889 | 0.502677 | ▇▁▁▁▇ | F1.0 | 5

#### Value labels

Response choices
name | value
--- | ---
female | 1
male | 2

### relStat

relationship status

#### Distribution

Distribution of values for relStat

1 missing values.

#### Summary statistics

name | label | data_type | n_missing | complete_rate | min | median | max | mean | sd | hist | format.spss | display_width
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
relStat | relationship status | numeric | 1 | 0.9888889 | 1 | 1 | 3 | 1.089888 | 0.3247534 | ▇▁▁▁▁ | F8.0 | 10

#### Value labels

Response choices
name | value
--- | ---
single | 1
in a relationship | 2
living separately / divorced | 3

### education

highest educational attainment

#### Distribution

Distribution of values for education

1 missing values.

#### Summary statistics

name | label | data_type | n_missing | complete_rate | min | median | max | mean | sd | hist | format.spss | display_width
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
education | highest educational attainment | numeric | 1 | 0.9888889 | 4 | 4 | 5 | 4.168539 | 0.3764655 | ▇▁▁▁▂ | F1.0 | 5

#### Value labels

Response choices
name | value
--- | ---
nine years schooling only | 1
professional training | 2
vocational school | 3
university-entrance diploma | 4
academic degree | 5

### NPI_avg

narcissistic personality inventory - average

#### Distribution

Distribution of values for NPI_avg

0 missing values.

#### Summary statistics

name | label | data_type | n_missing | complete_rate | min | median | max | mean | sd | hist | format.spss | display_width
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
NPI_avg | narcissistic personality inventory - average | numeric | 0 | 1 | 1.7 | 2.6 | 3.6 | 2.611944 | 0.3468807 | ▁▅▇▂▁ | F8.2 | 10

## Missingness report

### Codebook table

name | label | data_type | value_labels | n_missing | complete_rate | min | median | max | mean | sd | hist | format.spss | display_width
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
DG | dating group | numeric | NA | 0 | 1.0000000 | 1.0 | 2.0 | 3.0 | 2.033333 | 0.7709618 | ▆▁▇▁▆ | F8.0 | NA
sex | sex | numeric | 1. female, 2. male | 0 | 1.0000000 | 1.0 | 1.0 | 2.0 | 1.488889 | 0.5026770 | ▇▁▁▁▇ | F1.0 | 5
relStat | relationship status | numeric | 1. single, 2. in a relationship, 3. living separately / divorced | 1 | 0.9888889 | 1.0 | 1.0 | 3.0 | 1.089888 | 0.3247534 | ▇▁▁▁▁ | F8.0 | 10
education | highest educational attainment | numeric | 1. nine years schooling only, 2. professional training, 3. vocational school, 4. university-entrance diploma, 5. academic degree | 1 | 0.9888889 | 4.0 | 4.0 | 5.0 | 4.168539 | 0.3764655 | ▇▁▁▁▂ | F1.0 | 5
NPI_avg | narcissistic personality inventory - average | numeric | NA | 0 | 1.0000000 | 1.7 | 2.6 | 3.6 | 2.611944 | 0.3468807 | ▁▅▇▂▁ | F8.2 | 10