This function creates a derived smoking variable (smoke_simple) with four categories:
non-smoker (never smoked)
current smoker (daily and occasional?)
former daily smoker quit =<5 years or former occasional smoker
former daily smoker quit >5 years
smoke_simple_fun(SMKDSTY_cat5, time_quit_smoking)
derived variable that classifies an individual's smoking status. This variable captures cycles 2001-2018.
derived variable that calculates the approximate
time a former smoker has quit smoking.
See time_quit_smoking_fun
for documentation on how variable
was derived.
# Using the 'smoke_simple_fun' function to create the derived smoking
# variable across CCHS cycles.
# smoke_simple_fun() is specified in the variable_details.csv
# To create a harmonized smoke_simple variable across CCHS cycles, use
# rec_with_table() for each CCHS cycle and specify smoke_simple_fun and
# the required base variables. Since time_quit_smoking_der is also a derived
# variable, you will have to specify the variables that are derived from it.
# Using merge_rec_data(), you can combine smoke_simple across cycles.
library(cchsflow)
smoke_simple2009_2010 <- rec_with_table(
cchs2009_2010_p, c(
"SMKDSTY", "SMK_09A_B", "SMKG09C", "time_quit_smoking",
"smoke_simple"
)
)
#> No variable_details detected.
#> Loading cchsflow variable_details
#> Using the passed data variable name as database_name
#> Warning: SMKDSTY is missing from variable details therefore cannot be recoded
#> NOTE for SMKG09C: Don't know (7) and refusal (8) not included in CCHS 2015-2016 and CCHS 2017-2018
#> Warning: smoke_simple could not be derived because SMKDSTY_cat5 was never specified nor is it a function variable,
#> therefore it was not recoded
#> smoke_simple could not be derived because time_quit_smoking was never specified nor is it a function variable,
#> therefore it was not recoded
head(smoke_simple2009_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
smoke_simple2011_2012 <- rec_with_table(
cchs2011_2012_p,c(
"SMKDSTY", "SMK_09A_B", "SMKG09C", "time_quit_smoking",
"smoke_simple"
)
)
#> No variable_details detected.
#> Loading cchsflow variable_details
#> Using the passed data variable name as database_name
#> Warning: SMKDSTY is missing from variable details therefore cannot be recoded
#> NOTE for SMKG09C: Don't know (7) and refusal (8) not included in CCHS 2015-2016 and CCHS 2017-2018
#> Warning: smoke_simple could not be derived because SMKDSTY_cat5 was never specified nor is it a function variable,
#> therefore it was not recoded
#> smoke_simple could not be derived because time_quit_smoking was never specified nor is it a function variable,
#> therefore it was not recoded
tail(smoke_simple2011_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_smoke_simple <-
suppressWarnings(merge_rec_data(smoke_simple2009_2010,smoke_simple2011_2012))
head(combined_smoke_simple)
#> 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_smoke_simple)
#> 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