coicop {hicp} | R Documentation |
Working with COICOP codes
Description
Function is.coicop()
checks if the input is a valid COICOP code while level()
returns the COICOP level (e.g. division or subclass). Function parent()
derives the higher-level parent of a COICOP code if available in the data supplied. The function child()
does the same for lower-level children.
Usage
is.coicop(id, settings=list())
level(id, label=FALSE, settings=list())
child(id, flag=TRUE, direct=FALSE, settings=list())
parent(id, flag=TRUE, direct=FALSE, settings=list())
Arguments
id |
character vector of COICOP ids. |
label |
logical indicating if the number of digits or the labels (e.g., division, subclass) should be returned. |
flag |
for |
direct |
logical indicating if only direct relatives should be flagged as |
settings |
a list of control settings to be used. The following settings are supported:
|
Details
The following COICOP versions are supported:
Classification of Individual Consumption According to Purpose (COICOP-1999):
coicop1999
European COICOP (ECOICOP):
ecoicop
ECOICOP adopted to the needs of the HICP (ECOICOP-HICP):
ecoicop-hicp
-
COICOP-2018:
coicop2018
None of the COICOP versions include a code for the all-items index. The internal package code for the all-items index is globally defined by options(hicp.all.items.code="00")
but can be changed by the user. The level()
is always 1.
If settings$unbundle=TRUE
, COICOP bundle codes are resolved into their component ids and processed in that way. By contrast, if settings$unbundle=FALSE
, COICOP bundle codes are internally set to NA
. Consequently, they can't be a parent or a child of some other COICOP code.
Value
Function is.coicop()
returns a logical vector and function level()
a numeric vector. If argument flag=TRUE
, functions parent()
and child()
both return a logical vector. If flag=FALSE
, parent()
gives a character vector, while child()
returns a list. In any case, all function outputs have the same length as id
.
Author(s)
Sebastian Weinand
See Also
Examples
### EXAMPLE 1
# validity of coicop id:
is.coicop(id=c("00","CP00","13","08X"), settings=list(unbundle=TRUE))
is.coicop(id=c("00","CP00","13","08X"), settings=list(unbundle=FALSE))
# coicop level:
level(id=c("00","05","053","0531_2"))
level(id=c("00","05","053","0531_2"), label=TRUE)
# check for children in data:
child(id=c("0111"), flag=FALSE) # false, no child found
child(id=c("0111", "01"), flag=FALSE, direct=TRUE) # still false
child(id=c("0111", "01"), flag=FALSE, direct=FALSE) # now TRUE
# check for parent in data, including coicop bundles:
ids <- c("053","0531_2","05311","05321")
parent(id=ids, flag=FALSE, direct=TRUE, settings=list(unbundle=FALSE))
parent(id=ids, flag=FALSE, direct=TRUE, settings=list(unbundle=TRUE))
### EXAMPLE 2
# set cores for testing on CRAN:
library(restatapi)
options(restatapi_cores=1)
library(data.table)
# load hicp item weights:
coicops <- hicp.dataimport(id="prc_hicp_inw", filter=list(geo="EA"))
coicops <- coicops[grepl("^CP", coicop),]
coicops[, "coicop":=gsub("^CP", "", coicop)]
# get frequency of coicop levels:
coicops[, .N, by=list(time, "lvl"=level(coicop))]
# get coicop parent from the data:
coicops[, "parent":=parent(id=coicop, flag=FALSE), by="time"]
# flag if coicop has child available in the data:
coicops[, "has_child":=child(id=coicop, flag=TRUE), 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