chaining | R Documentation |
Function unchain()
unchains a chained index series.
These unchained index series can be aggregated into higher-level indices using aggregate()
.
To obtain a long-term index series, the higher-level indices must be chained using function chain()
.
Function rebase()
sets the index reference period.
Monthly indices can be converted into quarterly and yearly indices or 12-month moving averages using function convert()
.
unchain(x, t, by=12, settings=list())
chain(x, t, by=12, settings=list())
rebase(x, t, t.ref="first", settings=list())
convert(x, t, type="year", settings=list())
x |
numeric vector of index values. |
t |
date vector in format |
by |
for one-month or one-quarter overlap a single integer between 1 and 12 specifying the price reference period; for annual overlap using a full calendar year |
t.ref |
character specifying the index reference period either in format |
type |
type of converted index. Either |
settings |
list of control settings to be used. The following settings are supported:
|
Function unchain()
sets the value of the first price reference period to NA
although the value could be set to 100 (if by
is not NULL
) or 100 divided by the average of the year (if by=NULL
). This is wanted to avoid aggregation of these values. Function chain()
finally sets the values back to 100.
Functions unchain()
, chain()
, rebase()
, and convert(..., type="12mavg")
return numeric values of the same length as x
.
For type="year"
and type="quarter"
, function convert()
returns a named numeric vector of the length of quarters or years available in t
, where the names correspond to the last month of the year or quarter.
Sebastian Weinand
European Commission, Eurostat, Harmonised Index of Consumer Prices (HICP) - Methodological Manual - 2024 edition, Publications Office of the European Union, 2024, https://data.europa.eu/doi/10.2785/055028.
aggregate
### EXAMPLE 1
t <- seq.Date(from=as.Date("2021-12-01"), to=as.Date("2024-12-01"), by="1 month")
p <- rnorm(n=length(t), mean=100, sd=5)
# rebase index to new reference period:
rebase(x=p, t=t, t.ref=c("1996","2022")) # 1996 not present so 2022 is used
rebase(x=p, t=t, t.ref=c("1996","first")) # 1996 not present so first period is used
# convert into quarterly index:
convert(x=p, t=t, type="q") # first quarter is not complete so NA
# unchaining and chaining gives initial results:
100*p/p[1]
chain(unchain(p, t, by=12), t, by=12)
# use annual overlap:
100*p/mean(p[1:12])
(res <- chain(unchain(p, t, by=NULL), t, by=NULL))
# note that for backwards compability, each month in the first
# year receives an index value of 100. this allows the same
# computation again:
chain(unchain(res, t, by=NULL), t, by=NULL)
### EXAMPLE 2: Working with published HICP data
library(data.table)
library(restatapi)
options(restatapi_cores=1) # set cores for testing on CRAN
options(hicp.chatty=FALSE) # suppress package messages and warnings
# get hicp index values for euro area with base 2015:
dt <- hicp::data(id="prc_hicp_midx", filter=list(unit="I15", geo="EA"))
dt[, "time":=as.Date(paste0(time, "-01"))]
setkeyv(x=dt, cols=c("unit","coicop","time"))
# unchain, chain, and rebase all euro area indices by coicop:
dt[, "dec_ratio" := unchain(x=values, t=time), by="coicop"]
dt[, "chained_index" := chain(x=dec_ratio, t=time), by="coicop"]
dt[, "index_own" := rebase(x=chained_index, t=time, t.ref="2015"), by="coicop"]
# convert all euro area indices into annual averages:
dta <- dt[, as.data.table(
x=convert(x=values, t=time, type="year"),
keep.rownames=TRUE), by="coicop"]
setnames(x=dta, c("coicop","time","index"))
plot(index~as.Date(time), data=dta[coicop=="CP00",], type="l") # plot all-items index
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.