Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculating and graphing percentage change using predictive margins.

    Hello everyone,

    I am hoping to be able to calculate and graph the percentage change of predictive margins between 4 time points (change between 1 and 2, 2 and 3, and 3 and 4) using the predictive margins so I can compare a bunch of variables and see which have changed the most and when (I'd ideally like to graph them as well so I can present them easier). I was trying to look up ways to do it but all the code I can find seems to use data from variables that already exist, whereas I want to do it based off of margins. Any guidance is greatly appreciated. I've included my full code below (I want to keep this as well because it gives me our full graphs of the data).

    data_point is my time variable (there's just 4 time points).

    Code:
    local yvar DRS_Score CHESS_Score PAIN_Score ADL_H_SCORE ADL_S_SCORE ADL_L_SCORE ISE_SCORE PSI_SCORE ABS_SCORE PURS_SCORE CPS_SCORE
    local tvar 13 5 3 6 16 28 6 18 12 8 6
    local zvar 3.5 1.5 1 4.5 11.5 19.5 4.5 6.5 4.5 3 4.5
    local mvar 0 0 0 3 8 14 1 3.5 .5 1.5 2.5
    local nvar Depression CHESS Pain ADL_H ADL_S ADL_L ISE PSI ABS PURS CPS
    
    forval k = 1/11 {
        local y : word `k' of `yvar'
        local t : word `k' of `tvar'
        local n : word `k' of `nvar'
        local z : word `k' of `zvar'
        local m : word `k' of `mvar'
        display as result "Outcome = `y'"
        
        anova `y' Sex_AA2 Pre_LTCH Sex_AA2#Pre_LTCH / ///
        unique_ID|Pre_LTCH#Sex_AA2 ///
        data_point ///
        data_point#Sex_AA2 data_point#Pre_LTCH ///
        data_point#Sex_AA2#Pre_LTCH ///
        if Sex_AA2!=2, ///
        rep(data_point)
    
        margins, over(Pre_LTCH Sex_AA2 data_point)
        
        marginsplot, xdim(data_point) ylabel(0 `t') ytick(0(1)`t') name(`n',replace) ///
        graphregion(margin(5 20 10 5)) title("Predictive Margins for `n'") ///
        xtitle("Time point") ytitle("Adjusted Prediction (0-`t')") 
        
         marginsplot, xdim(data_point) ylabel(`m' `z') ytick(`m'(.5)`z') name(`n'zoom,replace) ///
        graphregion(margin(5 20 10 5)) title("Predictive Margins for `n'") ///
        xtitle("Time point") ytitle("Adjusted Prediction (0-`t')") 
        
        grc1leg `n' `n'zoom, ///
        altshrink  name(`n'both, replace) ///
        title("Predictive Margins for `n' (95% CI)", size(medium)) ///
        graphregion(fcolor(white))
     
        graph close `n' `n'zoom
        
        graph export "`n'.png", as(png) replace
    }
    Last edited by Elyse Cottrell; 20 Sep 2019, 14:05.
Working...
X