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)
pct_time_der | derived continuous percent time in Canada.
See |
---|
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" ) )#>#>#>#>#>#> 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 10pct_time_cat2011_2012 <- rec_with_table( cchs2011_2012_p, c( "DHHGAGE_cont", "SDCGCBG", "SDCGRES", "pct_time_der", "pct_time_der_cat10" ) )#>#>#>#>#>#> 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 10combined_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#> 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