# NOT RUN {
# Using the diet_score_fun_cat function to categorize the derived diet
# variable across CCHS cycles.
# diet_score_fun_cat() is specified in the variable_details.csv.
# To create a harmonized diet_score_cat3 variable across CCHS cycles, use
# rec_with_table() for each CCHS cycle.
# Since diet_score is also a derived variable, you will have to specify
# the variables that are derived from it.
# Using merge_rec_data(), you can combine diet_score_cat3 across cycles.
library(cchsflow)
diet_score_cat2009_2010 <- rec_with_table(
cchs2009_2010_p, c(
"FVCDFRU", "FVCDSAL", "FVCDPOT", "FVCDCAR", "FVCDVEG", "FVCDJUI",
"DHH_SEX", "diet_score", "diet_score_cat3"
)
)
head(diet_score_cat2009_2010)
diet_score_cat2011_2012 <- rec_with_table(
cchs2011_2012_p,c(
"FVCDFRU", "FVCDSAL", "FVCDPOT", "FVCDCAR", "FVCDVEG", "FVCDJUI",
"DHH_SEX", "diet_score", "diet_score_cat3"
)
)
tail(diet_score_cat2011_2012)
combined_diet_score_cat <- suppressWarnings(merge_rec_data(
diet_score_cat2009_2010, diet_score_cat2011_2012))
head(combined_diet_score_cat)
tail(combined_diet_score_cat)
# }
Run the code above in your browser using DataLab