Dear Statalists,
Was trying to generate a restricted cubic spline plot by following a set of codes found online. My outcome and exposure variables are continuous measurements. The ideal graph I was trying to plot should be slimier to the one below

Picture taken from : https://www.stata.com/meeting/4nasug/RCsplines.pdf
However, after applying the same codes used to generate the spline graph shown above, I found quite a few lines appearing in my graph instead of just one line (spline plot 2). Does this look right? Also, is it okay to use code "regress" here while I want to the non-linear relationship between my outcome and exposure variables?
rc_spline x
regress y _x* i.nationality i.ethnic group i.pairty i.smoking i.income age and BMI
predict y_hat, xb
scatter y x,msymbol(Oh) || line y_hat x

Although, I managed to cut down several lines by substituting the code from “scatter y x,msymbol(Oh) || line y_hat x“ to “scatter y x,msymbol(Oh) || lowess y_hat x” But, the graph doesn’t look right to me.

Any idea what went wrong with the method when it comes to generating the cubic spline plot?
Many thanks for your insight in advance
Was trying to generate a restricted cubic spline plot by following a set of codes found online. My outcome and exposure variables are continuous measurements. The ideal graph I was trying to plot should be slimier to the one below
Picture taken from : https://www.stata.com/meeting/4nasug/RCsplines.pdf
However, after applying the same codes used to generate the spline graph shown above, I found quite a few lines appearing in my graph instead of just one line (spline plot 2). Does this look right? Also, is it okay to use code "regress" here while I want to the non-linear relationship between my outcome and exposure variables?
rc_spline x
regress y _x* i.nationality i.ethnic group i.pairty i.smoking i.income age and BMI
predict y_hat, xb
scatter y x,msymbol(Oh) || line y_hat x
Although, I managed to cut down several lines by substituting the code from “scatter y x,msymbol(Oh) || line y_hat x“ to “scatter y x,msymbol(Oh) || lowess y_hat x” But, the graph doesn’t look right to me.
Any idea what went wrong with the method when it comes to generating the cubic spline plot?
Many thanks for your insight in advance
