# Import data
vars_of_interest <- read.csv("variable_coverage.csv")
# Keep variables that have an x in 2019-2023
vars_of_interest <- vars_of_interest[rowSums(vars_of_interest[, 10:14] == "x") > 4, ]
# Save variable column values to a list
vars_of_interest <- as.vector(vars_of_interest$variable)
# Load vars_of_interest from 2019-2023 BRFSS data
brfss_162_2019 <- read.csv("./data/2019_342.csv")[vars_of_interest]
brfss_162_2020 <- read.csv("./data/2020_279.csv")[vars_of_interest]
brfss_162_2021 <- read.csv("./data/2021_303.csv")[vars_of_interest]
brfss_162_2022 <- read.csv("./data/2022_326.csv")[vars_of_interest]
brfss_162_2023 <- read.csv("./data/2023_350.csv")[vars_of_interest]
# Add a year column to each dataframe
brfss_162_2019$year <- 2019
brfss_162_2020$year <- 2020
brfss_162_2021$year <- 2021
brfss_162_2022$year <- 2022
brfss_162_2023$year <- 2023
# Combine the dataframes
brfss_162_2019to2023 <- rbind(brfss_162_2019, brfss_162_2020, brfss_162_2021, brfss_162_2022, brfss_162_2023)
# Save the combined dataframe to a CSV file
write.csv(brfss_162_2019to2023, "brfss_162_2019to2023.csv", row.names = FALSE)