knitr::opts_chunk$set(echo = TRUE)
library('tidyverse')
library('tsibble')
devtools::load_all()

Medicaid

This document will outline all the things you should be aware of when forecasting medicaid. Hopefully, it will give you a step by step guide to our process.

Outline

Code

Construct quarterly and annual fmap

bea  <- fim::national_accounts %>% 
  select(date,
         medicaid  = yptmd,
         medicaid_grants = gfeghdx) %>% 
  filter_index("2019 Q1" ~ .) 

bea <- bea %>% 
  mutate(fmap_quarterly = medicaid_grants / medicaid) %>% 
  #separate(date, into = c('year', 'quarter'), sep = ' ') %>% 
  group_by(year=  year(date)) %>% 
  mutate(fmap_annual = mean(fmap_quarterly)) %>% 
  ungroup()


fmap <- readxl::read_xlsx('inst/extdata/projections.xlsx', 
                          sheet = 'annual fmap') 

fmap_quarterly <- readxl::read_xlsx('inst/extdata/projections.xlsx',
                                    sheet = 'quarterly fmap') %>% 
  mutate(date = yearquarter(date))
cbo_projections <-
  readxl::read_xlsx('inst/extdata/projections.xlsx', sheet = 'budget') %>% 
  as_tsibble(index = fy) 

Take the CBO projection and

medicaid_forecast <- cbo_projections %>% 
  mutate(federal_medicaid = yptmd, .after = 'fy') %>% 
  left_join(fmap, by = 'fy') %>% 
  relocate(fmap, .after = 'fy') %>% 
  mutate(medicaid = if_else(!is.na(fmap), federal_medicaid / fmap, federal_medicaid), .before = 'federal_medicaid') %>% 
  #  Deannualize annual  growth rate
  mutate(medicaid_growth = (medicaid / lag(medicaid))^0.25 - 1, .after = 'fy') %>% 
  select(-fmap) %>% 
  as_tsibble(index = fy) %>% 
  annual_to_quarter() %>% 
  fiscal_to_calendar() %>% 
  left_join(fmap_quarterly, by = 'date') %>% 
  filter_index("2020 Q4" ~ .) %>% 
  mutate(state_medicaid = medicaid - federal_medicaid, .after = 'federal_medicaid')
medicaid_forecast <-
  readxl::read_xlsx('inst/extdata/projections.xlsx', sheet = 'budget') %>% 
  as_tsibble(index = fy) %>% 
  mutate(federal_medicaid = yptmd, .after = 'fy') %>% 
  left_join(fmap, by = 'fy') %>% 
  relocate(fmap, .after = 'fy') %>% 
  mutate(medicaid = if_else(!is.na(fmap), federal_medicaid / fmap, federal_medicaid), .before = 'federal_medicaid') %>% 
  mutate(medicaid_growth = (medicaid / lag(medicaid))^0.25 - 1, .after = 'fy') %>% 
  select(-fmap) %>% 
  as_tsibble(index = fy) %>% 
  annual_to_quarter() %>% 
  fiscal_to_calendar() %>% 
  left_join(fmap_quarterly, by = 'date') %>% 
  filter_index("2020 Q4" ~ .) %>% 
  mutate(state_medicaid = medicaid - federal_medicaid, .after = 'federal_medicaid') %>% 
  select(date, medicaid_growth, fmap)
read_data() %>% 
  define_variables() %>% 
  select(-medicaid_growth) %>% 
  left_join(medicaid_forecast %>% 
              select(date, fmap, medicaid_growth), by = 'date') %>% 
  select(date, id,  medicaid,  federal_medicaid  =  medicaid_grants,
         medicaid_growth, fmap) %>% 
  mutate(state_mediciad  = medicaid - federal_medicaid) %>% 
  filter_index("2020  Q4" ~ .) %>% 
  key_vars()
contribution %>% 
  summarise(date,fmap,  medicaid,fed = medicaid *  fmap, federal_medicaid = medicaid_grants, state_medicaid = medicaid - federal_medicaid) %>% 
  filter_index("2021 Q1" ~ . )


malcalakovalski/fim documentation built on July 30, 2024, 8:37 a.m.