*! version 1.0 23 October 2020
help for bracketfillversion 1.0 (23 October 2020)

Title

bracketfill --
Fill a continuous variable with coarse data from a bracket variable.

Table of contents

Syntax
Description
Options
Remarks
Examples
Author
Also see

Syntax

bracketfill
newvar=function
[if] [in]
,
brackets(bracketspec [bracketspec] [...])
[options]

where valid functions are:

center: the class center of a bracket (i.e. lower bound+(upper bound-lower bound)/2)

median: the median of observations inside a bracket (as calculated by summarize)

mean: the mean of observations inside a bracket (as calculated by summarize)

Each bracketspec consists of two space-separated elements defining a bracket,
the category definition and the range specification:

A category definition is to be a usual Stata expression that defines
a bracket of the categorial variable, such as:

categoricalvar==category

An range specification defines the range of a continuous variable that observations from the named category are supposed to originate from.

It is to be defind as a lower bound, the name of the continuous variable, and the upper bound, with one of the operators < or <= in between. For instance:

100<=continuousvar<1000

If any of the category definition or the range specification should contain space characters, they are to be surrounded by (compound) double quotes.

replace replace newvar, if existing, with the result

missing(value) use value for observations where the result variable cannot be filled with values (defaults to . if omitted)

copyrest(varname) copy values for observations not defined in a bracketspec from varname to the result variable

exclude(ifexpression) exclude observations that match ifexpression from calculation

verbose give verbose output

Description

Imagine your dataset contains two variables, a categorical one and a continuous one, about the same content. But for some reason, maybe item non-response in a survey, the continous variable contains missing values for some observations, while the categorical variable contains information for these observations.

A typical example from a survey is the question about a person's income. Respondents might not be willing, or not be capable of, answering the question about their exact income (measured continuously). They might, however, give information about their income category, in brackets of 500 Euros, for instance.

bracketfill serves the, on first sight, trivial purpose to try filling in the values of the bracketed categorical variable into the continuous one. It does so by picking either the center value of a bracket, or the mode or median of the continuous variable's empirical values, and inserting it into the continuous variable. This operation is the most trivial implementation to gain something that could be analyzed as if full data were present. Naturally, way more elaborate ways to deal with the issue of missing data exist, and are implemented in Stata itself or via user contributed commands.

Note that bracketfill does not aim to replace (multiple) imputation methods, or FIML estimations. These mechanisms are way more suitable for running analyses. bracketfill is more a tool to quickly insert imaginary values into a variable that are somehow close to the original value, for instance as an intermediate step to produce further variables for an analysis dataset. The data bracketfill produces are no replacement for real data, and are no replacement for an approximation to real data. The mechanism of inserting a single value for all observations in a bracket can not reflect the variation of the real distribution, and will reduce the variation of the result variable.

Options

Default

replace if newvar already exists, replace it with the result instead of generating a new variable.

missing(value) use value as missing value for all observations that are not covered by any bracketspec. If omitted, value defaults to the system missing value ("."). Extended missing values are allowed.

copyrest(varname) after populating the result variable, copy values from varname to the result variable for all observations that have not been covered by any bracketspec (or out-of-sample observations excluded by if or in).

exclude(ifexpression) exclude all observations that match to ifexpression from the calculation of the bracket value. The specified ifexpression has to be a valid Stata expression. Note that using the exclude() option is not equivalent to excluding observations using the if or in qualifiers. The latter are used to completely exclude observations from generating the new variable; the exclude() option only excludes observations from calculation behind the scenes, not from populating the target variable.

verbose during calculation, give verbose output on what's happening. This may help in debugging errors.

Remarks

The source code of the program is licensed under the
GNU General Public License version 3 or later.
The corresponding license text can be found on the internet at
http://www.gnu.org/licenses/ or in gnugpl.

Examples

Resemble the integrated (household) income variable in NEPS SUFs:

. bracketfill income=median if (t510010<0 | missing(t510010)), ///

brackets( ///

t510012==1 "0<=t510010<500" ///

t510012==2 "500<=t510010<1000" ///

t510012==3 "1000<=t510010<1500" ///

t510013==1 "1500<=t510010<2000" ///

t510013==2 "2000<=t510010<2500" ///

t510013==3 "2500<=t510010<3000" ///

t510014==1 "3000<=t510010<4000" ///

t510014==2 "4000<=t510010<5000" ///

t510014==3 "5000<=t510010<." ///

t510011==1 "0<=t510010<1500" ///

t510011==2 "1500<=t510010<3000" ///

t510011==3 "3000<=t510010<." ///

) ///

verbose copyrest(t510010) missing(.z)

Author

Daniel Bela (daniel.bela@lifbi.de),
Leibniz Institute for Educational Trajectories (LIfBi), Germany.

Also see

NEPSmgmt (if installed), recode, generate, replace, if