Get started with tidyusmacro

library(tidyusmacro)

tidyusmacro downloads full flat files from BLS, BEA, and FRED and returns them as tidy data frames, with the lookup tables already joined. One call gets you the entire release, which is what you want for exploratory work, in-depth research, and real-time analysis on data days. BLS and BEA files update right as releases go live; FRED usually follows about 40 minutes later.

Data retrieval

BLS flat files

getBLSFiles() downloads and processes data from Bureau of Labor Statistics flat files. Supports CPI, ECI, JOLTS, CPS, CES, and CEX (Consumer Expenditure Survey). BLS asks for an email address in the user agent for flat-file downloads.

cpi_data <- getBLSFiles(data_source = "cpi", email = "[email protected]")
jolts_data <- getBLSFiles(data_source = "jolts", email = "[email protected]")

getCESRevisions() downloads the revisions table of the Current Employment Survey (CES) total jobs numbers straight from the BLS website.

revisions_df <- getCESRevisions()

BEA NIPA tables

getNIPAFiles() downloads and formats BEA NIPA data flat files, either monthly or quarterly values.

nipa_quarterly <- getNIPAFiles(type = "Q")
nipa_monthly <- getNIPAFiles(type = "M")

getPCEInflation() loads and processes Personal Consumption Expenditures (PCE) inflation data with weights and growth measures.

pce_monthly <- getPCEInflation("M")
pce_quarterly <- getPCEInflation("Q")

getDallasTrimPCE() builds the component-level panel underlying the Dallas Fed Trimmed Mean PCE inflation rate: monthly price changes, Fisher expenditure-share weights, and flags for which components are trimmed each month. Useful for replicating the trimmed-mean rate or analyzing what gets trimmed.

# Default 24/31 Dallas Fed trim
panel <- getDallasTrimPCE()

# Replicate the monthly trimmed-mean rate
panel |>
  dplyr::filter(!is_trimmed) |>
  dplyr::group_by(date) |>
  dplyr::summarize(trim_pce = weighted.mean(price_change, weight))

FRED

getFRED() downloads and merges economic data series from the Federal Reserve Economic Data (FRED) API.

# Named arguments give friendly column names
fred_data <- getFRED(prime_epop = "LNS12300060", cpi = "CPIAUCSL")

# Unnamed arguments use lowercase ticker as column name
fred_data <- getFRED("UNRATE", "PAYEMS")

getUnrateFRED() is a convenience function to download unemployment level and labor force from FRED and calculate the unemployment rate.

unrate_data <- getUnrateFRED()

Statistical functions

logLinearProjection() performs log-linear projections on historical data. Designed for use within dplyr verbs.

library(dplyr)

data %>%
  mutate(projection = logLinearProjection(
    date = date,
    value = gdp,
    start_date = "2015-01-01",
    end_date = "2019-12-01"
  ))

Visualization

theme_esp() is a custom ggplot2 theme for Economic Security Project graphics with cream background and clean styling.

library(ggplot2)

ggplot(data, aes(date, value)) +
  geom_line(color = esp_navy) +
  theme_esp()

scale_color_esp() and scale_fill_esp() provide ESP-branded color scales for ggplot2.

ggplot(data, aes(date, value, color = category)) +
  geom_line() +
  scale_color_esp() +
  theme_esp()

date_breaks_gg() creates intelligent date breaks for ggplot2 that always include the last data point.

ggplot(data, aes(date, value)) +
  geom_line() +
  scale_x_date(breaks = date_breaks_gg(n = 6, last = max(data$date)))

date_breaks_n() generates evenly spaced date breaks by selecting every nth unique date.

ggplot(data, aes(date, value)) +
  geom_line() +
  scale_x_date(breaks = date_breaks_n(data$date, n = 6))

Included data

cesDiffusionIndex is a tibble with 250 rows mapping CES industry codes to industry titles.

data(cesDiffusionIndex)

dallasTrimPCEcomponents is the 177-component dictionary used by getDallasTrimPCE(), mapping Dallas Fed trimmed-mean PCE components to BEA NIPA series codes and line numbers (Table 2.4.4U).

data(dallasTrimPCEcomponents)