This function creates a categorical derived variable (pct_time_der_cat10) that categorizes the derived percent time in Canada variable (pct_time_der).
pct_time_fun_cat(pct_time_der)
derived continuous percent time in Canada.
See pct_time_fun
for documentation on how variable was derived.
value for categorical percent time in Canada using pct_time_der variable.
The percent time in Canada provides an estimated percentage of the time a person's life was spent in Canada.The categorical percent time in Canada divides the continuous value into 10 percent intervals.
pct_time_der_cat10 uses the derived variable pct_time_der. pct_time_der uses various variables that have been transformed by cchsflow (see documentation on pct_time_der). In order to categorize percent time in Canada across CCHS cycles, the variables must be transformed and harmonized.
# Using pct_time_fun_cat() to create categorical percent time values
# between CCHS cycles.
# pct_time_fun_cat() is specified in variable_details.csv along with the CCHS
# variables and cycles included.
# To transform pct_time_der_cat10 across cycles, use rec_with_table() for
# each CCHS cycle.
# Since pct_time_der is a derived variable, you will have to specify the
# variables that are derived from it.
# Then by using merge_rec_data(), you can combine pct_time_der_cat10 across
# cycles.
library(cchsflow)
pct_time_cat2009_2010 <- rec_with_table(
cchs2009_2010_p, c(
"DHHGAGE_cont", "SDCGCBG",
"SDCGRES", "pct_time_der", "pct_time_der_cat10"
)
)
#> No variable_details detected.
#> Loading cchsflow variable_details
#> Using the passed data variable name as database_name
#> NOTE for SDCGCBG: CCHS 2001 does not have don't know (7) or refusal (8)
#> NOTE for SDCGRES: CCHS 2001 missing don't know (7), refusal (8)
head(pct_time_cat2009_2010)
#> DHHGAGE_cont SDCGCBG SDCGRES pct_time_der pct_time_der_cat10
#> 1 13 1 NA(a) 100.00000 10
#> 2 27 2 2 55.55556 6
#> 3 62 1 NA(a) 100.00000 10
#> 4 52 1 NA(a) 100.00000 10
#> 5 67 1 NA(a) 100.00000 10
#> 6 62 1 NA(a) 100.00000 10
pct_time_cat2011_2012 <- rec_with_table(
cchs2011_2012_p, c(
"DHHGAGE_cont", "SDCGCBG",
"SDCGRES", "pct_time_der", "pct_time_der_cat10"
)
)
#> No variable_details detected.
#> Loading cchsflow variable_details
#> Using the passed data variable name as database_name
#> NOTE for SDCGCBG: CCHS 2001 does not have don't know (7) or refusal (8)
#> NOTE for SDCGRES: CCHS 2001 missing don't know (7), refusal (8)
tail(pct_time_cat2011_2012)
#> DHHGAGE_cont SDCGCBG SDCGRES pct_time_der pct_time_der_cat10
#> 195 72.0 2 2 20.83333 3
#> 196 22.0 1 NA(a) 100.00000 10
#> 197 18.5 1 NA(a) 100.00000 10
#> 198 42.0 2 2 35.71429 4
#> 199 62.0 1 NA(a) 100.00000 10
#> 200 52.0 1 NA(a) 100.00000 10
combined_pct_time_cat <- merge_rec_data(pct_time_cat2009_2010,
pct_time_cat2011_2012)
head(combined_pct_time_cat)
#> DHHGAGE_cont SDCGCBG SDCGRES pct_time_der pct_time_der_cat10
#> 1 13 1 NA(a) 100.00000 10
#> 2 27 2 2 55.55556 6
#> 3 62 1 NA(a) 100.00000 10
#> 4 52 1 NA(a) 100.00000 10
#> 5 67 1 NA(a) 100.00000 10
#> 6 62 1 NA(a) 100.00000 10
tail(combined_pct_time_cat)
#> DHHGAGE_cont SDCGCBG SDCGRES pct_time_der pct_time_der_cat10
#> 395 72.0 2 2 20.83333 3
#> 396 22.0 1 NA(a) 100.00000 10
#> 397 18.5 1 NA(a) 100.00000 10
#> 398 42.0 2 2 35.71429 4
#> 399 62.0 1 NA(a) 100.00000 10
#> 400 52.0 1 NA(a) 100.00000 10