Table 3.3. State and Local Government Current Receipts and Expenditures - T30300

Data - BEA

Ex 1: Receipts, Expenditures and Net Saving as % of GDP

Code
gdp_A <- read_parquet("gdp_A.parquet") |>
  mutate(year = year(date)) |>
  select(year, gdp = value)

T30300_A |>
  filter(LineNumber %in% c(35, 38, 32)) |>
  year_to_date() |>
  mutate(year = year(date),
         LineDescription = case_when(LineNumber == 35 ~ "Total receipts",
                                      LineNumber == 38 ~ "Total expenditures",
                                      LineNumber == 32 ~ "Net saving")) |>
  left_join(gdp_A, by = "year") |>
  mutate(share = DataValue/gdp) |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = share, color = LineDescription)) +
  geom_hline(yintercept = 0, linetype = "dashed", color = "grey50") +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1959-01-01")),
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
            fill = 'grey', alpha = 0.5) +
  scale_x_date(breaks = seq(1930, 2100, 10) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
  scale_color_manual(values = viridis(3)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("% of GDP") + xlab("")

Ex 2: Composition of Receipts

Code
receipts_total <- T30300_A |> filter(LineNumber == 1) |> select(TimePeriod, total = DataValue)

T30300_A |>
  filter(LineNumber %in% c(3, 6, 11, 12, 18)) |>
  left_join(receipts_total, by = "TimePeriod") |>
  mutate(share = DataValue/total) |>
  year_to_date() |>
  ggplot() + theme_minimal() +
  geom_line(aes(x = date, y = share, color = LineDescription)) +
  geom_rect(data = nber_recessions |>
              filter(Peak > as.Date("1959-01-01")),
            aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
            fill = 'grey', alpha = 0.5) +
  scale_x_date(breaks = seq(1930, 2100, 10) |> paste0("-01-01") |> as.Date(),
               labels = date_format("%Y")) +
  scale_y_continuous(labels = scales::percent_format(accuracy = 1)) +
  scale_color_manual(values = viridis(5)) +
  theme(legend.title = element_blank(),
        legend.position = "bottom") +
  ylab("% of current receipts") + xlab("")