Statalist


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

st: Fwd: graphing piecewise linear functions


From   Tom Moliterno <[email protected]>
To   [email protected]
Subject   st: Fwd: graphing piecewise linear functions
Date   Wed, 21 Jan 2009 11:05:08 -0500

Has anyone had any success graphing a piecewise linear spline function
(as depicted in the manual entry for mkspline)?  Here's the
particulars of my situation:

I use mkspline to create linear splines of a continuous variable which
I then enter into a xtregar model.  The coefficient output is:

     ---------------------------
     Variable |   active
    -------------+-------------
      DiffAge |  .01427393
      nRetire |  .01360399
  NYEPitch | -.01675667
      PopL_t |  .01006339
  PerAttend |  .26760882
PHAa25neg |  .12388889
PHAa25pos | -.02416822
RSAQuart1 |  .52529619
RSAQuart2 |  1.3234114
RSAQuart3 |  .08617324
RSAQuart4 |   .7577389
        _cons |   .2089866
---------------------------

The RSAQuart* variables are the splines.  What I would like to do now
is graph these effects, with the goal being a graph similar to what
appears in the reference manual entry for the mkspline command:  i.e.,
a continuous effect with "kinks" at the knots.  Looking at my results,
it is clear that, for example, in 2nd spline (RSAQuart2) the slope
should be about 2.5x the slope in the first.

So how to do this??  I have tried a number of things, but with no
luck.  The best I got was with

.twoway (function y= 0.2089866 + 0.5252962*x, range(0 $p25)) ||
(function y = 0.2089866 + 1.323411*x, range($p25 $p50)) || /*
 */ (function y = 0.2089866 + 0.0861732*x, range($p50 $p75)) ||
(function y = 0.2089866 + 0.7577389*x, range($p75 $max))

Here the global macros $p25, etc. are the values of the continuous
variable (from which I made the splines) at the knots (i.e., the 25th,
50th and 75th percentiles). The 0.2089866 value is the constant from
the regression.  I know that constant value is not the right thing
there, since the graph that I get seems to show the right slopes in
the splines, but they don't connect at all.  So I suspect I need a
different constant in each of the (function) statements.  I have tried
calculating a constant that was a sum of the coefficients*mean values
for variables other than the splines ... but that didn't work either.
There must be a simple answer to this that I'm missing!

Thanks,

Tom

--
**********************************************************
Thomas P. Moliterno, PhD
Moore School of Business
University of South Carolina
[email protected]
**********************************************************
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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