# Re: st: broken stick (piecewise linear) regression

 From Maarten buis <[email protected]> To [email protected] Subject Re: st: broken stick (piecewise linear) regression Date Thu, 31 Jan 2008 21:05:58 +0000 (GMT)

```--- Raphael Fraser <[email protected]> wrote:
> I saw a thread with the above subject line concerning
> piecewise linear regression posted in 2005 on Statalist.
> I am facing the same problem now; that of estimating the unknown
> change point. Mention was made of using -nl- but it uses
> least squares method. The only way to solve this problem
> is numerical optimization. The problem can be solved
> quite easily in SAS using NLIN PROC.
> Is there a Stata solution?

Purely looking at the name my guess would be that both -nl- and NLIN
PROC use the same or a very similar algorithm: nonlinear least squares,
which is not the same as least squares. It is the most common way I
have seen to estimate these kinds of models, though you could also us
-ml- but that would be a bit (but not much) more work. Notice that this
is a tough maximization problem so it really helps to have good
starting values. I would recommend starting with a scatter plot, and
find the likely location for the knot, use that knot to create a spline
and estimate a regression. Use those parameters as starting values when
you use -nl- like in the example below to finally estimate your
parameters.

*--------------- begin example -----------------
sysuse auto, clear

// first take a look
twoway scatter price mpg

// 20 seems a nice starting value for
// the knot location
mkspline mpg1 20 mpg2 = mpg, marginal
reg price mpg1 mpg2
local cons = _b[_cons]
local b1 = _b[mpg1]
local b2 = _b[mpg2]
predict initial

// use -nl- to find the knot
nl (price = {cons=`cons'} + {b1=`b1'}*mpg + ///
{b2=`b2'}*max(mpg -{k1=20},0))
predict nl

// look at the results
twoway scatter price mpg ||          ///
line initial nl mpg, sort     ///
legend(order( 2 "first guess" ///
3 "estimated"))
*---------------- end example -------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

Hope this helps,
Maarten

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------

__________________________________________________________
Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```