help for hotdeckvar Matthias Schonlau

Creating imputed variables through single hotdeck imputation

hotdeckvar
[varlist]
[if exp]
[in range]
,
[
suffix(str)
]

Description

The algorithm identifies all donor observations
that have no missing values
for any of the variables specified. Missing values from the
same observation are replaced with values from the same donor
observation to preserve correlations.
Donor observations are chosen at
random.

Generates imputed variables named <varname>`suffix'. By default `suffix' is "_i".
The new variables are identical with the old ones except that missing values
are replaced by random values of the old variables.
If a variable contains no missing values no imputed variable is created.
If a variable contains only missing values an error is given.
<varlist> must contain only numerical variables.
Variables specified in a by statement may be either numerical or string variables.

If [in] or [if] is specified both the values to be imputed as well as
the pool of values imputed from is the values specified by [in] and [if].
by can be used with this command to impute within categories defined by the
by -variables. If any by-group contains only missing values
the command will give an error and exit.

Hotdeck imputation is especially useful for discrete variables (e.g 0/1 dummy variable)
where the imputed values shouldn't take any other values. Regression imputation with impute
would result into intermediate values (e.g. 0.56 for 0/1 dummy variables).

Note: hotdeckvar will impute both normal missing
values (.) and extended missing values (.a,.b,...,.z).
This is due to version control (V7).

Options

suffix(str) specifies the suffix that imputed variable
names take. By default the suffix is "_i". For example, the imputed variable "x"
will be named "x_i"

Examples Imputing completely at random

Impute variables var1 and var2 and store results in "var1_m" and "var2_m":

. hotdeckvar var1 var2, suffix("_m")

Impute all variables in memory that have missing values and generate
variables "<varname>_i " for the imputed variables (Note: this will not work if any
variables in memory are string variables.):

. hotdeckvar

Impute the housevalue where missing for respondents who own houses

. hotdeckvar housevalue if own_house==1

Example: Specifying a donor pool of observations

Often you don't want to impute completely at random, but rather from a pool of observations defined by a combination of a small number of categorical variables:

. bysort classvar1 classvar2: hotdeckvar y

If the donor pool of observations is empty (that is, if a combination of classvar1 and classvar2 has only missing values) then you will get an error mesage.

The sort in "bysort" is not stable. If you are want to make this reproducible,
in addition to setting a seed value you need to specify a stable sorting algorithm:

. set seed 5844

. sort classvar1 classvar2,stable

. by classvar1 classvar2: hotdeckvar y

Example: Multiple imputation.

Suppose we have 3 variables with missing values, x5, x2, and x8. We use the categorical variables x3 and x4 to form pool of observations from which missing values are imputed. That is, we only impute among observations that have the same combinations of values for x3 and x4.

In this example we impute 5 times. All 5 data sets remain in memory. (In Mander's function "hotdeck" imputations are written into an external file).
The five data sets can be identified through the variable imputation.

.gen seq=_n

.expand 5

.sort seq

.by seq: gen imputation= _n

We specify all three variables with missing values in the same command. In case an observation has missing values for more than one of the x-variables, this ensures that the same donor observation is used for the imputation.

.bysort imputation x3 x4 : hotdeckvar x5 x2 x8

micombine is a user written function that works with most regression functions for multiply imputed data. We use the imputed version of the variables (with suffix _i). Because previously we identified x3 and x4 as categorical variables, we use the i. prefix to create indicator variables.

.micombine regress y x1 x2_i i.x3 i.x4 x5_i x6 x7 x8_i, obsid(seq) impid(imputation)

Author

Matthias Schonlau
schonlau at uwaterloo dot ca
www.schonlau.net

Also see

On-Line: hotdeck in STB54, sg116.1 by A. Mander and D. Clayton

This ado file performs multiple imputations by subgroups. Each imputation is output to a different file which has to be merged back to the main data set. Therefore it is more cumbersome to use when a single imputation is desired.

On-Line: micombine by Patrick Royston

Manual: [R] impute