Hi. I am running a piecewise regression on my panel data where the time series variables are con_id and week_num. I have used the mkspline command to create knots at week 78 and 107, my two intervention points. I also have a categorical age variable that groups consultants (con_id) by age groups (<30, 30-40...). I suspect heterogenous treatment effects by age, where doctors of different age groups respond differently to the treatment, and want to estimate this effect of age on treatment uptake. In a regression with interaction terms, I would have interacted each age group with the treatment variable. However, I am not sure how to do this in the regression using splines. Any guidance on this would be much appreciated.
Code:
*current code //time dummy vars at intervention points gen week1 = 0 replace week1 = 1 if week_num >= 78 gen week2 = 0 replace week2 = 1 if week_num >= 107 *creating knots mkspline knot1 78 knot2 107 knot3 = week_num xtset con_id week_num xtreg week_docalltele knot1 knot2 knot3 week1 week2, vce(cluster con_id) predict linear_spline /* Generate the predicted scores */ *sample data clear input float week_num long con_id float(week_docalltele age_cat) byte(knot1 knot2 knot3) float(week1 week2) 1 1 5 2 1 0 0 0 0 1 2 3 2 1 0 0 0 0 1 3 1 3 1 0 0 0 0 1 4 16 3 1 0 0 0 0 1 5 15 3 1 0 0 0 0 1 6 5 4 1 0 0 0 0 1 9 3 2 1 0 0 0 0 1 10 3 3 1 0 0 0 0 1 14 6 3 1 0 0 0 0 1 18 3 2 1 0 0 0 0 1 19 12 4 1 0 0 0 0 1 20 2 2 1 0 0 0 0 1 21 1 4 1 0 0 0 0 2 1 9 2 2 0 0 0 0 2 2 2 2 2 0 0 0 0 2 3 5 3 2 0 0 0 0 2 4 15 3 2 0 0 0 0 2 5 10 3 2 0 0 0 0 2 6 6 4 2 0 0 0 0 2 9 2 2 2 0 0 0 0 2 10 1 3 2 0 0 0 0 2 11 2 3 2 0 0 0 0 2 14 5 3 2 0 0 0 0 2 17 3 4 2 0 0 0 0 2 18 4 2 2 0 0 0 0 2 19 7 4 2 0 0 0 0 2 20 6 2 2 0 0 0 0 2 21 6 4 2 0 0 0 0 2 23 2 4 2 0 0 0 0 3 1 24 2 3 0 0 0 0 3 4 13 3 3 0 0 0 0 3 5 29 3 3 0 0 0 0 3 9 8 2 3 0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