Announcement

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

  • Combine multiple marginsplots onto one graph

    Dear statalist users,

    I am currently using margins to estimate predicted values for logged NfL at different CAG repeat lengths and ages. I am doing this for each CAG individually and plotting a marginsplot for each individual CAG. Please see my code below:
    Code:
    regress logNfL Age i.CAG if disease_grp==1
                                          
            sum CAG if disease_grp==1, meanonly
                local min_cag = round(r(min)) 
                local max_cag = round(r(max))
                
        forvalues e = `min_cag'/`max_cag' {
        
            levelsof Age if CAG==`e' & disease_grp==1
        
            margins, at(Age=(`r(levels)') CAG=`e')
                est store model_cag`e'
                                    
            marginsplot, recast(line) noci plotopts(lcolor("179  50  40")) title("") ytitle("logNfL pg/mL") ///
            xlabel(20(5)46) xscale(range(20 46)) ylabel(1(0.5)4) yscale(range(1 4)) legend(off) ///
                    addplot( ///
                                (scatter `analyte' Age if disease_grp==1 & CAG==`e',  mcolor("179  50  40") ///
                                    xlabel(20(5)46) xscale(range(20 46)) ///
                                    ylabel(1(0.5)4') yscale(range(1 4))) ///
                            ) ///
                    name(control_`model'_`e', replace)
    What I want to now is to plot all of the different margin estimate models onto one graph as separate lines. Is there a way to do this? I have saved all of the models in a local and I have tried using coefplot to plot the individual models but I don't know if this is appropriate for margins.

    I look forward to your responses.

    Thank you,
    Annabelle

  • #2
    Have a look at

    Code:
    ssc describe combomarginsplot
    It should also be possible to combine several marginsplots using coefplot from SSC. However, there is no reproducible example provided here to illustrate this. If you struggle with the above command, please present a reproducible example with at least two marginsplots that need to be combined.

    Comment

    Working...
    X