Fred’s API

Data - Fred

Info

source dataset .html .RData
fred api 2025-01-07 NA

List of APIs

source dataset .html .RData
bdf api 2024-07-01 NA
bea api 2024-06-19 NA
bis api 2024-04-19 NA
bls api 2024-06-17 NA
dbnomics api 2024-06-07 NA
ecb api 2024-12-29 NA
eurostat api 2024-06-08 NA
imf api 2024-06-20 NA
insee api 2025-01-07 NA
oecd api 2024-05-07 2024-04-16
wdi api 2024-04-14 NA

LAST_COMPILE

LAST_COMPILE
2025-01-26

Info

Example 1

Code
"https://api.stlouisfed.org/fred/series?series_id=GNPCA&api_key=abcdefghijklmnopqrstuvwxyz123456" 
# [1] "https://api.stlouisfed.org/fred/series?series_id=GNPCA&api_key=abcdefghijklmnopqrstuvwxyz123456"

Find a Data series, or multiple

Code
fredr_series_search_text(search_text = "cpi cbsa rent",
                         order_by = "popularity",
                         sort_order = "desc") %>%
  select(id, title) %>%
  {if (is_html_output()) datatable(., filter = 'top', rownames = F) else .}

API

(ref:oil) Oil Prices

Code
map_dfr(c("CPIAUCSL", "WTISPLC"), fredr) %>% 
  spread(series_id, value) %>%
  na.omit %>%
  mutate(WTISPLC_real = CPIAUCSL[860]* WTISPLC / CPIAUCSL) %>% 
  select(date, WTISPLC, WTISPLC.real = WTISPLC_real) %>% 
  gather(variable, value, -date) %>%
  mutate(variable_desc = case_when(variable == "WTISPLC" ~ "Oil Prices (WTI)",
                                   variable == "WTISPLC.real" ~ "Real Oil Prices (WTI)")) %>%
  select(variable, variable_desc, everything()) %>%
  ggplot(data = .) + 
  geom_line(aes(x = date, y = value, linetype = variable_desc, color = variable_desc)) +
  labs(x = "Observation Date", y = "Rate") + theme_minimal() +
  scale_color_manual(values = viridis(3)[1:2]) +
  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) +
  theme(legend.title = element_blank(),
        legend.position = c(0.2, 0.8)) +
  scale_y_continuous(breaks = seq(0, 150, 25),
                labels = scales::dollar_format(accuracy = 1)) + 
  scale_x_date(breaks = as.Date(paste0(seq(1945, 2020, 5), "-01-01")),
               labels = date_format("%y"),
               limits = c(as.Date("1945-01-01"), as.Date("2020-01-01"))) +
  xlab("") + ylab("Oil Prices")

(ref:oil)

Modern Data

Code
fredr(series_id = "UNRATE") %>%
  tail(10) %>%
  {if (is_html_output()) print_table(.) else .}
date series_id value realtime_start realtime_end
2024-03-01 UNRATE 3.9 2025-01-10 2025-01-10
2024-04-01 UNRATE 3.9 2025-01-10 2025-01-10
2024-05-01 UNRATE 4.0 2025-01-10 2025-01-10
2024-06-01 UNRATE 4.1 2025-01-10 2025-01-10
2024-07-01 UNRATE 4.2 2025-01-10 2025-01-10
2024-08-01 UNRATE 4.2 2025-01-10 2025-01-10
2024-09-01 UNRATE 4.1 2025-01-10 2025-01-10
2024-10-01 UNRATE 4.1 2025-01-10 2025-01-10
2024-11-01 UNRATE 4.2 2025-01-10 2025-01-10
2024-12-01 UNRATE 4.1 2025-01-10 2025-01-10
Code
fredr(series_id = "UNRATE",
      observation_start = as.Date("1990-01-01")) %>%
  head(10) %>%
  {if (is_html_output()) print_table(.) else .}
date series_id value realtime_start realtime_end
1990-01-01 UNRATE 5.4 2025-01-20 2025-01-20
1990-02-01 UNRATE 5.3 2025-01-20 2025-01-20
1990-03-01 UNRATE 5.2 2025-01-20 2025-01-20
1990-04-01 UNRATE 5.4 2025-01-20 2025-01-20
1990-05-01 UNRATE 5.4 2025-01-20 2025-01-20
1990-06-01 UNRATE 5.2 2025-01-20 2025-01-20
1990-07-01 UNRATE 5.5 2025-01-20 2025-01-20
1990-08-01 UNRATE 5.7 2025-01-20 2025-01-20
1990-09-01 UNRATE 5.9 2025-01-20 2025-01-20
1990-10-01 UNRATE 5.9 2025-01-20 2025-01-20

What are other data series for unemployment?

Code
unemp.1929.1942 <- fredr(series_id = "M0892AUSM156SNBR")
unemp.1947.1966 <- fredr(series_id = "M0892CUSM156NNBR")
unemp.1948.now <- fredr(series_id = "UNRATE")

unemp.1929.1942 %>%
  head %>%
  {if (is_html_output()) print_table(.) else .}
date series_id value realtime_start realtime_end
1929-04-01 M0892AUSM156SNBR 0.69 2025-01-26 2025-01-26
1929-05-01 M0892AUSM156SNBR 1.65 2025-01-26 2025-01-26
1929-06-01 M0892AUSM156SNBR 2.06 2025-01-26 2025-01-26
1929-07-01 M0892AUSM156SNBR 0.79 2025-01-26 2025-01-26
1929-08-01 M0892AUSM156SNBR 0.04 2025-01-26 2025-01-26
1929-09-01 M0892AUSM156SNBR 0.91 2025-01-26 2025-01-26
Code
fredr_series_search_text(search_text = "unemployment",
                         order_by = "popularity",
                         sort_order = "desc") %>%
  select(id, observation_start, title) %>%
  as.tibble %>%
  head(20) %>%
  {if (is_html_output()) print_table(.) else .}
id observation_start title
CPIAUCSL 1947-01-01 Consumer Price Index for All Urban Consumers: All Items in U.S. City Average
UNRATE 1948-01-01 Unemployment Rate
PAYEMS 1939-01-01 All Employees, Total Nonfarm
ICSA 1967-01-07 Initial Claims
SAHMREALTIME 1959-12-01 Real-time Sahm Rule Recession Indicator
CES0500000003 2006-03-01 Average Hourly Earnings of All Employees, Total Private
CCSA 1967-01-07 Continued Claims (Insured Unemployment)
LNS14000006 1972-01-01 Unemployment Rate - Black or African American
UNEMPLOY 1948-01-01 Unemployment Level
NROU 1949-01-01 Noncyclical Rate of Unemployment
WEI 2008-01-05 Weekly Economic Index (Lewis-Mertens-Stock)
U6RATE 1994-01-01 Total Unemployed, Plus All Persons Marginally Attached to the Labor Force, Plus Total Employed Part Time for Economic Reasons, as a Percent of the Civilian Labor Force Plus All Persons Marginally Attached to the Labor Force (U-6)
USSLIND 1982-01-01 Leading Index for the United States
IC4WSA 1967-01-28 4-Week Moving Average of Initial Claims
SAHMCURRENT 1949-03-01 Sahm Rule Recession Indicator
CAUR 1976-01-01 Unemployment Rate in California
USPHCI 1979-01-01 Coincident Economic Activity Index for the United States
UNRATENSA 1948-01-01 Unemployment Rate
TXUR 1976-01-01 Unemployment Rate in Texas
LNS14000024 1948-01-01 Unemployment Rate - 20 Yrs. & over
Code
fredr_series_search_text(search_text = "price index",
                         order_by = "popularity",
                         sort_order = "desc") %>%
  select(id, title) %>%
  as.tibble %>%
  head(20) %>%
  {if (is_html_output()) print_table(.) else .}
id title
CPIAUCSL Consumer Price Index for All Urban Consumers: All Items in U.S. City Average
CSUSHPINSA S&P CoreLogic Case-Shiller U.S. National Home Price Index
FPCPITOTLZGUSA Inflation, consumer prices for the United States
DFII10 Market Yield on U.S. Treasury Securities at 10-Year Constant Maturity, Quoted on an Investment Basis, Inflation-Indexed
CORESTICKM159SFRBATL Sticky Price Consumer Price Index less Food and Energy
SP500 S&P 500
CPILFESL Consumer Price Index for All Urban Consumers: All Items Less Food and Energy in U.S. City Average
CUSR0000SETA02 Consumer Price Index for All Urban Consumers: Used Cars and Trucks in U.S. City Average
PCEPI Personal Consumption Expenditures: Chain-type Price Index
PPIACO Producer Price Index by Commodity: All Commodities
CSUSHPISA S&P CoreLogic Case-Shiller U.S. National Home Price Index
PCEPILFE Personal Consumption Expenditures Excluding Food and Energy (Chain-Type Price Index)
APU0000708111 Average Price: Eggs, Grade A, Large (Cost per Dozen) in U.S. City Average
USSTHPI All-Transactions House Price Index for the United States
WPU0911 Producer Price Index by Commodity: Pulp, Paper, and Allied Products: Wood Pulp
VIXCLS CBOE Volatility Index: VIX
CUUR0000SEHA Consumer Price Index for All Urban Consumers: Rent of Primary Residence in U.S. City Average
PCU325211325211 Producer Price Index by Industry: Plastics Material and Resin Manufacturing
CPALTT01USM657N Consumer Price Index: All Items: Total for United States
GDPDEF Gross Domestic Product: Implicit Price Deflator

Integrate with tidyverse package

Code
fredr_series_search_text(search_text = "federal funds",
                         order_by = "popularity",
                         sort_order = "desc",
                         limit = 1) %>%
  pull(id) %>%
  map_dfr(., fredr) %>%
  filter(date >= as.Date("1990-01-01")) %>%
  ggplot(.) + 
  geom_line(aes(x = date, y = value/100)) +
  labs(x = "Observation Date", y = "Rate") + theme_minimal() +
  theme(legend.title = element_blank(),
        legend.position = c(0.4, 0.8)) +
  scale_x_date(breaks = as.Date(paste0(seq(1990, 2020, 2), "-01-01")),
               labels = date_format("%y")) +
  scale_y_continuous(breaks = seq(-0.01, 0.12, 0.01),
                     labels = scales::percent_format(accuracy = 1)) + 
  xlab("") + ylab("10-Year Treasury Rate")

Look for series: debt and gross domestic product

Code
fredr_series_search_text(search_text = "debt",
                         order_by = "popularity",
                         sort_order = "desc",
                         limit = 5) %>%
  as.tibble %>%
  arrange(observation_start) %>%
  select(id, title) %>%
  {if (is_html_output()) print_table(.) else .}
id title
FEDFUNDS Federal Funds Effective Rate
DFF Federal Funds Effective Rate
GFDEGDQ188S Federal Debt: Total Public Debt as Percent of Gross Domestic Product
BAMLH0A0HYM2 ICE BofA US High Yield Index Option-Adjusted Spread
RRPONTSYD Overnight Reverse Repurchase Agreements: Treasury Securities Sold by the Federal Reserve in the Temporary Open Market Operations
Code
fredr_series_search_text(search_text = "gross domestic product",
                         order_by = "popularity",
                         sort_order = "desc",
                         limit = 5) %>%
  as.tibble %>%
  arrange(observation_start) %>%
  select(id, title) %>%
  {if (is_html_output()) print_table(.) else .}
id title
PAYEMS All Employees, Total Nonfarm
GDP Gross Domestic Product
GDPC1 Real Gross Domestic Product
A939RX0Q048SBEA Real gross domestic product per capita
GFDEGDQ188S Federal Debt: Total Public Debt as Percent of Gross Domestic Product
Code
fredr_series_observations(series_id = "UNRATE",
                          observation_start = as.Date("2018-01-01"),
                          frequency = "q",
                          units = "chg") %>%
  {if (is_html_output()) print_table(.) else .}
date series_id value realtime_start realtime_end
2018-01-01 UNRATE -0.1333333 2025-01-26 2025-01-26
2018-04-01 UNRATE -0.1000000 2025-01-26 2025-01-26
2018-07-01 UNRATE -0.1666667 2025-01-26 2025-01-26
2018-10-01 UNRATE 0.0666667 2025-01-26 2025-01-26
2019-01-01 UNRATE 0.0333333 2025-01-26 2025-01-26
2019-04-01 UNRATE -0.2333333 2025-01-26 2025-01-26
2019-07-01 UNRATE -0.0333333 2025-01-26 2025-01-26
2019-10-01 UNRATE 0.0000000 2025-01-26 2025-01-26
2020-01-01 UNRATE 0.2333333 2025-01-26 2025-01-26
2020-04-01 UNRATE 9.1666667 2025-01-26 2025-01-26
2020-07-01 UNRATE -4.2000000 2025-01-26 2025-01-26
2020-10-01 UNRATE -2.0333333 2025-01-26 2025-01-26
2021-01-01 UNRATE -0.5333333 2025-01-26 2025-01-26
2021-04-01 UNRATE -0.3000000 2025-01-26 2025-01-26
2021-07-01 UNRATE -0.8666667 2025-01-26 2025-01-26
2021-10-01 UNRATE -0.8666667 2025-01-26 2025-01-26
2022-01-01 UNRATE -0.3666667 2025-01-26 2025-01-26
2022-04-01 UNRATE -0.2000000 2025-01-26 2025-01-26
2022-07-01 UNRATE -0.1000000 2025-01-26 2025-01-26
2022-10-01 UNRATE 0.0333333 2025-01-26 2025-01-26
2023-01-01 UNRATE -0.0333333 2025-01-26 2025-01-26
2023-04-01 UNRATE 0.0000000 2025-01-26 2025-01-26
2023-07-01 UNRATE 0.1333333 2025-01-26 2025-01-26
2023-10-01 UNRATE 0.1333333 2025-01-26 2025-01-26
2024-01-01 UNRATE 0.0333333 2025-01-26 2025-01-26
2024-04-01 UNRATE 0.1666667 2025-01-26 2025-01-26
2024-07-01 UNRATE 0.1666667 2025-01-26 2025-01-26
2024-10-01 UNRATE -0.0333333 2025-01-26 2025-01-26

Integrate the purrr package

This is how to create a wide database with various FRED Databases:

Code
map_dfr(c("FEDFUNDS", "UNRATE"), fredr) %>%
  spread(series_id, value) %>%
  top_n(10) %>%
  {if (is_html_output()) print_table(.) else .}
date realtime_start realtime_end FEDFUNDS UNRATE
1982-10-01 2025-01-10 2025-01-10 NA 10.4
1982-11-01 2025-01-10 2025-01-10 NA 10.8
1982-12-01 2025-01-10 2025-01-10 NA 10.8
1983-01-01 2025-01-10 2025-01-10 NA 10.4
1983-02-01 2025-01-10 2025-01-10 NA 10.4
1983-03-01 2025-01-10 2025-01-10 NA 10.3
1983-04-01 2025-01-10 2025-01-10 NA 10.2
2020-04-01 2025-01-10 2025-01-10 NA 14.8
2020-05-01 2025-01-10 2025-01-10 NA 13.2
2020-06-01 2025-01-10 2025-01-10 NA 11.0
2020-07-01 2025-01-10 2025-01-10 NA 10.2

This is how to map them:

Code
map_dfr(c("UNRATE", "FEDFUNDS"), fredr) %>%
  ggplot(.) + theme_minimal() + 
  geom_line(aes(x = date, y = value/100, color = series_id)) +
  labs(x = "Observation Date", y = "Rate", linetype = "Series") +
  scale_color_manual(values = viridis(3)[1:2]) +
  theme(legend.title = element_blank(),
        legend.position = c(0.3, 0.8)) +
  scale_x_date(breaks = as.Date(paste0(seq(1920, 2020, 5), "-01-01")),
               labels = date_format("%y")) +
  scale_y_continuous(breaks = seq(-0.01, 0.3, 0.02),
                     labels = scales::percent_format(accuracy = 1)) + 
  xlab("") + ylab("") + theme(legend.title = element_blank())

Code
params <- list(series_id = c("UNRATE", "OILPRICE"),
               frequency = c("m", "q"))

pmap_dfr(.l = params,
         .f = ~ fredr(series_id = .x, frequency = .y)) %>%
  head(10) %>%
  {if (is_html_output()) print_table(.) else .}
date series_id value realtime_start realtime_end
1948-01-01 UNRATE 3.4 2025-01-11 2025-01-11
1948-02-01 UNRATE 3.8 2025-01-11 2025-01-11
1948-03-01 UNRATE 4.0 2025-01-11 2025-01-11
1948-04-01 UNRATE 3.9 2025-01-11 2025-01-11
1948-05-01 UNRATE 3.5 2025-01-11 2025-01-11
1948-06-01 UNRATE 3.6 2025-01-11 2025-01-11
1948-07-01 UNRATE 3.6 2025-01-11 2025-01-11
1948-08-01 UNRATE 3.9 2025-01-11 2025-01-11
1948-09-01 UNRATE 3.8 2025-01-11 2025-01-11
1948-10-01 UNRATE 3.7 2025-01-11 2025-01-11

Household Debt Service Payments as a Percent of Disposable Income

Code
map_dfr(c("TDSP"), fredr) %>%
  ggplot(data = ., mapping = aes(x = date, y = value/100)) +
  geom_line() + theme_minimal() +
  labs(x = "Observation Date", y = "Rate", color = "Series") +
  theme(legend.title = element_blank(),
        legend.position = c(0.4, 0.8)) +
  scale_x_date(breaks = as.Date(paste0(seq(1970, 2020, 5), "-01-01")),
               labels = date_format("%y")) +
  scale_y_continuous(breaks = seq(-0.01, 0.30, 0.01),
                     labels = scales::percent_format(accuracy = 1)) + 
  xlab("") + ylab("") + theme(legend.title = element_blank())

Nominal and Real Oil Prices

Oil Prices and Price Index

Data from FRED - Federal Reserve Bank of St. Louis:

  • CPIAUCSL: Consumer Price Index for All Urban Consumers: All Items. Available at: https://fred.stlouisfed.org/series/CPIAUCSL

  • WTISPLC: Spot Crude Oil Price: West Texas Intermediate (WTI). Available at: https://fred.stlouisfed.org/series/WTISPLC

Code
map_dfr(c("CPIAUCSL", "WTISPLC"), fredr) %>%
  ggplot(data = ., mapping = aes(x = date, y = value, linetype = series_id)) +
  geom_line() +
  labs(x = "Observation Date", y = "Rate", color = "Series") +
  theme_minimal() + xlab("") + ylab("") + theme(legend.title = element_blank())

Real Oil Prices

Code
map_dfr(c("CPIAUCSL", "WTISPLC"), fredr) %>%
  spread(series_id, value) %>%
  # Current House Prices from August 2018
  na.omit %>%
  mutate(WTISPLC_real = CPIAUCSL[860]* WTISPLC / CPIAUCSL) %>%
  select(-CPIAUCSL) %>%
  gather(series_id, value, -date) %>%
  ggplot(data = ., mapping = aes(x = date, y = value, linetype = series_id)) +
  geom_line() + labs(x = "Observation Date", y = "Rate", color = "Series") +
  theme_minimal() + xlab("") + ylab("") + theme(legend.title = element_blank())

Passenger car registration

Code
fredr_series_search_text(search_text = "Passenger Car Registrations",
                         order_by = "popularity",
                         sort_order = "desc",
                         limit = 5) %>%
  as.tibble %>%
  select(observation_start, id, title, everything()) %>%
  arrange(observation_start) %>%
  select(2, 3, frequency) %>%
  {if (is_html_output()) print_table(.) else .}
id title frequency
A01108USA258NNBR Automobile Registrations, Passenger Cars, Total for United States Annual, End of Year
M01109USM543NNBR New Passenger Car Registrations for United States Monthly
USASACRMISMEI Production, Sales, Work Started and Orders: Passenger Car Registrations: Economic Activity: Wholesale and Retail Trade and Repair of Motor Vehicles and Motorcycles for United States Monthly
USASLRTCR03MLSAM Sales: Retail Trade: Car Registration: Passenger Cars for United States Monthly
INDSLRTCR03MLSAM Sales: Retail Trade: Car Registration: Passenger Cars for India Monthly
Code
map_dfr(c("USASACRQISMEI"), fredr) %>%
  spread(series_id, value) %>%
  na.omit %>%
  # Current House Prices from August 2018
  gather(series_id, value, -date) %>%
  ggplot(data = ., mapping = aes(x = date, y = value)) +
  geom_line() + 
  scale_y_continuous(breaks = seq(80, 220, 20)) + xlab("") + ylab("") +
  theme_minimal() + theme(legend.title = element_blank())