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 |
A vector containing ISO country codes used in the Penn World Table.
countries
countries
Character vector of length 182
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/
A vector containing ISO 2-digit country codes.
country2
country2
Character vector of length 249
https://en.wikipedia.org/wiki/ISO_3166
A vector containing ISO 3-digit country codes.
country3
country3
Character vector of length 249
https://en.wikipedia.org/wiki/ISO_3166
Function that fetches economic data from the FRED based on the series ids.
fred( ..., key = NULL, all = TRUE, info = TRUE, realtime_start = NULL, realtime_end = NULL, long = FALSE )
fred( ..., key = NULL, all = TRUE, info = TRUE, realtime_start = NULL, realtime_end = NULL, long = FALSE )
... |
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 |
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 |
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 |
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.
data.frame
## 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)
## 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)
Each of the functions accept a category ID and return the requested information in a data.frame.
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())
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())
... |
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 |
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
data.frame with entries described in details
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
## 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)
## 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)
Function that fetches data series with related codes and places the results into a long data.frame.
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 )
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 )
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? |
key |
32 character lower-cased alpha-numeric character string |
name |
character string describing the name of the value column. If |
grp_name |
character string describing the name of the group column. Defaults to |
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. |
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"
.
data.frame
fred_state
: Fetch data across each state
## 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)
## 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)
Each of the functions accept a release name/number and return the requested information in a data.frame.
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())
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())
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 |
... |
character or numeric vectors of release ids to search |
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
data.frame with entries described in details
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
Each function receives a character string and returns a data.frame containing information on different series, tags, or related tags of the search.
fred_search(text, key = NULL, args = list()) fred_search_tags(text, key = NULL, args = list()) fred_search_related_tags(text, key = NULL, args = list())
fred_search(text, key = NULL, args = list()) fred_search_tags(text, key = NULL, args = list()) fred_search_related_tags(text, key = NULL, args = list())
text |
character string used for search. All spaces will automatically be converted appropriately. |
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 details below. |
Search arguments accept any of the following:
search_type
either "full_text"
or "series_id"
determining whether the description, title, units, and other information are searched or only the id. Defaults to full text.
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
order_by
One of the following: "search_rank"
, "series_id"
, "title"
, "units"
, "frequency"
, "seasonal_adjustment"
, "realtime_start"
, "realtime_end"
, "last_updated"
, "observation_start"
, "observation_end"
, "popularity"
, or "group_popularity"
. Default is "search_rank"
.
sort_order
Either "asc"
for ascending or "desc"
for descending order.
filter_variable
String to filter the results by.
tag_names
String of tag names separated by semicolons for filtering results.
exclude_tag_names
String of tag names separated by semicolons that should not be included.
These should be included in a list such as args = list(limit = 10, sort_order = "asc")
.
The results are included in a data.frame with all information about the series,
including detailed notes. The results are best viewed in the RStudio Viewer or
with the title extracted.
Each function returns the following information in a data.frame.
fred_search
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_search_tags
Tag name and its group id, popularity of tag, number of series in each tag, when it was created, and other notes
fred_search_related_tags
Same as fred_search_tags
data.frame with entries described in details
fred_search
: obtain series related to search
fred_search_tags
: obtain tags related to search
fred_search_related_tags
: obtain related tags related to search
## Not run: api_key <- "abcdefghijklmnopqrstuvwxyz123456" # Searching GDP in China, descending order by "title" results <- fred_search("GDP China", key=api_key, args = list(sort_order="desc", order_by="title")) # Fetch top 2 series df <- fred(results$id[1:2]) head(df) ## End(Not run)
## Not run: api_key <- "abcdefghijklmnopqrstuvwxyz123456" # Searching GDP in China, descending order by "title" results <- fred_search("GDP China", key=api_key, args = list(sort_order="desc", order_by="title")) # Fetch top 2 series df <- fred(results$id[1:2]) head(df) ## End(Not run)
Each of the functions accept a series ID from FRED and return a data.frame with information about the series.
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 )
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 )
... |
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 |
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
data.frame or list
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.
Each of the functions accept a source number and return the requested information in a data.frame.
fred_sources(key = NULL, args = list()) fred_source(..., key = NULL, args = list()) fred_source_releases(..., key = NULL, args = list())
fred_sources(key = NULL, args = list()) fred_source(..., key = NULL, args = list()) fred_source_releases(..., key = NULL, args = list())
key |
32 character lower-cased alpha-numeric character string |
args |
named list of other arguments passed to the API, mostly for |
... |
character or numeric vectors of release ids to search |
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
data.frame with entries described in details
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
Each of the functions accept a tag name and return the requested information in a data.frame.
fred_tags(key = NULL, args = list()) fred_related_tags(..., key = NULL, args = list()) fred_tags_series(..., key = NULL, args = list())
fred_tags(key = NULL, args = list()) fred_related_tags(..., key = NULL, args = list()) fred_tags_series(..., key = NULL, args = list())
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 |
... |
character vectors of tag names to search |
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
data.frame with entries described in details
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
Function that returns a data.frame containing information on series in FRED that were recently updated.
fred_updates(key = NULL, args = list())
fred_updates(key = NULL, args = list())
key |
32 character lower-cased alpha-numeric character string |
args |
named list of other arguments passed to the API. See 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
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
The function replaces spaces from character vectors with "+"
and separates
search terms with ";"
. Use whenever search terms are needed in the args
list for API calls. It is automatically applied for fred_search
and not needed.
parse_search(...)
parse_search(...)
... |
character vectors of search terms |
character string
terms <- c("Real GDP", "medical inflation", "Japan") parse_search(terms, "unemployment")
terms <- c("Real GDP", "medical inflation", "Japan") parse_search(terms, "unemployment")
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.
releases
releases
data.frame with 292 observations and 7 variables:
release id
date releases were saved
name of the release
logical value for whether there is an associated press release
a url for more data
character string containing information about the release
https://fred.stlouisfed.org/docs/api/fred/releases.html
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.
set_fred_key(key)
set_fred_key(key)
key |
32 character lower-cased alpha-numeric character string |
NULL
set_fred_key("abcdefghijklmnopqrstuvwxyz123456")
set_fred_key("abcdefghijklmnopqrstuvwxyz123456")
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.
sources
sources
data.frame with 102 observations and 6 variables:
source id
date releases were saved
name of the source
a url that links to the source's website
character string containing information about the source
https://fred.stlouisfed.org/docs/api/fred/sources.html
A vector containing U.S. state abbreviations, including the District of Columbia.
states
states
Character vector of length 51
https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations
A vector containing abbreviations of U.S. states and territories.
states_extended
states_extended
Character vector of length 51
https://en.wikipedia.org/wiki/List_of_U.S._state_and_territory_abbreviations
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.
tags
tags
data.frame with 1000 observations and 6 variables:
tag name
name of the group associated with the tag
when the tag was created
integer of the tag's popularity (up to 100)
character string containing information about the source
number of series associated with the tag
https://fred.stlouisfed.org/docs/api/fred/tags.html