Dear Stata users,

I am interested in investigating the association between specific measurements (baseline albuminuria and eGFR change). To do this, I am trying to use cubic spline and create a scatter plot of baseline UACR and eGFR change, where the line of best fits with 95% CI adjusted for other covariates.

My codes look as below, but not sure whether I am in right direction or not.

Codes:
HTML Code:
by ID (Years_from_baseline), sort: gen gfr_change = gfr - gfr[1]  
gen log_uacr=log(uacr)
mkspline uacr_spline = log_uacr, nknots(5) cubic
regress gfr_change uacr_spline* i.gender age sbp  
predict gfr_change_predicted, xb
by log_uacr, sort: egen gfr_change_margin = mean(gfr_change_predicted)

???  twoway (scatter gfr_change_margin log_uacr, msymbol(.) msize(tiny)) 
Would anyone be able to help?

Many thanks,
Oyun