Learning How to Create a Data Codebook

Load Packages

if (!require(haven)){
  install.packages("haven", dependencies = TRUE)
  require(haven)
}
Loading required package: haven
if (!require(tidyverse)){
  install.packages("tidyverse", dependencies = TRUE)
  require(tidyverse)
}
Loading required package: tidyverse
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.2     ✔ readr     2.1.4
✔ forcats   1.0.0     ✔ stringr   1.5.0
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.2     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
if (!require(summarytools)){
  install.packages("summarytools", dependencies = TRUE)
  require(summarytools)
}
Loading required package: summarytools
Warning in fun(libname, pkgname): couldn't connect to display ":0"
system might not have X11 capabilities; in case of errors when using dfSummary(), set st_options(use.x11 = FALSE)

Attaching package: 'summarytools'
The following object is masked from 'package:tibble':

    view

Import Data

SPSS

dataset.spss <- read_sav("Harry Potter Data.sav")

Codebook

#First select the variables you'd like to summarize
dataset.spss %>%
  select(CoinFlip, FFM_24, Potter24) -> newVariable
#Then print them with this command
print(dfSummary(newVariable, graph.magnif = .75), method = 'render')
Warning in png(png_loc <- tempfile(fileext = ".png"), width = 150 *
graph.magnif, : unable to open connection to X11 display ''

Warning in png(png_loc <- tempfile(fileext = ".png"), width = 150 *
graph.magnif, : unable to open connection to X11 display ''

Warning in png(png_loc <- tempfile(fileext = ".png"), width = 150 *
graph.magnif, : unable to open connection to X11 display ''

Data Frame Summary

newVariable

Dimensions: 122 x 3
Duplicates: 78
No Variable Label Stats / Values Freqs (% of Valid) Graph Valid Missing
1 CoinFlip [haven_labelled, vctrs_vctr, double] Flip a coin. Is it heads or tails?
Min : 1
Mean : 1.3
Max : 2
1 : 83 ( 70.3% )
2 : 35 ( 29.7% )
118 (96.7%) 4 (3.3%)
2 FFM_24 [haven_labelled, vctrs_vctr, double] I see Myself as Someone Who..... - Is emotionally stable, not easily upset
Mean (sd) : 3.2 (1.2)
min ≤ med ≤ max:
1 ≤ 3 ≤ 5
IQR (CV) : 2 (0.4)
1 : 8 ( 8.2% )
2 : 21 ( 21.6% )
3 : 20 ( 20.6% )
4 : 35 ( 36.1% )
5 : 13 ( 13.4% )
97 (79.5%) 25 (20.5%)
3 Potter24 [haven_labelled, vctrs_vctr, double] Late at night, walking alone down the street, you hear a peculiar cry that you believe to have a magical source. Do you:
Mean (sd) : 2.2 (1.2)
min ≤ med ≤ max:
1 ≤ 2 ≤ 4
IQR (CV) : 2 (0.6)
1 : 42 ( 41.2% )
2 : 22 ( 21.6% )
3 : 13 ( 12.7% )
4 : 25 ( 24.5% )
102 (83.6%) 20 (16.4%)

Generated by summarytools 1.0.1 (R version 4.3.2)
2024-02-14

Bonus Points