This example uses the National Study of Long-Term Care Providers (NSLTCP) Residential Care Community (RCC) Services User (SU) 2018 Public Use File (PUF) to replicate the estimates from a report called Residential Care Community Resident Characteristics: United States, 2018. “The survey used a sample of residential care community residents, obtained from a frame that was constructed from lists of licensed residential care communities acquired from the state licensing agencies in each of the 50 states and the District of Columbia.”
The RCC SU 2018 survey comes with the surveytable
package, for use in examples, in an object called
rccsu2018
.
Begin by loading the surveytable
package.
Now, specify the survey that you’d like to analyze.
Survey info {RCC SU 2018 PUF} | ||
Variables | Observations | Design |
---|---|---|
Check the survey name, survey design variables, and the number of observations to verify that it all looks correct.
For this example, we do want to turn on certain NCHS-specific options, such as identifying low-precision estimates. If you do not care about identifying low-precision estimates, you can skip this command. To turn on the NCHS-specific options:
Alternatively, you can combine these two commands into a single command, like so:
Survey info {RCC SU 2018 PUF} | ||
Variables | Observations | Design |
---|---|---|
This figure shows the percentage of residents by sex, race / ethnicity, and age group.
Sex.
Resident’s gender {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards. Nothing to report. |
Race / ethnicity.
Variables beginning with ‘race’ {RCC SU 2018 PUF} | ||
Variable | Class | Long name |
---|---|---|
Resident’s race/ethnicity {RCC SU 2018 PUF} | ||||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL | Flags |
---|---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards: Cx: suppress count (and rate). |
In the published figure, the Hispanic and Other categories have been
merged into a single category called “Another race or ethnicity”. We can
do that using the var_collapse()
function.
Resident’s race/ethnicity {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards. Nothing to report. |
Age group.
Variables beginning with ‘age’ {RCC SU 2018 PUF} | ||
Variable | Class | Long name |
---|---|---|
age2
is a numeric variable. We need to create a
categorical variable based on this numeric variable. This is done using
the var_cut()
function.
var_cut("Age", "age2"
, c(-Inf, 64, 74, 84, Inf)
, c("Under 65", "65-74", "75-84", "85 and over") )
tab("Age")
Age {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards. Nothing to report. |
This figure shows the percentage of residents with Medicaid, overall and by age group.
Used Medicaid to pay for services {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards. Nothing to report. |
As we can see, for some observations, the value of this variable is
unknown (it’s missing or NA
). The above command calculates
percentages based on all observations, including the ones with missing
(NA
) values. However, in the published figure, the
percentages are based on the knowns only. To exclude the
NA
’s from the calculation, use the drop_na
argument:
Used Medicaid to pay for services (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 817. Checked NCHS presentation standards. Nothing to report. |
Note that the table title alerts you to the fact that you are using known values only.
By age group:
Used Medicaid to pay for services (Age = Under 65) (knowns only) {RCC SU 2018 PUF} | ||||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL | Flags |
---|---|---|---|---|---|---|---|---|---|---|
N = 66. Checked NCHS presentation standards: Px: suppress percent. |
Used Medicaid to pay for services (Age = 65-74) (knowns only) {RCC SU 2018 PUF} | ||||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL | Flags |
---|---|---|---|---|---|---|---|---|---|---|
N = 83. Checked NCHS presentation standards: Px: suppress percent. |
Used Medicaid to pay for services (Age = 75-84) (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 196. Checked NCHS presentation standards. Nothing to report. |
Used Medicaid to pay for services (Age = 85 and over) (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 472. Checked NCHS presentation standards. Nothing to report. |
Note that according to the NCHS presentation criteria, some of the percentages should be suppressed.
(Figure 3 is slightly more involved, so we’ll do it next.)
Here’s a table for high blood pressure.
Resident diagnosed with high blood pressure {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards. Nothing to report. |
Once again, unknown values (NA
) are present, while the
figure is based on knowns only. Therefore, we again will use the
drop_na
argument:
tab("hbp", "alz", "depress", "arth", "diabetes", "heartdise", "osteo"
, "copd", "stroke", "cancer"
, drop_na = TRUE)
Resident diagnosed with high blood pressure (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with Alzheimer’s/dementia (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with depression (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with arthritis (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with diabetes (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with heart disease (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with osteoporosis (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with COPD (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with stroke (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
Resident diagnosed with cancer (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 878. Checked NCHS presentation standards. Nothing to report. |
surveytable
provides a number of functions to create
or modify survey variables.
We saw a couple of these above: var_collapse()
and
var_cut()
.
Occasionally, you might need to do advanced variable editing. Here’s how:
Every survey object has an element called
variables
This is a data frame where the survey’s variables are located
variables
data frame
(which is part of the survey object).set_survey()
again. Any time you modify the
variables
data frame, call set_survey()
.We go through these steps to count how many chronic conditions were present.
rccsu2018$variables$num_cc = 0
for (vr in c("hbp", "alz", "depress", "arth", "diabetes", "heartdise", "osteo"
, "copd", "stroke", "cancer")) {
idx = which(rccsu2018$variables[,vr])
rccsu2018$variables$num_cc[idx] = rccsu2018$variables$num_cc[idx] + 1
}
set_survey(rccsu2018, mode = "NCHS")
## * Mode: NCHS.
Survey info {RCC SU 2018 PUF} | ||
Variables | Observations | Design |
---|---|---|
num_cc
is a numeric variable with the number of chronic
conditions. The published figure uses a categorical variable which is
based on this numeric variable. Use var_cut()
, which
converts numeric variables to categorical (factor
)
variables.
var_cut("Number of chronic conditions", "num_cc"
, c(-Inf, 0, 1, 3, 10, Inf)
, c("0", "1", "2-3", "4-10", "??"))
tab("Number of chronic conditions")
Number of chronic conditions {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards. Nothing to report. |
Here’s a table for bathhlp
(help with bathing):
Type of assistance resident needs to bathe {RCC SU 2018 PUF} | ||||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL | Flags |
---|---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards: Cx: suppress count (and rate). |
This variable has multiple levels.
"NEED NO ASSISTANCE"
) = does not need
help"MISSING"
) = unknownWe want to show (resident needing help) as a percentage of knowns only (that is, excluding the unknowns).
To do this, convert the variable to having 2 levels (needs help /
does not need help) plus NA
(for unknown); then use the
drop_na
argument to base percentages on knowns only.
for (vr in c("bathhlp", "walkhlp", "dreshlp", "transhlp", "toilhlp", "eathlp")) {
var_collapse(vr
, "Needs assistance"
, c("NEED HELP OR SUPERVISION FROM ANOTHER PERSON"
, "USE OF AN ASSISTIVE DEVICE"
, "BOTH"))
var_collapse(vr, NA, "MISSING")
}
tab("bathhlp", "walkhlp", "dreshlp", "transhlp", "toilhlp", "eathlp", drop_na = TRUE)
Type of assistance resident needs to bathe (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 882. Checked NCHS presentation standards. Nothing to report. |
Type of assistance resident needs for locomotion (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 875. Checked NCHS presentation standards. Nothing to report. |
Type of assistance resident needs to dress (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 882. Checked NCHS presentation standards. Nothing to report. |
Type of assistance resident needs to transfer in/out of chair (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 883. Checked NCHS presentation standards. Nothing to report. |
Type of assistance resident needs to use bathroom (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 884. Checked NCHS presentation standards. Nothing to report. |
Type of assistance resident needs to eat (knowns only) {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 885. Checked NCHS presentation standards. Nothing to report. |
Now, go through the “advanced variable editing” steps – very similar to Figure 4 – to count how many ADLs were present.
rccsu2018$variables$num_adl = 0
for (vr in c("bathhlp", "walkhlp", "dreshlp", "transhlp", "toilhlp", "eathlp")) {
idx = which(rccsu2018$variables[,vr] %in%
c("NEED HELP OR SUPERVISION FROM ANOTHER PERSON"
, "USE OF AN ASSISTIVE DEVICE"
, "BOTH"))
rccsu2018$variables$num_adl[idx] = rccsu2018$variables$num_adl[idx] + 1
}
set_survey(rccsu2018, mode = "NCHS")
## * Mode: NCHS.
Survey info {RCC SU 2018 PUF} | ||
Variables | Observations | Design |
---|---|---|
For generating the figure, create a categorical variable based on
num_adl
, which is numeric.
var_cut("Number of ADLs", "num_adl"
, c(-Inf, 0, 2, 6, Inf)
, c("0", "1-2", "3-6", "??"))
tab("Number of ADLs")
Number of ADLs {RCC SU 2018 PUF} | |||||||||
Level | n | Number (000) | SE (000) | LL (000) | UL (000) | Percent | SE | LL | UL |
---|---|---|---|---|---|---|---|---|---|
N = 904. Checked NCHS presentation standards. Nothing to report. |