This function creates a derived variable (time_quit_smoking_der) that calculates the approximate time a former smoker has quit smoking based on various CCHS smoking variables. This variable is for CCHS respondents in CCHS surveys 2003-2014.
time_quit_smoking_fun(SMK_09A_B, SMKG09C)
value for time since quit smoking in time_quit_smoking_der.
# Using time_quit_smoking_fun() to create pack-years values across CCHS
# cycles.
# time_quit_smoking_fun() is specified in variable_details.csv along with the
# CCHS variables and cycles included.
# To transform time_quit_smoking across cycles, use rec_with_table() for each
# CCHS cycle and specify time_quit_smoking, along with each smoking variable.
# Then by using merge_rec_data(), you can combine time_quit_smoking across
# cycles.
library(cchsflow)
time_quit2009_2010 <- rec_with_table(
cchs2009_2010_p, c(
"SMK_09A_B", "SMKG09C", "time_quit_smoking"
)
)
#> No variable_details detected.
#> Loading cchsflow variable_details
#> Using the passed data variable name as database_name
#> NOTE for SMKG09C: Don't know (7) and refusal (8) not included in CCHS 2015-2016 and CCHS 2017-2018
head(time_quit2009_2010)
#> SMK_09A_B SMKG09C time_quit_smoking
#> 1 NA(a) NA(a) NA
#> 2 NA(a) NA(a) NA
#> 3 NA(a) NA(a) NA
#> 4 4 2 8
#> 5 4 3 12
#> 6 4 3 12
time_quit2011_2012 <- rec_with_table(
cchs2011_2012_p, c(
"SMK_09A_B", "SMKG09C", "time_quit_smoking"
)
)
#> No variable_details detected.
#> Loading cchsflow variable_details
#> Using the passed data variable name as database_name
#> NOTE for SMKG09C: Don't know (7) and refusal (8) not included in CCHS 2015-2016 and CCHS 2017-2018
tail(time_quit2011_2012)
#> SMK_09A_B SMKG09C time_quit_smoking
#> 195 4 3 12
#> 196 NA(a) NA(a) NA
#> 197 NA(a) NA(a) NA
#> 198 4 2 8
#> 199 NA(a) NA(a) NA
#> 200 NA(a) NA(a) NA
combined_time_quit <- suppressWarnings(merge_rec_data(time_quit2009_2010,
time_quit2011_2012))
head(combined_time_quit)
#> SMK_09A_B SMKG09C time_quit_smoking
#> 1 NA(a) NA(a) NA
#> 2 NA(a) NA(a) NA
#> 3 NA(a) NA(a) NA
#> 4 4 2 8
#> 5 4 3 12
#> 6 4 3 12
tail(combined_time_quit)
#> SMK_09A_B SMKG09C time_quit_smoking
#> 395 4 3 12
#> 396 NA(a) NA(a) NA
#> 397 NA(a) NA(a) NA
#> 398 4 2 8
#> 399 NA(a) NA(a) NA
#> 400 NA(a) NA(a) NA