Skip to content

Instantly share code, notes, and snippets.

@rwalk
Last active Dec 27, 2016
Embed
What would you like to do?
CHIS 2015: Insurance coverage type vs fast food consumption
library(foreign)
library(car)
library(ggplot2)
library(scales)
# load the CHIS data
file <- "~/projects/CHIS/chis15_adult_stata/Data/ADULT.dta" # your file
CHIS <- read.dta(file, convert.factors = TRUE)
# Recode insurance type
recodeSTR = "
c('MEDICARE & OTHERS', 'MEDICARE ONLY', 'MEDICARE & MEDICAID') = 'MEDICARE';
"
CHIS$coverage_type = recode(CHIS$instyp, recodeSTR)
# break number times fast food consumed last week into categorical buckets
CHIS$fast_food = cut(CHIS$ac31, right=FALSE,
breaks=c(0,1,2,5,1000),
labels=c("0","1","2-4","5+"))
# compute summary df
df <- as.data.frame(prop.table(xtabs(rakedw0 ~ coverage_type + fast_food, CHIS, drop.unused.levels=TRUE),1))
# plot result
cov_types = c("MEDICARE", "MEDICAID", "EMPLOYMENT-BASED", "UNINSURED", "PRIVATELY PURCHASED")
ggplot(df[df$coverage_type %in% cov_types,], aes(x=coverage_type, y=Freq, fill=fast_food)) + geom_bar(stat="identity") +
scale_fill_manual(values=c("gray","pink","red","darkred"), name="Fast food\nlast week\n(# times)") +
xlab("coverage type") + ylab("proportion") +
ggtitle("Fast Food vs Insurance Coverage Type")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment