------------------------------------------------------------------------------- help forpchipolate-------------------------------------------------------------------------------

Piecewise cubic Hermite interpolation

pchipolateyvarxvar[ifexp] [inrange],generate(newvar)

by...:may be used withpchipolate; see help by.

Description

pchipolatecreatesnewvarby averaging non-missing values ofyvarand using piecewise cubic Hermite interpolation of missing values ofyvar, givenxvar. That is, provided thatxvaris not missing,1. When

yvaris not missing,newvaris the mean ofyvarover observations with the same value ofxvar. If a value ofxvaris unique, then each mean is just the same as the value ofyvarat that point.2. When

yvaris missing,newvaris filled in using piecewise cubic Hermite interpolation.

RemarksThis method is often described informally as "pchip". For a lucid account, see Moler (2004, Ch.3). Informally, pchip interpolates using piecewise cubics that join smoothly, so that both the interpolated function and its first derivative are continuous. In addition, the interpolant is shape-preserving in the sense that it cannot overshoot locally; sections in which observed

yvaris increasing, decreasing or constant withxvarremain so after interpolation, and local extremes (maxima, maxima) also remain so.This interpolation method also extrapolates.

The first two examples are based on the help for ipolate in Stata 10.

Options

generate()is not optional; it specifies the name of the new variable to be created.

Examples--------------------------------------------------------------------------- Setup

. webuse ipolxmpl1, clearList the data

. list, sep(0)Create

y1containing an interpolation ofyonxfor missing values ofy. pchipolate y x, gen(y1)Plot the result

. line y1 x || scatter y xList the result

. list, sep(0)--------------------------------------------------------------------------- Setup

. webuse ipolxmpl2, clearShow years for which the circulation data are missing

. tabulate circ year if circ == ., missingCreate

pchicirccontaining an interpolation ofcirconyearfor missing values ofcircand perform this calculation separately for eachmagazine. by magazine: pchipolate circ year, gen(pchicirc)Plot the result

. line pchicirc year || scatter circ year, by(magazine){hline}--------------------------------------------------------------------------- Moler's example

. clear. set obs 6. matrix y = (16, 18, 21, 17, 15, 12)'. gen y = y[_n, 1]. gen x = _n. set obs 61. replace x = (_n + 1)/10 in 7/L. pchipolate y x, gen(pchip). line pchip x, sort || scatter y x---------------------------------------------------------------------------

AuthorNicholas J. Cox, Durham University, U.K. n.j.cox@durham.ac.uk

AcknowledgmentsMost of the Mata code in this program is a translation of MATLAB code given by Moler (2004).

ReferencesMoler, C. 2004.

Numerical Computing with MATLAB.Philadelphia: SIAM. Chapter 3. (also available in slightly different form at http://www.mathworks.com/moler/interp.pdf)

Also seeManual:

[D] ipolateOn-line: help for ipolate, help for cipolate (if installed), help for