Read and Unzip
for (i in 2011:2019){
p1=paste0("https://www.cdc.gov/brfss/annual_data/",i,"/files/LLCP",i,"XPT.zip")
p2=paste0("Y",i,".zip")
download.file(p1,p2)
unzip(p2)
}
y2011=read.xport("LLCP2011.XPT")
y2012=read.xport("LLCP2012.XPT")
y2013=read.xport("LLCP2013.XPT")
y2014=read.xport("LLCP2014.XPT")
y2015=read.xport("LLCP2015.XPT")
y2016=read.xport("LLCP2016.XPT")
y2017=read.xport("LLCP2017.XPT")
y2018=read.xport("LLCP2018.XPT")
y2019=read.xport("LLCP2019.XPT")
Annotations follow.
y2019$DIABETE3=y2019$DIABETE4 #identical question in codebook year over year
y2019$DIABAGE2=y2019$DIABAGE3 #identical question in codebook year over year
y2019$INSULIN=y2019$INSULIN1 #identical question in codebook year over year
#Cannot use Feetchk3...exists only in 2019
#Using Feetchk instead (all surveys)
#HLTHCVR1 = delete, not consistently asked
y2019$EYEEXAM=y2019$EYEEXAM1 #same question
y2018$EYEEXAM=y2018$EYEEXAM1 #same question
y2019$SEX=y2019$SEXVAR #gender questions are non-standard but standardizable
y2018$SEX=y2018$SEX1
y2011$EMPLOY1=y2011$EMPLOY #same question
y2012$EMPLOY1=y2012$EMPLOY
y2011$X.RACE.G1=y2011$X.RACE.G
y2012$X.RACE.G1=y2012$X.RACE.G
chck=c("X.AGE.G", "X.RACE.G1","SEX","MARITAL",
"INCOME2","EDUCA","EMPLOY1",
"HLTHPLN1","PERSDOC2", "CHECKUP1", "MEDCOST",
"DIABETE3","DIABAGE2","DIABEDU", "PDIABTST", "INSULIN",
"BLDSUGAR", "FEETCHK", "DOCTDIAB", "CHKHEMO3", "DIABEYE",
"EYEEXAM", "X.STSTR" , "X.LLCPWT", "X.STATE")
z=matrix(rep(0,10*length(chck)), nrow=10, ncol=length(chck))
for (i in 1:length(chck)){
if(chck[i] %in% colnames(y2011)){z[1,i]=1} else {z[1,i]=0}
if(chck[i] %in% colnames(y2012)){z[2,i]=1} else {z[2,i]=0}
if(chck[i] %in% colnames(y2013)){z[3,i]=1} else {z[3,i]=0}
if(chck[i] %in% colnames(y2014)){z[4,i]=1} else {z[4,i]=0}
if(chck[i] %in% colnames(y2015)){z[5,i]=1} else {z[5,i]=0}
if(chck[i] %in% colnames(y2016)){z[6,i]=1} else {z[6,i]=0}
if(chck[i] %in% colnames(y2017)){z[7,i]=1} else {z[7,i]=0}
if(chck[i] %in% colnames(y2018)){z[8,i]=1} else {z[8,i]=0}
if(chck[i] %in% colnames(y2019)){z[9,i]=1} else {z[9,i]=0}
z[10,i]=round(sum(z[1:10,i])/9,2)
}
colnames(z)=chck
rownames(z)=c(seq(2011,2019), "Proportion")
z%>%kbl()%>%kable_classic(html_font="Cambria")
| X.AGE.G | X.RACE.G1 | SEX | MARITAL | INCOME2 | EDUCA | EMPLOY1 | HLTHPLN1 | PERSDOC2 | CHECKUP1 | MEDCOST | DIABETE3 | DIABAGE2 | DIABEDU | PDIABTST | INSULIN | BLDSUGAR | FEETCHK | DOCTDIAB | CHKHEMO3 | DIABEYE | EYEEXAM | X.STSTR | X.LLCPWT | X.STATE | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2011 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2012 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2013 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2014 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2015 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2016 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2017 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2018 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| 2019 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Proportion | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
#Variables to Include
myvars=c("X.AGE.G", "X.RACE.G1","SEX","MARITAL",
"INCOME2","EDUCA","EMPLOY1",
"HLTHPLN1","PERSDOC2", "CHECKUP1", "MEDCOST",
"DIABETE3","DIABAGE2","DIABEDU", "PDIABTST", "INSULIN",
"BLDSUGAR", "FEETCHK", "DOCTDIAB", "CHKHEMO3", "DIABEYE",
"EYEEXAM", "X.STSTR" , "X.LLCPWT", "X.STATE")
#Pre-processing Function
myf=function(mydata, myvars){
mydata=mydata[myvars]
mydata$SEX[mydata$SEX>1]=0 #Modal Imputation, F=0, M=1
mydata$MARITAL[mydata$MARITAL>1]=0 #Recode as identified married or not
mydata$INCOME2[mydata$INCOME2>8]=9 #Separate category for unsure / refused
mydata$EDUCA[mydata$EDUCA==9]=6 #modal imputation
mydata$EMPLOY1[mydata$EMPLOY1==9]=1 #modal imputation
mydata$HLTHPLN1[mydata$HLTHPLN1==2]=0
mydata$HLTHPLN1[mydata$HLTHPLN1>2]=1 #modal imputation
mydata$PERSDOC2[mydata$PERSDOC2==3]=0 #no doc
mydata$PERSDOC2[mydata$PERSDOC2==2]=1 #2 docs = 1 or more
mydata$PERSDOC2[mydata$PERSDOC2>3]=1 #modal imputation
mydata$MEDCOST[mydata$MEDCOST>1]=0 #refused / don't know assumed greater 1 year
mydata$DIABETE3[mydata$DIABETE3>1]=0 #gestational, no, refused = 0
mydata$DIABEDU[mydata$DIABEDU>=2]=0
mydata$PDIABTST[mydata$PDIABTST>=2]=0
mydata$INSULIN[mydata$INSULIN>=2]=0
mydata$DOCTDIAB[mydata$DOCTDIAB==88]=0
mydata$DOCTDIAB[mydata$DOCTDIAB>76]=0
mydata$CHKHEMO3[mydata$CHKHEMO3==88]=0
mydata$CHKHEMO3[mydata$CHKHEMO3>76]=0
mydata$DIABEYE[mydata$DIABEYE>=2]=0 # dichtomous
mydata$EYEEXAM[mydata$EYEEXAM==2]=1 #within one year
mydata$EYEEXAM[mydata$EYEEXAM>2]=0
colnames(mydata)=c( "Age", "Race","Gender" ,"Married",
"Income", "Education" ,"Employed",
"Health Plan", "Have Dr.", "Checkup <1Yr" ,"No $ to Access" ,
"Diabetes (Non-G)" , "Age Told" , "Diabetes Class", "Test <3 Years" , "Insulin",
"Blood Sugar" , "Foot Check", "Doc for Diabetes" , "Hemo Check", "Eye Affected",
"Eye Check", "Stratum", "Weights", "State")
return(mydata)
}
y2011=myf(y2011,myvars)
y2012=myf(y2012,myvars)
y2013=myf(y2013,myvars)
y2014=myf(y2014,myvars)
y2015=myf(y2015,myvars)
y2016=myf(y2016,myvars)
y2017=myf(y2017,myvars)
y2018=myf(y2018,myvars)
y2019=myf(y2019,myvars)
# Set options for allowing a single observation per stratum
options(survey.lonely.psu = "adjust")
makesurvey=function(surveydata){
mysurvey <- svydesign(
id=~1,
strata = ~Stratum,
weights = ~Weights,
data = surveydata)
return(mysurvey)
}
#Build complex weighted survey lists
svy2011=makesurvey(y2011)
svy2012=makesurvey(y2012)
svy2013=makesurvey(y2013)
svy2014=makesurvey(y2014)
svy2015=makesurvey(y2015)
svy2016=makesurvey(y2016)
svy2017=makesurvey(y2017)
svy2018=makesurvey(y2018)
svy2019=makesurvey(y2019)
myplot=function(mydf,q){
mynames=c("Age Adjusted and by Gender")
mydf$Year=round(mydf$Year,0)
z=ggplot(mydf, aes (x=Year))+
geom_line(aes(y=Male, col="Male"))+
geom_line(aes(y=Female, col="Female"))+
geom_smooth(aes(y=Male, col="Male"), size=.2)+
geom_smooth(aes(y=Female, col="Female"), size=.2)+
scale_fill_continuous(name = "Gender", labels = c("Male", "Female"))+
ylab("Proportion")+
xlab("")+
xlim(2011,2019)+
theme(legend.title = element_blank())+
theme(legend.text = element_text(size = 6))+
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))+
ggtitle(mynames[q])+
theme(plot.title = element_text(size=11))+
theme(axis.text=element_text(size=6),
axis.title=element_text(size=6,face="bold"))+
theme(legend.key.size = unit(.5, "cm"))+
theme(legend.key.width = unit(0.2,"cm"))
return(z)
}
We build age-adjusted tables below to calculate proportions for vet and non-vet populations.
myf=function(svy){
male=ageadjust.direct(count=svytable(`Diabetes (Non-G)`~Gender+Age, svy)[2,],
pop=svytable(~Gender+Age, svy)[2,],
stdpop=svytable(`Diabetes (Non-G)`~Age, svy),
conf.level=.95
)
female=ageadjust.direct(count=svytable(`Diabetes (Non-G)`~Gender+Age, svy)[1,],
pop=svytable(~Gender+Age, svy)[1,],
stdpop=svytable(`Diabetes (Non-G)`~Age, svy),
conf.level=.95
)
z=rbind(male,female)
return(z[,1])
}
a9=myf(svy2011)
a10=myf(svy2012)
a11=myf(svy2013)
a12=myf(svy2014)
a13=myf(svy2015)
a14=myf(svy2016)
a15=myf(svy2017)
a16=myf(svy2018)
a17=myf(svy2019)
myval=rbind( a9, a10, a11, a12, a13, a14, a15, a16,a17)
mydf=as.data.frame(cbind(seq(2011,2019),myval))
colnames(mydf)=c("Year", "Male", "Female")
plot0=myplot(mydf, 1)
plot0
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'