knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
The purpose of resurrectionr is recode_religion()
which recodes a set of religious identification variables from the US General Social Survey, in a way that is analytically useful and easy to implement in data processing.
Bigger sociological and political problems in recoding of religious identification are elaborated and resolved with a recoding schema in the paper by Darren E. Sherkat and Derek Lehman,[^1] based on classification[^2] from 2001. This package provides solutions for main technical issues with recoding of religious identification from GSS in R, using said schema.
relig
), 30 (denom
), and 201 (other
). This package provides universal function recode_religion()
that can recode all these varaibles and adds additional benefits in terms of cheking values, providing a recoding key, etc.
# Install development version from GitHub # install.packages("devtools") # If you don't have it devtools::install_github("mdjeric/resurrectionr")
This is a basic use of function:
library(resurrectionr) gss <- gss14_f gss$religion <- recode_religion(gss$relig, gss$denom, gss$other) summary(gss$religion)
recode_religion()
is a wrapper for basic function that does all the recoding. It confirms the variables are with proper codes, same length, transforms the type, and provides additional information, warning messages, errors, etc.
fct_rec_relig()
, the simple function, uses data frames in the list rdo_cdbk
from which three vectors are formed where index corresponds to punch number, and label is value (of relig
, denom
, and other
).
For each new religious identification, separate vectors (for relig
, denom
, and/or other
identification) are created that contain corresponding punch codes and labels, per paper and SPSS syntax. In addition, logical vectors are created for Sectarian Protestants with valid denomination codes for sorting between 'Sectarian Protestants', 'Christian - no group given', and 'other religions'.
Next, twelve logical vectors, for respondent's belonging to each group, are created by checking against appropriate vectors containing labels. Names are assigned, function prints frequency table, and returns vector that contains new variable.
Function checks that the (1) vectors are of same length, and (2) that their values are valid answers, throwing errors like this:
religion <- recode_religion("PROTESTANT", c(12, 13), "IAP") #> Error: Vectors must be of the same lenght, currently they are: #> Length of `relig`: 1. #> Length of `denom`: 2. #> Length of `other`: 1.
It is also possible to combine punches with labels, and get same results, or print the coding key that was used on specific data.
set.seed(999) # for reproducability short <- sample(1:2358, 50, replace = FALSE) # chose random 50 cases gshrt <- gss[short, ] gshrt$religion <- recode_religion(gshrt$relig, gshrt$denom, gshrt$other, add_missing_levels = TRUE, print_key = TRUE)
It also works well when some (or all) variables contain punches, either as characters or numbers.
gshrt$d_num <- gss14_n$denom[short] gshrt$o_num_char <- as.character(gss14_n$other[short]) gshrt$religion2 <- recode_religion(gshrt$relig, gshrt$d_num, gshrt$o_num_char, add_missing_levels = TRUE, frequencies = FALSE) # We can see that there is no difference FALSE %in% (gshrt$religion2 == gshrt$religion)
Three more things are planned to be included in this package:
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
[^1]: "After The Resurrection: The Field of the Sociology of Religion in the United States"{target="_blank"}
[^2]: Sherkat, Darren E. 2001. "Tracking the restructuring of American religion: Religious affiliation and patterns of religious mobility, 1973–1998." Social Forces 79(4), 1459-1493. doi:10.1353/sof.2001.0052
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.