fred_transform: FRED transformation and subset helper

View source: R/85_transform.R

fred_transformR Documentation

FRED transformation and subset helper

Description

Apply transformations given by FRED-MD or FRED-QD and generate rectangular subsets. See fred_qd for information on data and the Details section for information on the transformations. Call without arguments to retrieve available codes / all FRED suggestions.

Usage

fred_transform(
  data,
  type = c("fred_qd", "fred_md"),
  codes,
  na.rm = TRUE,
  lag = 1L,
  scale = 100
)

fred_code(vars, type = c("fred_qd", "fred_md"), table = FALSE)

Arguments

data

A data.frame with FRED-QD or FRED-MD time series. The column names are used to find the correct transformation.

type

Character scalar. Whether data stems from the FRED-QD or the FRED-MD database.

codes

Integer vector. Transformation code(s) to apply to data. Overrides automatic lookup of transformation codes.

na.rm

Logical scalar. Whether to subset to rows without any NA values. A warning is thrown if rows are non-sequential.

lag

Integer scalar. Number of lags to apply when taking differences. See diff.

scale

Numeric scalar. Scaling to apply to log differences.

vars

Character vector. Names of the variables to look for.

table

Logical scalar. Whether to return a table of matching transformation codes instead of just the codes.

Details

FRED-QD and FRED-MD include a transformation code for every variable. All codes are provided in system.file("fred_trans.csv", package = "BVAR"). The transformation codes are as follows:

  1. 1 - no transformation;

  2. 2 - first differences - \Delta x_t;

  3. 3 - second differences - \Delta^2 x_t;

  4. 4 - log transformation - \log x_t;

  5. 5 - log differences - \Delta \log x_t;

  6. 6 - log second differences - \Delta^2 \log x_t;

  7. 7 - percent change differences - \Delta x_t / x_{t-1} - 1;

Note that the transformation codes of FRED-MD and FRED-QD may differ for the same series.

Value

fred_transform returns a data.frame object with applied transformations. fred_code returns transformation codes, or a data.frame of matching transformation codes.

See Also

fred_qd

Examples

# Transform a subset of FRED-QD
fred_transform(fred_qd[, c("GDPC1", "INDPRO", "FEDFUNDS")])

# Get info on transformation codes for unemployment variables
fred_code("UNRATE", table = TRUE)

# Get the transformation code for GDPC1
fred_code("GDPC1", type = "fred_qd")

# Transform all of FRED-MD
## Not run: 
fred_transform(fred_md, type = "fred_md")

## End(Not run)

BVAR documentation built on May 29, 2024, 5:34 a.m.