coicop | R Documentation |
Function is.coicop()
checks if the input is a valid COICOP code while level()
returns the level (e.g. division or subclass).
For HICP data, COICOP codes are sometimes merged into bundles (e.g. 08X
, 0531_2
), deviating from the usual code structure. Function is.bundle()
flags if a COICOP code is a bundle or not, while unbundle()
resolves the bundles into the underlying valid codes.
Functions parent()
and child()
derive the higher-level parents or lower-level children of a COICOP code.
is.coicop(id, settings=list())
level(id, label=FALSE, settings=list())
is.bundle(id, settings=list())
unbundle(id, settings=list())
child(id, usedict=TRUE, closest=TRUE, k=1, settings=list())
parent(id, usedict=TRUE, closest=TRUE, k=1, settings=list())
id |
character vector of COICOP codes. |
label |
logical indicating if the number of digits or the labels (e.g., division, subclass) should be returned. |
usedict |
logical indicating if parents or children should be derived from the full code dictionary defined by |
closest |
logical indicating if the closest parents or children should be derived or the k-th ones defined by |
k |
integer specifying the k-th relative (e.g., |
settings |
list of control settings to be used. The following settings are supported:
|
The following COICOP versions are supported:
Classification of Individual Consumption According to Purpose (COICOP-1999): coicop1999
European COICOP (version 1, ECOICOP): ecoicop
ECOICOP adopted to the needs of the HICP (version 1, ECOICOP-HICP): ecoicop.hicp
COICOP-2018: coicop2018
ECOICOP (version 2, ECOICOP 2): ecoicop2
The COICOP version can be set temporarily in the function settings or globally via options(hicp.coicop.version)
. The package default is ecoicop.hicp
.
None of the COICOP versions include a code for the all-items index. By default, the internal package code for the all-items index is defined by options(hicp.all.items.code="00")
but can be changed by the user. The level is always 1.
Although bundle codes (e.g. 08X
, 0531_2
) are no valid COICOP codes, they are internally resolved into their underlying codes and processed in that way if they can be found in the bundle code dictionary (see getOption("hicp.coicop.bundles")
). If bundle codes should not be processed, the dictionary can be cleared by options("hicp.coicop.bundles"=list())
.
Functions is.coicop()
and is.bundle()
return a logical vector, function level()
an integer vector, and functions child()
, parent()
, and unbundle()
a list. All function outputs have the same length as id
.
Sebastian Weinand
tree
### EXAMPLE 1
# check if coicop codes are valid:
is.coicop(id=c("00","CP00","01","011","13","08X"))
# get the coicop level or label:
level(id=c("00","05","053","0531_2"))
level(id=c("00","05","053","0531_2"), label=TRUE)
# derive children and parents
# no children of 01 present in ids:
child(id=c("01"), usedict=FALSE)
# still no direct child present:
child(id=c("01","0111"), usedict=FALSE, closest=FALSE, k=1)
# but a grandchild of 01 is found:
child(id=c("01","0111"), usedict=FALSE, closest=TRUE)
# derive the children from the code dictionary:
child(id=c("01"), usedict=TRUE)
# two parents found for 05311 due to presence of bundle code:
parent(id=c("0531","0531_2","05311","05321"), usedict=FALSE)
# simplification removes bundle code:
parent(id=c("0531","0531_2","05311","05321"), usedict=FALSE, settings=list(simplify=TRUE))
### 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
# load hicp item weights of euro area:
coicops <- hicp::data(id="prc_hicp_inw", filter=list(geo="EA"))
coicops <- coicops[grepl("^CP", coicop),]
coicops[, "coicop":=gsub("^CP", "", coicop)]
# show frequency of coicop levels over time:
coicops[, .N, by=list(time, "lvl"=level(coicop))]
# get coicop parent from the data:
coicops[, "parent":=parent(id=coicop, usedict=FALSE, settings=list(simplify=TRUE)), by="time"]
# flag if coicop has child available in the data:
coicops[, "has_child":=lengths(child(id=coicop, usedict=FALSE))>0, by="time"]
coicops[has_child==FALSE, sum(values, na.rm=TRUE), by="time"]
# coicop bundles and their component ids are both taken into
# account. this double counting explains some differences
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.