Replaces the raw household-level data with the anonymized household-level data in the full dataset for anonymization of data with a household structure (or other hierarchical structure). Requires a matching household ID in both files.
Replaces the raw household-level data with the anonymized household-level data in the full dataset for anonymization of data with a household structure (or other hierarchical structure). Requires a matching household ID in both files.
mergeHouseholdData(dat, hhId, dathh)
Arguments
dat: a data.frame with the full dataset
hhId: name of the household (cluster) ID (identical in both datasets)
dathh: a dataframe with the treated household level data (generated for example with selectHouseholdData )
Returns
a data.frame with the treated household level variables and the raw individual level variables
Examples
## Load datax <- testdata
## donttest is necessary because of ## Examples with CPU time > 2.5 times elapsed time## caused by using C++ code and/or data.table## Create household level datasetx_hh <- selectHouseholdData(dat=x, hhId="ori_hid", hhVars=c("urbrur","roof","walls","water","electcon","household_weights"))## Anonymize household level dataset and extract datasdc_hh <- createSdcObj(x_hh, keyVars=c('urbrur','roof'), w='household_weights')sdc_hh <- kAnon(sdc_hh, k =3)x_hh_anon <- extractManipData(sdc_hh)## Merge anonymized household level data back into the full datasetx_anonhh <- mergeHouseholdData(x,"ori_hid", x_hh_anon)## Anonymize full dataset and extract datasdc_full <- createSdcObj(x_anonhh, keyVars=c('sex','age','urbrur','roof'), w='sampling_weight')sdc_full <- kAnon(sdc_full, k =3)x_full_anon <- extractManipData(sdc_full)