# NOT RUN {
# Using binge_drinker_fun() to create binge_drinker values across CCHS cycles
# binge_drinker_fun() is specified in variable_details.csv along with the
# CCHS variables and cycles included.
# To transform binge_drinker, use rec_with_table() for each CCHS cycle
# and specify binge_drinker, along with the various alcohol and sex
# variables. Then by using bind_rows() you can combine binge_drinker
# across cycles.
library(cchsflow)
binge2001 <- rec_with_table(
cchs2001_p, c(
"ALW_1", "DHH_SEX", "ALW_2A1", "ALW_2A2", "ALW_2A3", "ALW_2A4",
"ALW_2A5", "ALW_2A6", "ALW_2A7", "binge_drinker"
)
)
head(binge2001)
binge2009_2010 <- rec_with_table(
cchs2009_2010_p, c(
"ALW_1", "DHH_SEX", "ALW_2A1", "ALW_2A2", "ALW_2A3", "ALW_2A4",
"ALW_2A5", "ALW_2A6", "ALW_2A7", "binge_drinker"
)
)
tail(binge2009_2010)
combined_binge <- bind_rows(binge2001, binge2009_2010)
head(combined_binge)
tail(combined_binge)
# Using binge_drinker_fun() to generate binge_drinker with user-inputted
# values.
#
# Let's say you are a male, and you had drinks in the last week. Let's say
# you had 3 drinks on Sunday, 1 drink on
# Monday, 6 drinks on Tuesday, 0 drinks on Wednesday, 3 drinks on Thurday,
# 8 drinks on Friday, and 2 drinks on Saturday. Using binge_drinker_fun(),
# we can check if you would be classified as a drinker.
binge <- binge_drinker_fun(DHH_SEX = 1, ALW_1 = 1, ALW_2A1 = 3, ALW_2A2 = 1,
ALW_2A3 = 6, ALW_2A4 = 0, ALW_2A5 = 3,
ALW_2A6 = 8, ALW_2A7 = 2)
print(binge)
# }
Run the code above in your browser using DataLab