Function for Top and Bottom Coding.

topBotCoding(obj, value, replacement, kind = "top", column = NULL)

Arguments

obj

a numeric vector, a data.frame or a sdcMicroObj-class-object

value

limit, from where it should be top- or bottom-coded

replacement

replacement value.

kind

top or bottom

column

variable name in case the input is a data.frame or an object of class sdcMicroObj-class.

Value

Top or bottom coded data or modified sdcMicroObj-class.

Details

Extreme values larger or lower than value are replaced by a different value (replacement in order to reduce the disclosure risk.

Note

top-/bottom coding of factors is no longer possible as of sdcMicro >=4.7.0

References

Templ, M. and Kowarik, A. and Meindl, B. Statistical Disclosure Control for Micro-Data Using the R Package sdcMicro. Journal of Statistical Software, 67 (4), 1–36, 2015. doi:10.18637/jss.v067.i04

See also

Author

Matthias Templ and Bernhard Meindl

Examples

data(free1)
res <- topBotCoding(free1[,"DEBTS"], value=9000, replacement=9100, kind="top")
max(res)
#> [1] 9100

data(testdata)
range(testdata$age)
#> [1]  0 95
testdata <- topBotCoding(testdata, value=80, replacement=81, kind="top", column="age")
range(testdata$age)
#> [1]  0 81

## for objects of class sdcMicro:
data(testdata2)
sdc <- createSdcObj(testdata2, keyVars=c('urbrur','roof','walls','water','electcon','relat','sex'),
           numVars=c('expend','income','savings'), w='sampling_weight')
sdc <- topBotCoding(sdc, value=500000, replacement=1000, column="income")
testdataout <- extractManipData(sdc)