Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: -nnipolate- added to SSC for nearest neighbour interpolation


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: -nnipolate- added to SSC for nearest neighbour interpolation
Date   Fri, 9 Nov 2012 09:20:50 +0000

Thanks as usual to Kit Baum, a new command -nnipolate- for nearest
neighbour interpolation has been added to SSC. Stata 8.2 is required,
except that any Stata 8 or 9 users downloading it should rename
nnipolate.sthlp to nnipolate.hlp. If interested, download with

. ssc inst nnipolate

A couple of recent threads seemed to be asked for something like this,
so I decided to add it to the toolkit.

Assume a response yvar with some missing values we want to interpolate
with respect to a known xvar. Often, but not necessarily, xvar will be
a time variable. There is no presumption that data come regularly
spaced or that data have been -tsset- or -xtset-. Panels or some
equivalent are not excluded.

-nnipolate- creates newvar by averaging non-missing values of yvar and
using nearest neighbour interpolation of missing values of yvar, given
xvar. That is, provided that xvar is not missing, missing values of
yvar are filled in with
the value of the previous known value of yvar or the value of the next
known value of yvar, depending on which is nearer in terms of xvar.
When previous and next values are equally distant from a known value,
users have a choice
of rules that they may wish applied. By default, -nnipolate- uses the
mean of the two values.

See the help for details, and please note that this program cannot be
persuaded, tricked or coerced into interpolation in two or more
dimensions.

Official Stata has a very substantial multiple imputation suite, but
is still limited to linear interpolation using -ipolate-. This program
joins other user-written interpolation programs on SSC, namely

-cipolate- (cubic polynomials)

and

-csipolate-  (cubic splines).

Nick
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index