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)
SMKDSTY_cat5 | derived variable that classifies an individual's smoking status. This variable captures cycles 2001-2018. |
---|---|
time_quit_smoking | derived variable that calculates the approximate
time a former smoker has quit smoking.
See |
# 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" ) )#>#>#>#> Warning: SMKDSTY is missing from variable details therefore cannot be recoded#>#> 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#> 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 12smoke_simple2011_2012 <- rec_with_table( cchs2011_2012_p,c( "SMKDSTY", "SMK_09A_B", "SMKG09C", "time_quit_smoking", "smoke_simple" ) )#>#>#>#> Warning: SMKDSTY is missing from variable details therefore cannot be recoded#>#> 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#> 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) NAcombined_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#> 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