-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodebook.Rmd
65 lines (56 loc) · 1.94 KB
/
codebook.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
---
title: "Codebook"
output:
html_document:
toc: true
toc_depth: 4
toc_float: true
code_folding: 'hide'
self_contained: true
pdf_document:
toc: yes
toc_depth: 4
latex_engine: xelatex
---
Here, we're just setting a few options.
```{r setup}
knitr::opts_chunk$set(
warning = TRUE, # show warnings during codebook generation
message = TRUE, # show messages during codebook generation
error = TRUE, # do not interrupt codebook generation in case of errors,
# usually better for debugging
echo = TRUE # show R code
)
ggplot2::theme_set(ggplot2::theme_bw())
```
Now, we're preparing our data for the codebook.
```{r prepare_codebook}
library(codebook)
codebook_data <- rio::import("final_dataset.txt")
# to import an SPSS file from the same folder uncomment and edit the line below
# codebook_data <- rio::import("mydata.sav")
# for Stata
# codebook_data <- rio::import("mydata.dta")
# for CSV
# codebook_data <- rio::import("mydata.csv")
codebook_data=codebook_data[,2:ncol(codebook_data)]
# omit the following lines, if your missing values are already properly labelled
codebook_data <- detect_missing(codebook_data,
only_labelled = TRUE, # only labelled values are autodetected as
# missing
negative_values_are_missing = FALSE, # negative values are missing values
ninety_nine_problems = TRUE, # 99/999 are missing values, if they
# are more than 5 MAD from the median
)
# If you are not using formr, the codebook package needs to guess which items
# form a scale. The following line finds item aggregates with names like this:
# scale = scale_1 + scale_2R + scale_3R
# identifying these aggregates allows the codebook function to
# automatically compute reliabilities.
# However, it will not reverse items automatically.
codebook_data <- detect_scales(codebook_data)
```
Create codebook
```{r codebook}
codebook(codebook_data)
```