Skip to contents

Returns a suitably transformed, lagged and/or differenced data. Inspired by the GAUSS procs originally written by Mark Watson.

Usage

transform_series(
  y,
  take_log = FALSE,
  dcode = c("nd", "d1", "d4", "d12"),
  pcode = c("np", "p1", "p4", "p12")
)

Arguments

y

numeric vector, input time series, eg class ts

take_log

logical, take the natural logarithm? Default is no (FALSE)

dcode

character option to specify how y is differenced:

  • "nd", No difference, i.e., level, default

  • "d1", 1st Difference, i.e., (1 - B)y

  • "d4", 4th Difference, i.e., (1 - B^4)y, use with quarterly data

  • "d12", 12th Difference, i.e., (1 - B^12)y, use with monthly data

pcode

character, option to specify if percentages are computed:

  • "np", no change, default

  • "p1", multiply by 100

  • "p4", multiply by 400, eg. for annualized quarterly rate

  • "p12", multiply by 1200, eg. for annualized monthly rate

Value

A vector transformed, if class x is class ts, class ts

Examples

data(usdata)
head(transform_series(usdata$GDPC1, TRUE, "d4", "p4"))
#>           [,1]
#> [1,] 11.213782
#> [2,] 18.130664
#> [3,] 20.774190
#> [4,] 14.936670
#> [5,]  3.602726
#> [6,] -4.196225