Skip to contents

This vignette walks through the most common starting workflow with fred: fetching several series in one call, applying a server-side transformation, pivoting to wide format for cross-series analysis, and producing a default plot with recession shading.

The chunks below require an API key (set via fred_set_key() or the FRED_API_KEY environment variable). If no key is set, code is shown but not executed.

Setup

A core macro panel

A typical first move is to grab GDP, unemployment, and headline CPI together, on a long format that is easy to iterate over.

panel <- fred_series(
  c("GDPC1", "UNRATE", "CPIAUCSL"),
  from = "2000-01-01"
)
panel

The print header tells you immediately what you are looking at: three series, how many rows, which transformation was applied, the frequency, and any vintage information. Underneath, panel is a plain data frame.

Transformations

For inflation and growth analyses, raw levels are usually less useful than year-on-year percent change. Pass a readable transform rather than the raw FRED units code:

growth_panel <- fred_series(
  c("GDPC1", "CPIAUCSL"),
  from = "2010-01-01",
  transform = "yoy_pct"
)
growth_panel

transform and units are mutually exclusive. The full list of readable aliases lives in ?fred_series. Server-side transforms avoid a manual diff(log(x)) step and ensure the result matches what FRED itself shows.

Wide format for cross-series work

For correlation matrices, scatter plots, or regression input, wide is more convenient than long.

wide <- fred_series(
  c("UNRATE", "CIVPART", "EMRATIO"),
  from = "2000-01-01",
  format = "wide"
)
head(wide)

Default plot

The default plot.fred_tbl() method handles long and wide format automatically and shades NBER recessions when the date range overlaps one.

plot(growth_panel, ylab = "% YoY")
plot(wide, ylab = "%", main = "US labour market")

Pass recessions = FALSE to switch off shading. Pass a col = vector of length equal to the number of series to override the default palette.

A starting catalogue

If you cannot remember a series ID, fred_catalogue() ships a curated offline reference of around 50 widely used series:

fred_catalogue(category = "Inflation")
#> # FRED: catalogue · 6 rows
#>         id                                                     title frequency
#> 1 CPIAUCSL                    CPI for All Urban Consumers: All Items         M
#> 2 CPILFESL         CPI for All Urban Consumers: Less Food and Energy         M
#> 3    PCEPI Personal Consumption Expenditures: Chain-type Price Index         M
#> 4 PCEPILFE     PCE Excluding Food and Energy: Chain-type Price Index         M
#> 5   PPIACO        Producer Price Index by Commodity: All Commodities         M
#> 6   T10YIE                          10-Year Breakeven Inflation Rate         D
#>               units  category                               description
#> 1 Index 1982-84=100 Inflation     BLS headline CPI, seasonally adjusted
#> 2 Index 1982-84=100 Inflation                              BLS core CPI
#> 3    Index 2017=100 Inflation                 BEA headline PCE deflator
#> 4    Index 2017=100 Inflation        BEA core PCE deflator (Fed target)
#> 5    Index 1982=100 Inflation                   BLS PPI all commodities
#> 6           Percent Inflation Market-implied 10y inflation expectations

Filtering with query = does a case-insensitive substring match against the ID, title, and description:

fred_catalogue(query = "mortgage")
#> # FRED: catalogue · 1 row
#>             id                               title frequency   units
#> 1 MORTGAGE30US 30-Year Fixed Rate Mortgage Average         W Percent
#>         category                        description
#> 1 Interest Rates Freddie Mac PMMS 30y mortgage rate

For the FRED category tree, use fred_browse(). With no arguments it shows the eight top-level categories from a static reference (no API call):

fred_browse()
#> FRED top-level categories
#> -------------------------
#>    32991  Money, Banking, & Finance
#>       10  Population, Employment, & Labor Markets
#>    32992  National Accounts
#>        1  Production & Business Activity
#>    32455  Prices
#>    32263  International Data
#>     3008  U.S. Regional Data
#>    33060  Academic Data
#> 
#> Use fred_browse(id) to drill into a category.

Pass a category ID to drill into its children (this hits the API and is cached).

Where to next