------------------------------------------------------------------------------- help forcsipolate-------------------------------------------------------------------------------

Cubic spline interpolation

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

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

Description

csipolatecreatesnewvarby averaging non-missing values ofyvarand using natural cubic spline 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 natural cubic spline interpolation.

RemarksExtrapolation is not provided. Some users may wish to extrapolate any remaining missing values linearly using ipolate.

csipolateis a wrapper using Mata functionsspline3()andspline3eval(). If desired see help and in turn Mata source code here. That code is a translation of code originally given by Herriot and Reinsch (1973).The examples are based on the help for ipolate in Stata 10. Stata 9 users will need to substitute their own.

Options

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

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

. webuse ipolxmpl1List the data

. list, sep(0)Create

y1containing a natural cubic spline interpolation ofyonxfor missing values ofy. csipolate y x, gen(y1)List the result

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

. webuse ipolxmpl2Show years for which the circulation data are missing

. tabulate circ year if circ == ., missingCreate

csicirccontaining a natural cubic spline interpolation ofcirconyearfor missing values ofcircand perform this calculation separately for eachmagazine. by magazine: csipolate circ year, gen(csicirc)---------------------------------------------------------------------------

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

AcknowledgmentsBen Ammar reported an example which underlined that there is point in asking for interpolation of singleton values. If that value is known, there is nothing to interpolate. If that value is unknown, there is nothing to do it with.

ReferencesHamming, R.W. 1973.

Numerical methods for scientists and engineers.New York: McGraw-Hill. See pp.349-356.Herriot, J.G. and C.H. Reinsch. 1973. Algorithm 472: procedures for natural spline interpolation.

Communications of the Association forComputing Machinery16: 763-768.Lancaster, P. and K. Salkauskas. 1986.

Curve and surface fitting: anintroduction.London: Academic Press. [capital S of Salkauskas should bear caron or wedge diacritic]Press, W.H., S.A. Teukolsky, W.T. Vetterling, B.P. Flannery. 2007.

Numerical recipes: the art of scientific computing.Cambridge: Cambridge University Press. See pp.120-124.

Also seeManual:

[D] ipolate