Package 'eFRED'

Title: Fetch Data from the Federal Reserve Economic Database
Description: Interact with the FRED API, <https://fred.stlouisfed.org/docs/api/fred/>, to fetch observations across economic series; find information about different economic sources, releases, series, etc.; conduct searches by series name, attributes, or tags; and determine the latest updates. Includes functions for creating panels of related variables with minimal effort and datasets containing data sources, releases, and popular FRED tags.
Authors: Chris Mann <[email protected]>
Maintainer: Chris Mann <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2025-03-03 02:47:16 UTC
Source: https://github.com/cran/eFRED

Help Index


Country Codes

Description

A vector containing ISO country codes used in the Penn World Table.

Usage

countries

Format

Character vector of length 182

Source

Feenstra, Robert C., Robert Inklaar and Marcel P. Timmer (2015), "The Next Generation of the Penn World Table", American Economic Review, 105(10), 3150-3182, available for download at https://www.rug.nl/ggdc/productivity/pwt/


Country Codes

Description

A vector containing ISO 2-digit country codes.

Usage

country2

Format

Character vector of length 249

Source

https://en.wikipedia.org/wiki/ISO_3166


Country Codes

Description

A vector containing ISO 3-digit country codes.

Usage

country3

Format

Character vector of length 249

Source

https://en.wikipedia.org/wiki/ISO_3166


Fetch Data Series from FRED

Description

Function that fetches economic data from the FRED based on the series ids.

Usage

fred(
  ...,
  key = NULL,
  all = TRUE,
  info = TRUE,
  realtime_start = NULL,
  realtime_end = NULL,
  long = FALSE
)

Arguments

...

character vectors of series ids to search. Any names will be used to label the series in the resulting data.frame

key

32 character lower-cased alpha-numeric character string

all

logical; should all observations be used? Defaults to TRUE. If FALSE, only observations existing in all series will be kept.

info

logical; should information about each series, such as units and title, be kept? If so, the information will be stored in a data.frame under the attribute "info".

realtime_start, realtime_end

character date strings of format "YYY-MM-DD" used obtain information that was known during the specified time period. If empty, the latest update of the information is used.

long

logical; should the resulting data.frame be long or wide? Defaults to FALSE so that a new column is created for each series

Details

The fred function search for series ids from the FRED and returns the values in a data.frame. Unless long=TRUE, a new column will be created for each series. The dates for each observation will be included in the "date" column and will be of class "Date". Each series will be a numeric value.

If a series cannot be found, then it will be skipped and R will issue a warning.

To access ALFRED, or the archived Federal Reserve Economic Data, use the realtime_start and realtime_end arguments to specify a time frame. More details about real time periods can be found at https://fred.stlouisfed.org/docs/api/fred/realtime_period.html.

Value

data.frame

Examples

## Not run: 
api_key <- "abcdefghijklmnopqrstuvwxyz123456"

# Naive Phillips Curve Estimation
df <- fred(p = "CPIAUCSL", u = "u6rate", key=api_key)
head(df)

df$pi  <- log(df$p) - log(c(NA, df$p[2:nrow(df)]))
reg_pc <- lm(pi ~ u, data = df)
summary(reg_pc)

# Different variations of the CPI
cpis <- c("CPIMEDSL", "CPIFABSL", "CPIHOSSL")
names(cpis) <- c("P_Med", "P_Food", "P_House")

df_cpi <- fred(cpis, key=api_key, long=TRUE)
head(df)

## End(Not run)

Fetch Information on a Category in FRED

Description

Each of the functions accept a category ID and return the requested information in a data.frame.

Usage

fred_category(..., key = NULL)

fred_category_children(
  ...,
  key = NULL,
  realtime_start = NULL,
  realtime_end = NULL
)

fred_category_related(
  ...,
  key = NULL,
  realtime_start = NULL,
  realtime_end = NULL
)

fred_category_series(..., key = NULL, args = list())

fred_category_tags(..., key = NULL, args = list())

fred_category_related_tags(..., key = NULL, args = list())

Arguments

...

character or numeric vectors of a category ID to fetch. Names are ignored.

key

32 character lower-cased alpha-numeric character string

realtime_start, realtime_end

character date strings of format "YYY-MM-DD" used obtain information that was known during the specified time period. If empty, the latest update of the information is used.

args

named list of other arguments passed to the API, including "limit", "offset", "sort_order", etc. See fred_search for more details on accepted parameters.

Details

Each function returns the following information in a data.frame.

fred_category

Category id, its name, and the id of its parent

fred_category_children

Same as fred_category

fred_category_related

Same as fred_category

fred_category_series

Series id, its title, observations start and end, frequency, units, seasonal adjustment type, popularity, realtime start and end, and when it was last updated

fred_category_tags

Tag name and its group id, popularity of tag, number of series in each tag, when it was created, and other notes

fred_category_related_tags

Same as fred_category_tags

Value

data.frame with entries described in details

Functions

  • fred_category: get the name and parent_id for a FRED category

  • fred_category_children: get the category children ids of a given parent_id

  • fred_category_related: get the categories that are related to a category id

  • fred_category_series: get all series within a particular category

  • fred_category_tags: get all tags associated with a particular category

  • fred_category_related_tags: get all tags related to tags within a particular category

Examples

## Not run: 
api_key <- "abcdefghijklmnopqrstuvwxyz123456"

# What category is the unemployment rate in?
un_cat <- fred_category("UNRATE", key=api_key)

# What other series are in the same category?
other_in_cat <- fred_category_series(un_cat$id, key=api_key)
head(other_in_cat)

## End(Not run)

Fetch and Create a Panel of Data

Description

Function that fetches data series with related codes and places the results into a long data.frame.

Usage

fred_group(
  id,
  groups,
  type = c("prefix", "postfix", "infix"),
  key = NULL,
  name = NULL,
  grp_name = "group",
  realtime_start = NULL,
  realtime_end = NULL
)

fred_state(
  id,
  type = c("prefix", "postfix", "infix"),
  key = NULL,
  name = NULL,
  realtime_start = NULL,
  realtime_end = NULL
)

Arguments

id

character string containing the common series id segment

groups

character vector denoting the variation in the series

type

how should the group vectors be combined with the id? "prefix" places the groups before the id, "postfix" after the id, and use "infix" to place the group code between values in id *(requires id to be a length 2 character vector)*

key

32 character lower-cased alpha-numeric character string

name

character string describing the name of the value column. If NULL, the id will be used.

grp_name

character string describing the name of the group column. Defaults to "group".

realtime_start, realtime_end

character date strings of format "YYY-MM-DD" used obtain information that was known during the specified time period. If empty, the latest update of the information is used.

Details

The fred_group command is convenience function that searches for many different series at once and places them in a panel. This is similar to the fred command except that it can be more convenient when the series are related to each other. For example, the statewide unemployment rates from the Bureau of Labor Statistics have all codes with the format: "<State Abbreviation><UR>". If state abbreviations are located in variable state.abb, then the command fred_group("UR", state.abb, "prefix", key) would search place all unemployment rates into a data.frame.

fred_state is a wrapper around fred_group with the state abbreviations used for groups and with the group column "state".

Value

data.frame

Functions

  • fred_state: Fetch data across each state

Examples

## Not run: 
api_key <- "abcdefghijklmnopqrstuvwxyz123456"

# Panel of Unemployment Rates Across States
unemploy <- fred_state("UR", key = api_key)
unemploy

# Panel of Constant GDP per Capita by Country
GDP <- fred_group("NYGDPPCAPKD", eFRED::countries, type="postfix",
  key=api_key, name= "gdppc", grp_name="country")
GDP

## End(Not run)

Fetch Information on a Release in FRED

Description

Each of the functions accept a release name/number and return the requested information in a data.frame.

Usage

fred_releases(key = NULL, args = list())

fred_releases_dates(key = NULL, args = list())

fred_release(..., key = NULL, args = list())

fred_release_dates(..., key = NULL, args = list())

fred_release_series(..., key = NULL, args = list())

fred_release_sources(..., key = NULL, args = list())

fred_release_tags(..., key = NULL, args = list())

fred_release_related_tags(..., key = NULL, args = list())

fred_release_tables(..., key = NULL, args = list())

Arguments

key

32 character lower-cased alpha-numeric character string

args

named list of other arguments passed to the API, including "limit", "offset", "sort_order", etc. See fred_search for more details on accepted parameters.

...

character or numeric vectors of release ids to search

Details

Each function returns the following information in a data.frame.

fred_releases

Release id, its name, a url link, whether there is a press release, and realtime start and end dates

fred_releases_dates

Release id, its name, and date of release

fred_release

Release id, its name, a url link, whether there is a press release, and realtime start and end dates

fred_release_dates

Release id and its release date

fred_release_series

Series id, its title, observations start and end, frequency, units, seasonal adjustment type, popularity, realtime start and end, and when it was last updated

fred_release_sources

Source id, name of source, url link, and realtime start and end dates

fred_release_tags

Tag name and its group id, popularity of tag, number of series in each tag, when it was created, and other notes

fred_release_related_tags

Same as fred_release_tags

fred_release_tables

Release, element, parent, and series ids, type, and name

Value

data.frame with entries described in details

Functions

  • fred_releases: get all releases of economic data

  • fred_releases_dates: get the dates of all economic releases

  • fred_release: get information about a particular release

  • fred_release_dates: get release dates for a particular release

  • fred_release_series: get all series associated with a particular release

  • fred_release_sources: get the sources associated with a particular release

  • fred_release_tags: get all tags associated with a particular release

  • fred_release_related_tags: get all related tags associated with a particular release

  • fred_release_tables: get the release tables for a particular release


Fetch Data or Information on a SERIES in FRED

Description

Each of the functions accept a series ID from FRED and return a data.frame with information about the series.

Usage

fred_series(..., key = NULL, realtime_start = NULL, realtime_end = NULL)

fred_series_release(
  ...,
  key = NULL,
  realtime_start = NULL,
  realtime_end = NULL
)

fred_series_categories(
  ...,
  key = NULL,
  realtime_start = NULL,
  realtime_end = NULL
)

fred_series_tags(..., key = NULL, realtime_start = NULL, realtime_end = NULL)

fred_observations(
  ...,
  key = NULL,
  realtime_start = NULL,
  realtime_end = NULL,
  all = TRUE
)

fred_series_vintage(
  ...,
  key = NULL,
  realtime_start = NULL,
  realtime_end = NULL
)

Arguments

...

character vectors of series to fetch. If named, then the names are used to identify the series in the result.

key

32 character lower-cased alpha-numeric character string

realtime_start, realtime_end

character date strings of format "YYY-MM-DD" used obtain information that was known during the specified time period. If empty, the latest update of the information is used.

all

logical; should all observations be used? Defaults to TRUE. If FALSE, only observations existing in all series will be kept.

Details

Each function returns the following information in a data.frame.

fred_observations

Date of observation, its value, and the realtime start and end dates

fred_series

Series id, its title, observations start and end, frequency, units, seasonal adjustment type, popularity, realtime start and end, and when it was last updated

fred_series_categories

Category id, its name, and the id of its parent

fred_series_release

Release id, its name, a url link, whether there is a press release, and realtime start and end dates

fred_series_tags

Tag name, its group id, popularity, the number of series that are tagged, when it was created, and any notes about the tag

fred_series_related_tags

Same as fred_series_tags

fred_series_vintage

dates of each vintage

fred_category_related_tags

Same as fred_category_tags

Value

data.frame or list

Functions

  • fred_series: get information about the series including observation periods, seasonal adjustment, units, title, etc.

  • fred_series_release: get the release information about the series

  • fred_series_categories: get the categories into which a series falls

  • fred_series_tags: get the FRED tags for the series

  • fred_observations: get the observational data for a series

  • fred_series_vintage: get the dates in which the data for the series were revised or released. Returns a named list of dates.


Fetch Information on a Data Source in FRED

Description

Each of the functions accept a source number and return the requested information in a data.frame.

Usage

fred_sources(key = NULL, args = list())

fred_source(..., key = NULL, args = list())

fred_source_releases(..., key = NULL, args = list())

Arguments

key

32 character lower-cased alpha-numeric character string

args

named list of other arguments passed to the API, mostly for fred_source_releases, including "limit", "offset", "sort_order", etc. See fred_search for more details on accepted parameters.

...

character or numeric vectors of release ids to search

Details

Each function returns the following information in a data.frame.

fred_sources

Source id, its name, a url link, and realtime start and end dates

fred_source

Same as fred_sources

fred_source_releases

Release id, its name, a url link, whether there is a press release, and realtime start and end dates

Value

data.frame with entries described in details

Functions

  • fred_sources: get all sources of economic data

  • fred_source: get information about a particular source

  • fred_source_releases: get releases by a particular source


Fetch Information on a Tag in FRED

Description

Each of the functions accept a tag name and return the requested information in a data.frame.

Usage

fred_tags(key = NULL, args = list())

fred_related_tags(..., key = NULL, args = list())

fred_tags_series(..., key = NULL, args = list())

Arguments

key

32 character lower-cased alpha-numeric character string

args

named list of other arguments passed to the API, including "limit", "offset", "sort_order", etc. See fred_search for more details on accepted parameters.

...

character vectors of tag names to search

Details

Each function returns the following information in a data.frame.

fred_tags

Tag name, its group id, popularity, the number of series that are tagged, when it was created, and any notes about the tag

fred_related_tags

Same as fred_tags

fred_tags_series

Series id, its title, observations start and end, frequency, units, seasonal adjustment type, popularity, realtime start and end, and when it was last updated

Value

data.frame with entries described in details

Functions

  • fred_tags: get the tag names associated with the search parameters

  • fred_related_tags: get the tags that are related to one or more tag names

  • fred_tags_series: get the series associated with tags


Fetch Series with Recent Updates

Description

Function that returns a data.frame containing information on series in FRED that were recently updated.

Usage

fred_updates(key = NULL, args = list())

Arguments

key

32 character lower-cased alpha-numeric character string

args

named list of other arguments passed to the API. See details.

Details

Arguments accept any of the following:

realtime_start, realtime_end

character string of format "YYYY-MM-DD" determining the real-time period. This is used to find historical series.

limit

integer between 1 and 1000 determining the maximum number of results to return.

offset

Non-negative integer

filter_value

Either "macro", "regional", or "all" *(the default)* describing the geographic type of the series

start_time, end_time

character string of format "YYYYMMDDHhmm" determining the time range, down to minutes, with which to filter the results

Value

data.frame with values for the series id, its title, start and end date of its observations, its frequency, units, whether it is seasonally adjusted, its popularity, when it was last updated, and the realtime start and end dates


Economic Releases

Description

A data.frame containing information on the economic releases in FRED. Information is from January 2021. Use fred_releases for an up-to-date version.

Usage

releases

Format

data.frame with 292 observations and 7 variables:

id

release id

realtime_start, realtime_end

date releases were saved

name

name of the release

press_release

logical value for whether there is an associated press release

link

a url for more data

notes

character string containing information about the release

Source

https://fred.stlouisfed.org/docs/api/fred/releases.html


Set a FRED API Key

Description

Function used to set the default key. If included, then key arguments in FRED API calls are no longer needed. API keys can be requested at https://fred.stlouisfed.org/docs/api/api_key.html.

Usage

set_fred_key(key)

Arguments

key

32 character lower-cased alpha-numeric character string

Value

NULL

Examples

set_fred_key("abcdefghijklmnopqrstuvwxyz123456")

Sources of Economic Data

Description

A data.frame containing information on the sources of data in FRED. Information is from January 2021. Use fred_sources for an up-to-date version.

Usage

sources

Format

data.frame with 102 observations and 6 variables:

id

source id

realtime_start, realtime_end

date releases were saved

name

name of the source

link

a url that links to the source's website

notes

character string containing information about the source

Source

https://fred.stlouisfed.org/docs/api/fred/sources.html


U.S. State Abbreviations

Description

A vector containing U.S. state abbreviations, including the District of Columbia.

Usage

states

Format

Character vector of length 51

Source

https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations


Extended State Abbreviations

Description

A vector containing abbreviations of U.S. states and territories.

Usage

states_extended

Format

Character vector of length 51

Source

https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations


Popular Tags

Description

A data.frame containing information on 1000 of the most common tags in FRED. Information is from January 2021. Use fred_tags for an up-to-date version and the ability to refine it further.

Usage

tags

Format

data.frame with 1000 observations and 6 variables:

name

tag name

group_id

name of the group associated with the tag

created

when the tag was created

popularity

integer of the tag's popularity (up to 100)

notes

character string containing information about the source

series_count

number of series associated with the tag

Source

https://fred.stlouisfed.org/docs/api/fred/tags.html