The following is a quick-reference guide to compare common programming statements using SAS, STATA, and R to analyze MEPS expenditure data. Note that each language requires use of functions and methods specifically built to analyze survey data.
These examples are based on the 2011 Full-Year-Consolidated public use file (HC-147).
Description | SAS | STATA | R |
---|---|---|---|
Full Population | proc surveymeans data=FYC; stratum VARSTR; cluster VARPSU; weight PERWT11F; var TOTEXP11; run; |
svyset [pweight=perwt11f], strata(varstr) psu(varpsu) svy: mean totexp11 |
library(survey) mepsdsgn <- svydesign( id=~VARPSU, strata=~VARSTR, weights=~PERWT11F, data=FYC, nest=TRUE) svymean(~TOTEXP11, mepsdsgn) |
Sub-population | proc surveymeans DATA=FYC; stratum VARSTR; cluster VARPSU; weight PERWT11F; var TOTEXP11; domain SEX; run; |
svy: mean totexp11, subpop(sex) |
svymean(~TOTEXP11, subset(mepsdsgn,SEX==1)) |
Comparing groups |
proc surveyreg DATA=FYC; stratum VARSTR; cluster VARPSU; weight PERWT11F; class SEX; model TOTEXP11=SEX/NOINT solution VADJUST=NONE; lsmeans SEX/DIFF; contrast "Male vs. female" SEX 1 -1; run; |
svy: mean totexp11, over(sex) lincom [totexp11]1-[totexp11]2 |
svyby(~TOTEXP11, by=~SEX, design = mepsdsgn, FUN = svymean) svyttest(TOTEXP11~SEX, design = mepsdsgn) summary( svyglm(TOTEXP11~factor(SEX), design = mepsdsgn)) |