library(tidyverse) # includes lubridate
library(eurostat) # install.packages("eurostat")
# euro area members (ECB country codes)
ea <- c("AT","BE","BG","CY","DE","EE","ES","FI","FR","GR","HR",
"IE","IT","LT","LU","LV","MT","NL","PT","SI","SK")
cc <- paste(ea, collapse = "+")
start <- "2015-01"
# helper: ECB Data Portal API -> tibble
ecb_get <- function(flow, key, start = "2015-01") {
url <- paste0("https://data-api.ecb.europa.eu/service/data/", flow, "/", key,
"?format=csvdata&startPeriod=", start)
read_csv(url, show_col_types = FALSE) |>
select(REF_AREA, TIME_PERIOD, OBS_VALUE)
}
# 1. ECB deposit facility rate (daily -> monthly average)
dfr <- ecb_get("FM", "D.U2.EUR.4F.KR.DFR.LEV", start) |>
mutate(date = floor_date(as.Date(TIME_PERIOD), "month")) |>
group_by(date) |>
summarise(dfr = mean(OBS_VALUE, na.rm = TRUE), .groups = "drop")
# 2. HICP inflation, annual rate of change
inflation <- ecb_get("HICP", paste0("M.", cc, ".N.000000.4D0.ANR"), start) |>
transmute(country = REF_AREA, date = ym(TIME_PERIOD), inflation = OBS_VALUE)
# 3. Cost of borrowing for house purchase, new business
mortgage <- ecb_get("MIR", paste0("M.", cc, ".B.A2C.AM.R.A.2250.EUR.N"), start) |>
transmute(country = REF_AREA, date = ym(TIME_PERIOD), mortgage_rate = OBS_VALUE)
# 4. Unemployment rate, seasonally adjusted (Eurostat uses EL for Greece)
unemployment <- get_eurostat(
"une_rt_m",
filters = list(geo = recode(ea, GR = "EL"), s_adj = "SA",
age = "TOTAL", sex = "T", unit = "PC_ACT"),
time_format = "date") |>
rename_with(~ "date", any_of(c("time", "TIME_PERIOD"))) |>
transmute(country = recode(geo, EL = "GR"), date, unemployment = values) |>
filter(date >= ym(start))
# combine into one panel
panel <- inflation |>
left_join(mortgage, by = c("country", "date")) |>
left_join(unemployment, by = c("country", "date")) |>
left_join(dfr, by = "date") |>
mutate(period = case_when(
date < as.Date("2022-07-01") ~ "Negative rates", # first hike July 2022
date < as.Date("2024-06-01") ~ "Tightening", # first cut June 2024
TRUE ~ "Easing"
) |> factor(levels = c("Negative rates", "Tightening", "Easing"))) |>
select(date, country, period, dfr, inflation, mortgage_rate, unemployment) |>
arrange(country, date)
write_csv(panel, "ea_panel.csv") # saves a copy so you don't re-download each render