Skip to contents

This function accepts a data frame df, an index date option index_date which is either a fixed date or the name of a date variable in quotes, and a variable lookback_days that encodes how many days of Medicare coverage are necessary.

Usage

verify_medicare_primary(
  df,
  index_date,
  lookback_days = 365,
  medicare_coverage_df = NULL,
  coverage_start_variable = NULL,
  coverage_end_variable = NULL,
  cache = FALSE
)

Arguments

df

is a data frame, presumably one with a single row per patient. Data frame must contain a column named USRDS_ID.

index_date

either a fixed date or the name of a date variable in quotes

lookback_days

is the number of days of Medicare as primary necessary. Default value is 365.

medicare_coverage_df

is an optional parameter containing a df from the payhist file.

coverage_start_variable

is the name of the variable containing the start date of Medicare primary coverage for the coverage spell containing the index_date. The default value of NULL specifies no variable returned.

coverage_end_variable

is the name of the variable containing the end date of Medicare primary coverage for the coverage spell containing the index_date. The default value of NULL specifies no variable returned.

cache

whether or not to cache, or use a previously cached version, of the medicare coverage data frame. This can save substantial amounts of time in a loop.

Value

The original df data fame with the variable medicare_primary_TF added

Details

An optional variable medicare_coverage_df allows for a df containing information from the payhist file to be passed to the function. If left NULL, then the function will load the data via the load_usrds_file function, which can be very inefficient for multiple function calls.

It returns the same dataframe with a new variable medicare_primary_TF that takes the values TRUE or FALSE.

Optionally, the start dates and end dates of Medicare primary coverage for that coverage spell can also be returned by specifying names for the return variables in the coverage_start_variable and coverage_end_variable parameters. If unspecified, these parameters will not be returned.

For repeated use, setting cache=TRUE will either cache or use the processed version of the Medicare coverage file (whether generated by the function or derived from the medicare_coverage_df passed to the function).

Examples

if (FALSE) {

test_df<-data.frame(
USRDS_ID=c(30, 111112),
initial_dates=as.Date(c("1994-01-01", "2019-01-01"))
)

verify_medicare_primary(df=test_df, index_date = "initial_dates", lookback_days = 365)

}