Description Usage Arguments Details Value Examples
Function recodes religious identification from Genearl Social Survey,
based on three variables: relig
, denom
, and other
.
It can successfully recode either respondent's, or any other religious
identification which is determened by coresponding three variables.
1 2 3 | recode_religion(relig, denom, other, n_groups = 7,
add_missing_levels = FALSE, frequencies = TRUE, print_key = FALSE,
return_num = FALSE)
|
relig, denom, other |
Numerical, character, or factor, all of same length and with coresponding punches or labels in codebook. |
n_groups |
Number, 7 (default) or 12 of new religious identifications. |
add_missing_levels |
Logical, to include as empty levels religious identifications that may not be present in specific sample, but are part of recoding schema. |
frequencies |
Logical, to print frequency and percent table of
recoded religius identification (default is |
print_key |
Logical, to print the all unique tetrads of recoded variables, i.e. a recoding key. |
return_num |
Logical, to return numerical factor and print codebook. |
recode_religion
uses schema developed by Darren E. Sherkat and
Derek Lehman in "After
The Resurrection: The Field of the Sociology of Religion in the United
States", and is effectievly translation of that SPSS syntax (the bare
bone function for recoding is fct_rec_relig), with
additional functionality.
Namley, it can handle both punches and labels
at the same time (but in different variables), which is important since
punches are not consequtive as indexes. In addition, function checks that
variables are adequate (i.e. that all values are in codebook) and of same
length, and also handles missing values: (1) if supplied through values,
provides detail recoding; (2) if NA
, lumps them together in final
variable but uses them correctly in the recoding. Through passed
arguments, one can:
Return longer version, of 12 religious identifications.
Add identifications from schema that are not present in sample as empty levels.
Suppress printing of the frequencies of newly recoded variable.
Print unique key of the values that were recoded.
Return values as numerical factor, in which case the codebook for new variable will be printed.
If frequencies
is passed as FALSE
, and numerical vector
is not requested as return value, all other information, such as
treatment of missing values, are provided as messages that can be
suppressed.
More details can be found on github.mdjeric.
Vector with recoded religion from relig
, denom
,
and other
. Function does not return NA
, but as
factor levels "Not answered" and "Don't know", or combined
"Not answered/Don't know" when missing values are not
declared as punches or labels in initial variables but passed on as
NA
(function gives message and where NAs
are lcoated).
Default is to have factor with 7 descriptive levels, but function can
also return numerical vector. Default behavior returns only present
values, but can be made to add additional empty levels if TRUE
is passed to add_missing_levels
. Function also prints
frequency table of newly recoded religious identification, which can be
suppressed with frequencies
. If required, it can also return
numerical vector and print the coding for it (not recommended).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | library(resurrectionr)
# When all variables are factor
gss14_f$religion <- recode_religion(gss14_f$relig, gss14_f$denom,
gss14_f$other, frequencies = FALSE)
# Twelve groups
gss14_f$religion <- recode_religion(gss14_f$relig, gss14_f$denom,
gss14_f$other, n_groups = 12)
# When all variables are numeric
gss14_n$religion <- recode_religion(gss14_n$relig, gss14_n$denom,
gss14_n$other,
add_missing_levels = TRUE)
# But also, combining them works
religion <- recode_religion(gss14_f$relig, gss14_n$denom,
as.character(gss14_f$other))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.