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

st: Re: -mkspline- reference

From   Kit Baum <>
Subject   st: Re: -mkspline- reference
Date   Wed, 6 May 2009 10:55:54 -0400

Section 7.4.1 of IMEUS (below) contains some of that material. It does not work from first principles, but the algebra involved with linear splines is very straightforward in terms of restricted least squares. For a linear spline, the function must equal the same value to the left and right of each knot point, as discussed in 7.4.1. Thus if we did not have -mkspline-, we could easily do what it is doing:

webuse lutkepohl,clear
g t1 = 0
g t2 = 0
g a1 = tin(1960q1,1974q4)
g a2 = tin(1975q1,1982q4)
replace t1 = qtr if tin(1960q1,1974q4)
replace t2 = qtr if tin(1975q1,1982q4)
reg income a1 a2 t1 t2, nocons hascons
predict double ihat, xb
tsline ihat if tin(1960q1,1974q4) || tsline ihat if tin(1975q1,1982q4)
// 1982q4 is t = 60; apply continuity
constraint def 1 a1 + t1*60 = a2 + t2*60
cnsreg income a1 a2 t1 t2, nocons c(1)
predict double ihat2, xb
tsline ihat2 if tin(1960q1,1974q4) || tsline ihat2 if tin(1975q1,1982q4)

Compare the two graphs. Notice that the constrained function is continuous (but not differenttiable) at the single knot point. (We could easily add additional knot points to this function). If we imposed that the derivative of the function was equal to the left and right, we'd have a quadratic spline. If we imposed that both first and second derivatives were equal to the left and right, we'd have a cubic spline. But linear splines are just predicted values that obey continuity over the variable at each knot point.

Kit Baum   |   Boston College Economics & DIW Berlin   |
An Introduction to Stata Programming |
   An Introduction to Modern Econometrics Using Stata  |

On May 6, 2009, at 02:33 , statalist-digest wrote:

Thanks.  Actually, -mkspline- computes *linear* splines. For instance,
the following code:

. mkspline  Age1  44  Age2 = Age

. regress Y Age1 Age2

fits a continuous, piecewise linear model of E(Y|Age) for which the
slope is permitted to change abruptly at Age=44.

Thus I am looking for a reference that specifically explains what
algorithm and formulas are implemented in -mkspline-, and perhaps also
discusses uses of linear splines and gives examples where they are
used to good effect.

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index