Two points:
Official Mata has its own -invtokens()- function so that you can use
that instead without installing -moremata-. But note that Ben's function
does pre-date the official one, or so I recall.
Also, -rcspline- on SSC has an option -showknots- which does this. It
may be that
. rcspline price mpg, nknots(7) showknots
is what you want. Alternatively, install -rcspline- anyway using -ssc-
and look at the code for showing the knots.
if "`showknots'" != "" {
tempname xk
matrix `xk' = r(knots)
forval i = 1/`= r(N_knots)' {
local k `k' `=`xk'[1, `i']'
}
local showk xline(`k', lw(vvthin))
}
Nick
[email protected]
Ben Jann
How about:
sysuse auto
mkspline smpg=mpg, nknots(7) displayknots cubic
matrix list r(knots)
mata: st_local("knots", mm_invtokens(strofreal(st_matrix("r(knots)"))))
scatter price mpg, xline(`knots')
-moremata- is required. Type -ssc install moremata-.
ben
On Wed, Jan 28, 2009 at 12:13 PM, Claus Dethlefsen
<[email protected]> wrote:
> Using cubic splines, I would like to display the knots used. In Stata
> 10, I can use mkspline to create the spline variables and it returns
> the values of the knots in a matrix. I would like to transfer this
> matrix in a nice way to my scatter plot command as the xline argument.
> Example:
>
>
> sysuse auto
> mkspline smpg=mpg, nknots(7) displayknots cubic
> matrix list r(knots)
>
>
> scatter price mpg, xline(14 16 18 20
> 23 26 31)
> ^ here I would like to write
> r(knots) instead of copy-pasting the values
>
*
* 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/