Learning how to create a data codebook

Load Packages

Import and Export SPSS, STATA, and SAS files

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

A collection of packages that makes it easy to tidy, clean, and work with data.

if(!require(tidyverse)){
  install.packages("tidyverse", dependencies = TRUE)
  library(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.2     ✔ tibble    3.2.1
✔ lubridate 1.9.2     ✔ tidyr     1.3.0
✔ purrr     1.0.1     
── 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

A collection of tools to quickly and neatly summarize the data.

if(!require(summarytools)){
  install.packages("summarytools", dependencies = TRUE)
  library(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 <- read_sav ("Harry Potter Data.sav")

Selecting Key Variables

(dataset %>%
  select(CoinFlip, FFM_44, Potter28) -> newVariable)
# A tibble: 122 × 3
   CoinFlip  FFM_44                         Potter28    
   <dbl+lbl> <dbl+lbl>                      <dbl+lbl>   
 1 1 [Heads] 2 [Disagree a little]          2 [Imitated]
 2 2 [Tails] 4 [Agree a little]             5 [Liked]   
 3 1 [Heads] 5 [Agree Strongly]             5 [Liked]   
 4 2 [Tails] 5 [Agree Strongly]             3 [Trusted] 
 5 1 [Heads] 5 [Agree Strongly]             3 [Trusted] 
 6 2 [Tails] 2 [Disagree a little]          3 [Trusted] 
 7 2 [Tails] 3 [Neither agree nor diasgree] 3 [Trusted] 
 8 1 [Heads] 2 [Disagree a little]          3 [Trusted] 
 9 1 [Heads] 4 [Agree a little]             3 [Trusted] 
10 1 [Heads] 2 [Disagree a little]          3 [Trusted] 
# ℹ 112 more rows

Create Codebook

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: 82
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_44 [haven_labelled, vctrs_vctr, double] I see Myself as Someone Who..... - Is sophisticated in art, music, or literature
Mean (sd) : 3.3 (1.2)
min ≤ med ≤ max:
1 ≤ 3 ≤ 5
IQR (CV) : 2 (0.4)
1 : 7 ( 7.2% )
2 : 22 ( 22.7% )
3 : 20 ( 20.6% )
4 : 27 ( 27.8% )
5 : 21 ( 21.6% )
97 (79.5%) 25 (20.5%)
3 Potter28 [haven_labelled, vctrs_vctr, double] Which would you rather be:
Mean (sd) : 3.3 (1)
min ≤ med ≤ max:
1 ≤ 3 ≤ 6
IQR (CV) : 0 (0.3)
1 : 5 ( 5.0% )
2 : 3 ( 3.0% )
3 : 69 ( 68.3% )
4 : 9 ( 8.9% )
5 : 10 ( 9.9% )
6 : 5 ( 5.0% )
101 (82.8%) 21 (17.2%)

Generated by summarytools 1.0.1 (R version 4.3.0)
2023-07-09