Learning how to create a data codebook

Load Packages

haven

if (!require(haven)){
  install.packages("haven", dependencies = TRUE)
  require(haven)
}
Loading required package: haven

tidyverse

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.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.4.4     ✔ tibble    3.2.1
✔ lubridate 1.9.3     ✔ tidyr     1.3.1
✔ 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

summarytools

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

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

Codebook

dataset.spss %>%
  select(CoinFlip, FFM_10, Potter10) -> newVariable
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: 92
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_10 [haven_labelled, vctrs_vctr, double] I see Myself as Someone Who..... - Is curious about many different things
Mean (sd) : 4.2 (0.9)
min ≤ med ≤ max:
1 ≤ 4 ≤ 5
IQR (CV) : 1 (0.2)
1 : 1 ( 1.0% )
2 : 5 ( 5.1% )
3 : 11 ( 11.2% )
4 : 40 ( 40.8% )
5 : 41 ( 41.8% )
98 (80.3%) 24 (19.7%)
3 Potter10 [haven_labelled, vctrs_vctr, double] One of your housemates has cheated in a Hogwarts exam by using a Self-Spelling Quill. Now he has come top of the class in Charms, beating you into second place. Professor Flitwick is suspicious of what happened. He draws you to one side after his lesson and asks you whether or not your classmate used a forbidden quill. What do you do?
Mean (sd) : 2.3 (0.8)
min ≤ med ≤ max:
1 ≤ 2 ≤ 4
IQR (CV) : 1 (0.3)
1 : 14 ( 13.9% )
2 : 46 ( 45.5% )
3 : 34 ( 33.7% )
4 : 7 ( 6.9% )
101 (82.8%) 21 (17.2%)

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