rates {hicp}R Documentation

Change rates and contributions

Description

Function rates() computes monthly, annual and annual average rates of change for an index series. Function contrib() computes the contributions of a subcomponent to the annual change rate of the overall index.

Usage

rates(x, t=NULL, type="monthly")

contrib(x, w, t, x.all, w.all, method="ribe")

Arguments

x, x.all

numeric vector of index values.

w, w.all

numeric vector of weights of the subcomponent (w) and the overall index (w.all).

t

date vector.

type

character specifying the type of change rate. Allowed values are monthly for monthly change rates, annual for annual change rates, and annual-average for annual average change rates.

method

character specifying the method used for the calculations. Allowed values are ribe and kirchner.

Value

For rates(), a numeric vector of the same length as x if type='monthly' or type='annual'. If type='annual-average', same length as years available.

For contrib(), a numeric vector of the same length as x.

Author(s)

Sebastian Weinand

References

Eurostat (2024), Harmonised Index of Consumer Prices (HICP): Methodological Manual, Luxembourg: Publications Office of the European Union, online available at: https://ec.europa.eu/eurostat/web/products-manuals-and-guidelines/w/ks-gq-24-003.

Examples

### EXAMPLE 1

P <- rnorm(n=25,mean=100,sd=5)
t <- seq.Date(from=as.Date("2021-01-01"), by="1 month", length.out=length(P))

rates(x=P, type="monthly")
rates(x=P, type="annual")
rates(x=P, type="annual-average")
rates(x=P, t=t, type="annual-average")

### EXAMPLE 2: Contributions using published HICP data

# set cores for testing on CRAN:
library(restatapi)
options(restatapi_cores=1)
library(data.table)

# import monthly price indices:
prc <- hicp.dataimport(id="prc_hicp_midx", filter=list(unit="I15", geo="EA"))
prc[, "time":=as.Date(paste0(time, "-01"))]
prc[, "year":=as.integer(format(time, "%Y"))]
setnames(x=prc, old="values", new="index")

# import item weights:
inw <- hicp.dataimport(id="prc_hicp_inw", filter=list(geo="EA"))
inw[, "time":=as.integer(time)]
setnames(x=inw, old=c("time","values"), new=c("year","weight"))

# merge price indices and item weights:
hicp.data <- merge(x=prc, y=inw, by=c("geo","coicop","year"), all.x=TRUE)

# add all-items hicp:
hicp.data <- merge(x=hicp.data,
                   y=hicp.data[coicop=="CP00", list(geo,time,index,weight)],
                   by=c("geo","time"), all.x=TRUE, suffixes=c("","_all"))

# ribe decomposition:
hicp.data[, "ribe" := contrib(x=index, w=weight, t=time, 
                              x.all=index_all, w.all=weight_all), by="coicop"]

# annual change rates over time:
plot(rates(x=index, t=time, type="annual")~time,
     data=hicp.data[coicop=="CP00",],
     type="l", ylim=c(-2,12))

# add contribution of energy:
lines(ribe~time, data=hicp.data[coicop=="NRG"], col="red")

# compare to published contributions:
hicp.ctrb <- hicp.dataimport(id="prc_hicp_ctrb")
hicp.ctrb[, "time":=as.Date(paste0(time, "-01"))]
dt.comp <- merge(x=hicp.ctrb,
                 y=hicp.data[, list(coicop, time, ribe)],
                 by=c("coicop","time"),
                 all=TRUE)
head(dt.comp[!is.na(values) & abs(values-ribe)>0.1, ]) # should be empty

[Package hicp version 0.4.2 Index]