FRED Categories

knitr::opts_chunk$set(
  fig.width = 7,
  fig.height = 5,
  eval = !(Sys.getenv("FRED_API_KEY") == ""),
  cache = TRUE,
  collapse = TRUE,
  comment = "#>"
)
library(fredr)
options(digits = 4)

Introduction

This vignette is intended to introduce the user to fredr functions for the Categories endpoint of the FRED API.

FRED series are assigned categories. Each FRED category is assigned an integer identifier. For example:

Categories are organized in a hierarchical structure where parent categories contain children categories. All categories are children of the root category (category_id = 0). The following examples illustrate usage of the Categories endpoint functions in fredr.

Get a FRED category

fredr_category() returns minimal information for a single category specified by category_id. The data returned is a tibble in which each row represents a category. The default is the root category.

fredr_category() 
fredr_category(category_id = 97L)

Get the children of a FRED category

fredr_category_children() returns minimal information (child ID, name, and parent ID) for all child categories of the parent category specified by category_id. The data returned is a tibble in which each row represents child category of the parent specified. The default is the root category.

fredr_category_children()
fredr_category_children(category_id = 1L)

Get a related FRED category

fredr_category_related() returns minimal information (ID, name, and parent ID) for all related categories to the category specified by category_id. The data returned is a tibble in which each row represents category related to the one specified. Note that not all categories have related categories. The default is the root category.

fredr_category_related()
fredr_category_related(category_id = 4L) # Employment Cost Index

Get series in a category

fredr_category_series() returns detailed information for the FRED series belonging to the category specified by category_id. The data returned is a tibble in which each row represents a series belonging to the category specified. The default is the root category. For example, to get the top 100 quarterly series in the "Housing" category, ordering the results so that the most recently updated series appear first:

fredr_category_series(
  category_id = 97L, # Housing
  limit = 100L,
  order_by = "last_updated",
  filter_variable = "frequency",
  filter_value = "Quarterly"
)

To return all series in the "National Accounts" tagged with "usa" and not "gnp", ordering the results such that higher frequency series appear first:

fredr_category_series(
  category_id = 32992L, # National Accounts
  order_by = "frequency",
  sort_order = "desc",
  tag_names = "usa",
  exclude_tag_names = "gnp"
)

Get tags within a FRED category

fredr_category_tags() returns information for the FRED tags assigned to series in the category specified by category_id. The data returned is a tibble in which each row represents a tag assigned to a series in the category specified. The default is the root category. For example, to get all "source" tags belonging to series in the "Retail Trade" category:

fredr_category_tags(
  category_id = 6L,
  tag_group_id = "src"
)

To search for tags with the words "usa" in the "Production & Business Activity" category, ordering the results by popularity:

fredr_category_tags(
  category_id = 1L,
  search_text = "usa",
  order_by = "popularity",
  sort_order = "desc"
)

Get related tags within a FRED category

fredr_category_related_tags() returns a set of FRED tags assigned to series in the category specified by category_id that are related to the tags specified in the tag_names parameter. The data returned is a tibble in which each row represents a tag related to a tag assigned to a series in the specified category. The default is the root category. For example, to get all tags except "rate" in the "Retail Trade" category related to the tags "business" and "monthly", ordering the results alphabetically:

fredr_category_related_tags(
  category_id = 1L,
  tag_names = "business;monthly",
  exclude_tag_names = "rate",
  order_by = "name"
)


Try the fredr package in your browser

Any scripts or data that you put into this service are public.

fredr documentation built on May 2, 2019, 7:29 a.m.