Skip to content

Instantly share code, notes, and snippets.

@MattCowgill
Created January 21, 2024 22:55
Show Gist options
  • Save MattCowgill/33bfa9363d262d6643de9a30e57dcac5 to your computer and use it in GitHub Desktop.
Save MattCowgill/33bfa9363d262d6643de9a30e57dcac5 to your computer and use it in GitHub Desktop.
Correlation between quarterly growth in WPI and CPI
library(tidyverse)
library(readabs)
cpi_sa <- read_abs_series("A3604507J") |>
select(date, cpi = value) |>
filter(!is.na(cpi))
wpi_sa <- read_abs_series("A83895395V") |>
select(date, wpi = value) |>
filter(!is.na(wpi))
wpi_lead_lag <- map(1:4,
~mutate(wpi_sa,
"Past_{.x}" := lag(wpi, .x)) |>
mutate("Future_{.x}" := lead(wpi, .x))) |>
reduce(left_join)
wpi_cpi <- wpi_lead_lag |>
rename(Current_0 = wpi) |>
left_join(cpi_sa, by = "date")
corrs <- wpi_cpi |>
corrr::correlate() |>
select(term, cpi) |>
filter(term != "cpi") |>
separate(term, into = c("series", "lag_num"), sep = "_") |>
mutate(lag_num = as.numeric(lag_num),
lag_num = if_else(series == "Past", -lag_num, lag_num))
cols <- c("Past" = "#4472c4",
"Current" = "#7d7d7d",
"Future" = "#ff0000")
corrs |>
ggplot(aes(x = lag_num, y = cpi, fill = series, col = series)) +
geom_col() +
geom_text(data = ~group_by(., series) |>
filter(cpi == min(cpi)),
aes(label = glue::glue("Corr. of {tolower(series)} wage growth with current inflation") |>
str_wrap(12)),
vjust = -0.2) +
scale_y_continuous(breaks = seq(0,1, .1),
limits = \(x) c(0, x[2]),
expand = expansion(c(0, 0.05))) +
scale_x_continuous(labels = \(x) if_else(x == 0,
"WPI (current)",
glue::glue("WPI (t{scales::number(x, style_positive = 'plus')})")
),
breaks = -4:4) +
theme_minimal(base_size = 16) +
scale_fill_manual(values = cols) +
scale_colour_manual(values = cols) +
theme(axis.title = element_blank(),
legend.position = "none",
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank()) +
labs(title = "Intertemporal correlations of price and wage growth (1997-2023), Australia")
ggsave("cor_wpi_cpi.png",
width = 40,
height = 22,
units = "cm",
bg = "white",
scale = 0.8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment