Codebook example with SPSS dataset"

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

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("", 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](

### 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 <- ""
metadata(darktriad)$datePublished <- "2015-10-07"
metadata(darktriad)$creator <- list(
      "@type" = "Person",
      givenName = "Emanuel", familyName = "Jauk",
      email = "emanuel.jauk@uni‐", 
      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 <- ""
metadata(darktriad)$temporalCoverage <- "2015" 
metadata(darktriad)$spatialCoverage <- "Graz, Austria" 
metadata(darktriad)$distribution = list(
  list("@type" = "DataDownload",
       "requiresSubscription" = "",
       "encodingFormat" = "",
       contentUrl = "")
# 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.

codebook(darktriad, survey_repetition = "single",
         metadata_table = knit_by_pkgdown, metadata_json = knit_by_pkgdown)

r ifelse(knit_by_pkgdown, '', '### Codebook table')

if (!knit_by_pkgdown) {

Try the codebook package in your browser

Any scripts or data that you put into this service are public.

codebook documentation built on July 1, 2020, 10:28 p.m.