rdb(ids = c("BEA/NIPA-T10106/A191RX-A",
"BEA/NIPA-T10105/DDURRC-A",
"BEA/NIPA-T10105/A191RC-A")) |>
select(series_code, date = period, value) |>
spread(series_code, value) |>
rename(GDP = `A191RC-A`,
`Durable Goods` = `DDURRC-A`,
`Real GDP` = `A191RX-A`) |>
mutate(year = lubridate::year(date),
`Real GDP HP (10000) Trend` = exp(hpfilter(log(`Real GDP`), freq = 10000,
type = "lambda", drift = FALSE)$trend),
`Real GDP Log-Linear Trend` = exp(fitted(lm(log(`Real GDP`) ~ year,
na.action = na.exclude))),
`Durable Goods (% of GDP)` = `Durable Goods` / GDP,
`Durable Goods (% of Log-Linear GDP Trend)` =
(`Durable Goods` / GDP)*(`Real GDP` / `Real GDP Log-Linear Trend`),
`Durable Goods (% of HP GDP Trend)` =
(`Durable Goods` / GDP)*(`Real GDP` / `Real GDP HP (10000) Trend`)) |>
select(date, contains("Durable Goods (%")) |>
gather(variable, value, -date) |>
ggplot() +
geom_line(aes(x = date, y = value, linetype = variable)) +
theme_minimal() +
theme(legend.title = element_blank(),
legend.position = c(0.3, 0.85)) +
geom_rect(data = nber_recessions |>
filter(Peak >= as.Date("1928-01-01")),
aes(xmin = Peak, xmax = Trough, ymin = -Inf, ymax = +Inf),
fill = 'grey', alpha = 0.5) +
scale_x_date(breaks = nber_recessions$Peak,
labels = date_format("%Y")) +
scale_y_continuous(breaks = 0.01*seq(2, 16, 1),
limits = 0.01*c(2, 16),
labels = scales::percent_format(accuracy = 1)) +
xlab("") + ylab("Durable Goods (% of GDP)")