knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>", 
  echo = FALSE,
  fig.align = 'center',
  warning = FALSE,
  message = FALSE,
  cache = TRUE 
)

knitr::opts_knit$set(root.dir = rprojroot::find_rstudio_root_file())
librarian::shelf(tidyverse, fim, tsibble, purrr, lubridate)
devtools::load_all()

# Load previous months results
previous <-
  readxl::read_xlsx('results/5-2021/fim-5-2021.xlsx') %>%
  mutate(date = yearquarter(date)) %>%
  drop_na(date) %>%
  as_tsibble(index = date) %>%
  filter_index("2020 Q2" ~ "2023 Q1") %>% 
  mutate(federal_non_health_grants_arp = mpc_non_health_grants_arp(federal_non_health_grants_arp)) %>% 
  mutate(federal_purchases = federal_purchases + federal_non_health_grants_arp,
         federal_purchases_contribution = federal_purchases_contribution + federal_non_health_grants_arp_contribution) %>% 
  mutate(federal_ui = federal_ui,
         federal_ui_contribution = federal_ui_contribution + federal_ui_arp_contribution) %>% 
  mutate(federal_ui = federal_ui + federal_ui_arp,
         federal_ui_contribution = federal_ui_contribution + federal_ui_arp_contribution) %>% 
  mutate(federal_health_outlays= federal_health_outlays + federal_health_grants_arp,
         federal_health_outlays_contribution = federal_health_outlays_contribution + federal_health_grants_arp_contribution)


forecast <- readxl::read_xlsx('data/forecast_06_2021.xlsx',
                              sheet = 'forecast') %>% 
  select(-name) %>% 
  pivot_longer(-variable) %>% 
  pivot_wider(names_from = 'variable',
              values_from = 'value') %>% 
  rename(date = name) %>% 
  mutate(date = yearquarter(date))


current <- readRDS('data/contributions.RDS') %>%
  mutate(date = yearquarter(date)) %>%
  drop_na(date) %>%
  as_tsibble(index = date) %>%
  filter_index("2020 Q2" ~ "2023 Q1")

previous_long <- pivot_longer(previous, cols = where(is.numeric), values_to = 'previous')
current_long <- pivot_longer(current, cols = where(is.numeric), values_to = 'current')

comparison <- inner_join(previous_long,
                         current_long,
                         by = c('date', 'name', 'id')) %>%
  rename(variable = name) %>% 
  pivot_longer(c(previous, current),
               values_to = 'value',
               names_to = 'source')



inner_join(previous_long,
          current_long,
          by = c('date', 'name', 'id')) %>%
  rename(variable = name) %>% 
  filter(variable %in% names(forecast[-1])) %>% 
  openxlsx::write.xlsx('comparison_levels.xlsx')

comparison_nested <-
  comparison %>%
  group_by(variable) %>%
  nest() %>%
  mutate(plot = purrr::map2(.x = variable,
                     .y = data,
                     .f = ~fim::comparison_plot(.data = .y,
                                           variable = .x)))

# 
plots <- rlang::set_names(comparison_nested$plot, comparison_nested$variable)  

Purchases & Grants

During the last update, we were counting all of the grants and purchases from the American Rescue Plan as federal purchases. Hence, of the $r previous %>% filter_index('2021 Q2') %>% pull(federal_purchases) billion in federal purchases in 2021 Q2, $r previous %>% filter_index('2021 Q2') %>% pull(federal_non_health_grants_arp) were from the American Rescue Plan. In 2021 Q3, federal purchases were $r previous %>% filter_index('2021 Q2') %>% pull(federal_purchases) of which $r previous %>% filter_index('2021 Q2') %>% pull(federal_non_health_grants_arp) were from the American Rescue Plan.

However, the federal purchases portion from ARP was actually lower last time since we applied an MPC to it. Now, we only apply that MPC to the portion that we put into consumption grants. Therefore, our federal purchases are r current$federal_purchases[5] - previous$federal_purchases[5] billion higher this time.

The timing of federal purchases seems strange. Why does it go down so much in Q3 but then up in Q4?

The timing sheet in the spreadsheet adds up to 105%.

ggsave('results/06-2021/transfers_contribution.png', plots$transfers_contribution)
ggsave('results/06-2021/taxes_contribution.png', plots$taxes_contribution)
ggsave('results/06-2021/subsidies_contribution.png', plots$subsidies_contribution)
ggsave('results/06-2021/federal_purchases_contribution.png', plots$federal_contribution)
ggsave('results/06-2021/state_purchases_contribution.png', plots$state_contribution)
ggsave('results/06-2021/fiscal_impact.png', plots$fiscal_impact)
plots$taxes_contribution

plots$subsidies_contribution

plots$federal_contribution
plots$state_contribution
# 
# previous_purchases <-
#   previous %>% 
#   select(date, federal_purchases, state_purchases, consumption_grants, investment_grants) %>% 
#   mutate(federal_purchases_fim = federal_purchases + consumption_grants + investment_grants, 
#          state_purchases_fim = state_purchases - consumption_grants - investment_grants) %>% 
#   
#   as_tibble() %>% 
#   pivot_longer(-date)
# 
# current_purchases <-
#   current %>% 
#   select(date, federal_purchases, state_purchases, consumption_grants, investment_grants) %>% 
#   mutate(federal_purchases_fim = federal_purchases + consumption_grants + investment_grants, 
#          state_purchases_fim = state_purchases - consumption_grants - investment_grants) %>% 
#   
#   as_tibble() %>% 
#   select(-id) %>% 
#   pivot_longer(-date)
# 
# left_join(current_purchases, previous_purchases, by = c('date', 'name'),
#           suffix = c('_current', '_previous')) %>% 
#   filter_index("2021 Q2" ~ .)
plots$state_purchases
plots$consumption_grants


plots$federal_contribution
plots$fiscal_impact

Likewise, consumption grants are higher now given that we reattributed some of the ARP grants away from federal purchases.

plots$consumption_grants

State purchases have been unaffected by any of our changes

plots$state_contribution

Taxes

Transfers

Last time, we forgot to include the rebate checks from ARP that will go out in the next tax year.

plots$rebate_checks
plots$rebate_checks_arp

Health outlays

While our total medicaid forecast is unchanged, we bumped up our forecast for the federal portion of medicaid (Medicaid grants) to reflect the increased FMAP due to the ARP. This increases federal health outlays and decreases state health outlays a litte bit.

Why do we fall of one quarter sooner? Is it because we estimate that the pandemic will end in 2022 Q3?

plots$medicaid
plots$medicaid_grants

Our medicare forecast is unchanged. The difference of r current$medicare[5] - previous$medicare[5] is due to the Medicare sequester which we previously included in our federal health outlays add factor instead of directly into our Medicare forecast.

plots$medicare

Finally, the bulk of the difference in federal health outlays comes from double counting revenues from Medicaid, Medicare, and CHIP in CBO's ARP score. We had previously said that health grants from the ARP in Q2 2021 and Q3 2021 were r previous$federal_health_grants_arp[5]. Afterwards, we had r previous$federal_health_grants_arp[7] for 4 quarters. Since the MPC for health outlays is high (90% over four quarters), this overestimated the contribution of federal health outlays considerably.

plots$federal_health_outlays
plots$state_health_outlays

Unemployment Insurance

Previously, we guessed that regular federal UI would be $20 billion and that the ARP UI was r previous$federal_ui_arp[5]. Since our ARP score was based on an outdated unemployment rate forecast from CBO, we changed it to reflect higher employment growth due to reopenings.

plots$federal_ui


plots$state_ui

Subsidies

We took out the business meals deductions from subsidies since we believe they're actually a tax break instead. Moreover, we changed our PPP forecast to more accurately predict the timing of how BEA will write PPP disbursements down. In particular, we had $568 billion in PPP for Q2 2021 and Q3 2021 previously and now we have 488, 322 and 32 in Q1 through Q3 of 2021. Hence, oour PPP forecast is 294 lower.

Otherwise, our forecast is the same (nothing from the ARP changed)

plots$federal_subsidies
plots$federal_aid_to_small_businesses_arp

Other direct aid ARP

Unchanged

plots$federal_other_direct_aid_arp

Other vulnerable ARP

Not sure why this is different. ASK LOUISE

plots$federal_other_vulnerable_arp

Social benefits remainder (Net of Medicare, Medicaid, UI, and Rebate checks)

plots$federal_social_benefits

Taxes

plots$federal_non_corporate_taxes
plots$state_non_corporate_taxes
plots$federal_corporate_taxes
plots$state_corporate_taxes
plots$federal_corporate_taxes_contribution

contributions

plots$federal_social_benefits
plots$rebate_checks_contribution
plots$rebate_checks_arp_contribution

plots$federal_purchases_contribution


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