Hello! I am using Stata 17, trying to run npregress with the option knotsmat() to estimate and plot linear splines with knots at specific points.
However, from the graph, it is clear that knotsmat() is not working – the lines are very messy and definitely have more than one and two knots (for model 2 and 3, respectively).
Here is my code:
My data looks like this:
Could someone kindly advise?
Thank you in advance.
However, from the graph, it is clear that knotsmat() is not working – the lines are very messy and definitely have more than one and two knots (for model 2 and 3, respectively).
Here is my code:
Code:
gen gdp_lag = L.gdp gen debt_lag = L.debt reg gdp gdp_lag debt_lag // Model (1) predict gdp_fitted1 if e(sample) matrix knotsmat_60 = (3 \ 60) npregress series gdp gdp_lag debt_lag, spline(1) knotsmat(knotsmat_60) // Model (2) predict gdp_fitted2 if e(sample) matrix knotsmat_40_80 = (3, 3 \ 40, 80) npregress series gdp gdp_lag debt_lag, spline(1) knotsmat(knotsmat_40_80) // Model (3) predict gdp_fitted3 if e(sample) twoway (scatter gdp debt_lag) /// (line gdp_fitted1 debt_lag) /// (line gdp_fitted2 debt_lag) /// (line gdp_fitted3 debt_lag), /// legend(label(1 "Observed") label(2 "Model 1") label(3 "Model 2") label(4 "Model 3")) /// ytitle("GDP growth") xtitle("Debt lag") /// title("GDP growth and debt/GDP ratio models")
Code:
* Example generated by -dataex-. For more info, type help dataex clear input int year float(debt gdp inflation) 1791 38.61396 5.955335 -.6532725 1792 36.526653 7.259953 2.554585 1793 31.37096 8.078603 5.142333 1794 26.04761 13.131313 9.607142
Thank you in advance.