Deflation of welfare using auxiliary data
pd_deflation.RdDeflates a single cleaned survey data.table. Two input modes:
Usage
pd_deflation(
dt = NULL,
cpi = NULL,
ppp = NULL,
pop = NULL,
pip_id = NULL,
version = NULL,
verbose = getOption("pipdata.verbose", default = TRUE)
)Arguments
- dt
A single cleaned survey
data.table(classpipmdorpipgd), orNULLwhenpip_idis given instead.- cpi
Named numeric vector of CPI values (as returned by
pd_aux_attr()), or adata.tablefrompipload::pip_load_aux("cpi")for the legacy interface.NULLtriggers inventory-based loading.- ppp
Named numeric vector of PPP values (as returned by
pd_aux_attr()), or adata.tablefrompipload::pip_load_aux("ppp")for the legacy interface.NULLtriggers inventory-based loading.- pop
Named numeric vector of population values (as returned by
pd_aux_attr()), or adata.tablefrompipload::pip_load_aux("pop")for the legacy interface.NULLtriggers inventory-based loading.- pip_id
Character scalar. Survey identifier for Mode B (load from stamp). Ignored when
dtis provided.- version
Character scalar or
NULL. Stamp version used when loading the survey (Mode B) or resolving the metadata version from the master inventory.- verbose
Logical. When
TRUE(the default), informational messages from downstreampipload/stampI/O calls are shown. Set toFALSEto suppress them. Defaults togetOption("pipdata.verbose", default = TRUE).
Value
The input survey data.table augmented with welfare_lcu and
welfare_ppp_* columns, and three attributes:
welfare_vars: character vector of allwelfare_*column namesadj_pop: logical;TRUEif population weights were adjustedppp_sort: integer base year used for row sorting (e.g.2017L), orNULLwhen deflation produced nowelfare_ppp_*columns ReturnsNAwhen deflation fails (error logged vialog_failure()).
Details
Mode A (
dt): pass the cleaned survey directly. Whencpi/ppp/popareNULL, auxiliary metadata is loaded automatically from stamp via the master inventory.Mode B (
pip_id): pass a survey identifier and optional stamp version. The survey and metadata are both loaded automatically.
To deflate many surveys in a batch, use the future pd_deflate_pipeline()
wrapper (tracked in the roadmap as deflate-pipeline-wrapper), which
calls pd_deflation() for each survey in an inventory.
Note
pd_deflation() is a single-survey deflation helper. When
cpi/ppp/pop are NULL (the default), it resolves the matching
metadata version from the master inventory and loads CPI/PPP/pop
automatically. All package-level environment access uses the unified
.pipdataenv via accessor helpers (pd_env_set(), pd_env_get(),
pd_env_rm()).
See also
Other pd_process_data pipeline:
add_attr(),
aux_hash_candidates(),
build_pip_inventory(),
create_attr(),
data_to_dt(),
filter_aux_data(),
filter_aux_inv(),
fix_year_var(),
get_aux_hashes(),
inv_dlw_load(),
inv_to_process(),
log_report(),
pd_aux_attr(),
save_pip_data(),
survey_id_to_attr(),
valid_dlw_load()
Examples
if (FALSE) { # \dontrun{
# Mode A: pass survey directly, aux loaded automatically from master inventory
release <- "20250203"
pipfun::setup_working_release(release)
pfw <- pipload::pip_load_aux("pfw")
gd <- pipload::pip_load_dlw("CHN", 2015)
ls <- pd_cpfw_merge(gd, pfw)
x <- pd_dlw_clean(gd)[["CHN_2015_CHIP_INC_D1"]]
pd_deflation(x)
# Legacy Mode A: explicit aux tables
ppp <- pipload::pip_load_aux("ppp")
cpi <- pipload::pip_load_aux("cpi")
pop <- pipload::pip_load_aux("pop")
pd_deflation(x, cpi = cpi, ppp = ppp, pop = pop)
# Mode B: load by survey id
pd_deflation(pip_id = "CHN_2015_CHIP_INC_D1")
} # }