Hi, I am fitting a piecewise linear mixed regression in Stata. I want to model the mileage of cars (macars) at day 0, 30, 90, and 180 (variable days), with age as a confounder. Note that this model is illustrative and not the real data.
Based on the descriptives, I found that the estimates should go down from day 0 to day 30, down but more flattened from day 30 to day 90, and slightly up from day 90 to day 180. I want to model the regression with two knots at day 30 and 90 (to detect any inflection point), and then predict the car mileage at day 0, 30, 90, and 180. This is the code that I am using:
Is this technically correct? By using this command, I found a very erroneous predicted estimates which do not match the descriptives at all, so I was wondering if my coding is correct.
Any help would be greatly appreciated. Thank you very much.
#p.s.: sorry I could not post any part of the data here
Based on the descriptives, I found that the estimates should go down from day 0 to day 30, down but more flattened from day 30 to day 90, and slightly up from day 90 to day 180. I want to model the regression with two knots at day 30 and 90 (to detect any inflection point), and then predict the car mileage at day 0, 30, 90, and 180. This is the code that I am using:
Code:
mkspline days_1 30 days_2 90 days_3 = days, marginal mixed macars c.days_1 c.days_2 c.days_3 c.age || id: days_1 days_2 days_3, difficult *To find the predicted car mileage at day 0, 30, 90, and 180 margins, at(days_1 = 0 days_2 = 0 days_3 = 0) at(days_1 = 30 days_2 = 0 days_3 = 0) at(days_1 = 90 days_2 = 60 days_3 = 0) at(days_1 = 180 days_2 = 150 days_3 = 90) *To find the slope for each segment, where the coefficient of days_1 is regarded as the slope for d0-30, days_2 for d30-90, and days_3 for d90-180 margins, dydx(*)
Any help would be greatly appreciated. Thank you very much.
#p.s.: sorry I could not post any part of the data here