Medicare Current Beneficiary Survey (MCBS)

License: GPL v3 Github Actions Badge

The monitoring system for Medicare enrollees in the United States on topics not available in the program’s administrative data, such as out of pocket expenditure and beneficiary satisfaction.

  • Survey and supplemental tables with one row per sampled individual, although downloadable datasets not linkable.

  • A complex sample survey designed to generalize to all elderly and disabled individuals with at least one month of program enrollment during the calendar year.

  • Released annually as a public use file since 2015.

  • Conducted by the Office of Enterprise Data and Analytics (OEDA) of the Centers for Medicare & Medicaid Services (CMS) through a contract with NORC at the University of Chicago.


Download, Import, Preparation

tf <- tempfile()

this_url <- "https://www.cms.gov/files/zip/cspuf2021.zip"

download.file( this_url , tf , mode = 'wb' )

unzipped_files <- unzip( tf , exdir = tempdir() )

mcbs_csv <- grep( '\\.csv$' , unzipped_files , value = TRUE )

mcbs_df <- read.csv( mcbs_csv )

names( mcbs_df ) <- tolower( names( mcbs_df ) )

Save Locally  

Save the object at any point:

# mcbs_fn <- file.path( path.expand( "~" ) , "MCBS" , "this_file.rds" )
# saveRDS( mcbs_df , file = mcbs_fn , compress = FALSE )

Load the same object:

# mcbs_df <- readRDS( mcbs_fn )

Survey Design Definition

Construct a complex sample survey design:

library(survey)

mcbs_design <-
    svrepdesign(
        weight = ~cspufwgt ,
        repweights = 'cspuf[0-9]+' ,
        mse = TRUE ,
        type = 'Fay' ,
        rho = 0.3 ,
        data = mcbs_df
    )

Variable Recoding

Add new columns to the data set:

mcbs_design <-
    update(
        
        mcbs_design ,

        one = 1 ,
        
        csp_age =
            factor( 
                csp_age , 
                levels = 1:3 , 
                labels = 
                    c( 
                        '01: younger than 65' ,
                        '02: 65 to 74' ,
                        '03: 75 or older'
                    )
            ) ,
        
        two_or_more_chronic_conditions = as.numeric( csp_nchrncnd > 1 ) ,

        csp_sex = factor( csp_sex , labels = c( 'male' , 'female' ) )
    )

Analysis Examples with the survey library  

Unweighted Counts

Count the unweighted number of records in the survey sample, overall and by groups:

sum( weights( mcbs_design , "sampling" ) != 0 )

svyby( ~ one , ~ csp_age , mcbs_design , unwtd.count )

Weighted Counts

Count the weighted size of the generalizable population, overall and by groups:

svytotal( ~ one , mcbs_design )

svyby( ~ one , ~ csp_age , mcbs_design , svytotal )

Descriptive Statistics

Calculate the mean (average) of a linear variable, overall and by groups:

svymean( ~ pamtoop , mcbs_design )

svyby( ~ pamtoop , ~ csp_age , mcbs_design , svymean )

Calculate the distribution of a categorical variable, overall and by groups:

svymean( ~ csp_sex , mcbs_design )

svyby( ~ csp_sex , ~ csp_age , mcbs_design , svymean )

Calculate the sum of a linear variable, overall and by groups:

svytotal( ~ pamtoop , mcbs_design )

svyby( ~ pamtoop , ~ csp_age , mcbs_design , svytotal )

Calculate the weighted sum of a categorical variable, overall and by groups:

svytotal( ~ csp_sex , mcbs_design )

svyby( ~ csp_sex , ~ csp_age , mcbs_design , svytotal )

Calculate the median (50th percentile) of a linear variable, overall and by groups:

svyquantile( ~ pamtoop , mcbs_design , 0.5 )

svyby( 
    ~ pamtoop , 
    ~ csp_age , 
    mcbs_design , 
    svyquantile , 
    0.5 ,
    ci = TRUE 
)

Estimate a ratio:

svyratio( 
    numerator = ~ pamtoop , 
    denominator = ~ pamttot , 
    mcbs_design 
)

Subsetting

Restrict the survey design to household income below $25,000:

sub_mcbs_design <- subset( mcbs_design , csp_income == 1 )

Calculate the mean (average) of this subset:

svymean( ~ pamtoop , sub_mcbs_design )

Measures of Uncertainty

Extract the coefficient, standard error, confidence interval, and coefficient of variation from any descriptive statistics function result, overall and by groups:

this_result <- svymean( ~ pamtoop , mcbs_design )

coef( this_result )
SE( this_result )
confint( this_result )
cv( this_result )

grouped_result <-
    svyby( 
        ~ pamtoop , 
        ~ csp_age , 
        mcbs_design , 
        svymean 
    )
    
coef( grouped_result )
SE( grouped_result )
confint( grouped_result )
cv( grouped_result )

Calculate the degrees of freedom of any survey design object:

degf( mcbs_design )

Calculate the complex sample survey-adjusted variance of any statistic:

svyvar( ~ pamtoop , mcbs_design )

Include the complex sample design effect in the result for a specific statistic:

# SRS without replacement
svymean( ~ pamtoop , mcbs_design , deff = TRUE )

# SRS with replacement
svymean( ~ pamtoop , mcbs_design , deff = "replace" )

Compute confidence intervals for proportions using methods that may be more accurate near 0 and 1. See ?svyciprop for alternatives:

svyciprop( ~ two_or_more_chronic_conditions , mcbs_design ,
    method = "likelihood" )

Regression Models and Tests of Association

Perform a design-based t-test:

svyttest( pamtoop ~ two_or_more_chronic_conditions , mcbs_design )

Perform a chi-squared test of association for survey data:

svychisq( 
    ~ two_or_more_chronic_conditions + csp_sex , 
    mcbs_design 
)

Perform a survey-weighted generalized linear model:

glm_result <- 
    svyglm( 
        pamtoop ~ two_or_more_chronic_conditions + csp_sex , 
        mcbs_design 
    )

summary( glm_result )

Replication Example

This example matches the weighted total from the 2021 Data User’s Guide: Cost Supplement File Public Use File:

stopifnot( round( coef( svytotal( ~ one , mcbs_design ) ) , 0 ) == 59040948 )

Analysis Examples with srvyr  

The R srvyr library calculates summary statistics from survey data, such as the mean, total or quantile using dplyr-like syntax. srvyr allows for the use of many verbs, such as summarize, group_by, and mutate, the convenience of pipe-able functions, the tidyverse style of non-standard evaluation and more consistent return types than the survey package. This vignette details the available features. As a starting point for MCBS users, this code replicates previously-presented examples:

library(srvyr)
mcbs_srvyr_design <- as_survey( mcbs_design )

Calculate the mean (average) of a linear variable, overall and by groups:

mcbs_srvyr_design %>%
    summarize( mean = survey_mean( pamtoop ) )

mcbs_srvyr_design %>%
    group_by( csp_age ) %>%
    summarize( mean = survey_mean( pamtoop ) )