Title

stripolate -- Interpolate string values

Syntax

stripolate
stryvar
xvar
[if] [in]
,
generate(newvar)
[
forward
backward
groupwise
]

by is allowed; see [D] by.
A by() option may be specified instead, but not in conjunction.

Description

stripolate creates in newvar an interpolation of the string
variable stryvar on xvar for missing values of stryvar.

stripolate uses one of the following methods: forward, backward,
groupwise. One of these options must be specified.

Remarks

Interpolation requires that stryvar be a function of xvar, so
cannot proceed if two or more distinct non-missing values are observed
for stryvar fr the same xvar
(or with the by: prefix, for the same
xvar and the same values of the variables specified by by:).
When stryvar is not missing, the value of newvar is just
stryvar.

stripolate does not require tsset or xtset data and
makes no check for, or use of, any such settings. With panel data, it
will usually be essential to specify a panel identifier to by:.

Use of the by: prefix restricts interpolation to at most
the same group of observations as defined by the variable(s) specified.

Options

generate(newvar) is required and specifies the name of the
new variable to be created.

forward specifies forward interpolation, so that any known
value just before one or more missing values is copied in cascade to
provide interpolated values, constant within any such block.

backward specifies backward interpolation, so that any known
value just after one or more missing values is copied in cascade to
provide interpolated values, constant within any such block.

groupwise specifies that non-missing values be copied to
missing values if, and only if, just one distinct non-missing value
occurs in each group. Thus a group of values "", "A", "", "" qualifies
as "A" is not missing and is the only non-missing value in the group.
Hence the missing values in that group will be replaced with "A" in the
new variable. By the same rules "A", "", "A", "" qualifies but "A", "",
"B", "" does not. Normally, but not necessarily, this option is used in
conjunction with by:, which is how groups are specified; otherwise
the (single) group is the entire set of observations being used.

Note that xvar is strictly irrelevant for this method, as
order of values is immaterial. To keep syntax consistent, it should be
specified any way.

Examples

Setup

. clear

. set obs 15

. gen id = ceil(_n/5)

. bysort id: gen time = _n

. gen foo = "A" if inlist(_n, 2, 4)

. replace foo = "B" if inlist(_n, 6, 8, 12)

. replace foo = "C" in 14

List the data

. list, sepby(id)

Methods illustrated

. by id: stripolate foo time, gen(barf) forward

. by id: stripolate foo time, gen(barb) backward

. by id: stripolate foo time, gen(barg) groupwise

List the data and results

. list, sepby(id)

Author

Nicholas J. Cox, Durham University, U.K.

n.j.cox@durham.ac.uk