Skip to content

Instantly share code, notes, and snippets.

@MattCowgill
Created April 26, 2023 04:09
Show Gist options
  • Save MattCowgill/be796a3147082ef86fe33e40987f2ed1 to your computer and use it in GitHub Desktop.
Save MattCowgill/be796a3147082ef86fe33e40987f2ed1 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(readabs)
# This data contains groups, sub-groups, and expenditure classes
cpi_t13 <- read_abs("6401.0", "13")
# Fetch a list of expenditure classes, as we want to filter to just those
cpi_t14 <- read_abs("6401.0", 14)
exp_classes <- cpi_t14 |>
pull(series) |>
unique() |>
str_remove("Combined Seasonal Adjustment Factors ;") |>
paste(collapse = "|")
# 3% threshold, in quarterly annualised terms
threshold <- 1.03^(1/4)-1
above_target <- cpi_t13 |>
filter(str_detect(series, exp_classes),
!is.na (value)) |>
group_by(series) |>
mutate(quarterly_growth = (value / lag(value, 1, order_by = date)) - 1) |>
filter(!is.na(value)) |>
group_by(date) |>
summarise(num_above_target = sum(quarterly_growth > threshold, na.rm = TRUE),
n = n()) |>
mutate(prop_above_target = num_above_target / n)
# Make the chart!
above_target |>
filter(year(date) >= 1998) |>
ggplot(aes(x = date, y = prop_above_target)) +
geom_line() +
theme_minimal() +
scale_y_continuous (labels = scales:: percent,
limits = c(.1, 1),
expand = expansion(0)) +
theme(axis.title = element_blank() ) +
labs(subtitle= "Proportion of CPI expenditure classes with ›3% annual inflation",
caption = "Source: ABS CPI")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment