Announcement

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

  • marginsplot legend code modfication for different lines

    Dear all,

    q5_ is an ordinal variable of 1-5 which has been measured for each ptid
    pre-procedure pre_post =1 and post-procedure pre_post=2 for each procedure =1 (treatment) and procedure=0 (control)

    I would like to plot the probabilities of response to q5 pre and post procedure for both treatment and control

    Here is what I used

    Code:
    meologit q5_ i.procedure_t_c##pre_postno ||ptid:,vce(robust) or level(95)
    marginsplot, by(procedure_t_c)
    
    //This produced two graphs for procedure_t_c =1 and procedure_t_c=0  at the pre_post=1 and pre_post=2 (which is what I want)  but with lots of lines (of course since q_5 is an ordinal variable of 1-5)
    However, I'm unable to tell which one belongs to q5_ =1 etc
    Perhaps, is there a way I can relabel the legend? Or if you could suggest any modifications to the code ?

    Many thanks

  • #2
    You do not show your margins command. If you include only the interaction, the outcomes should be identified in the marginsplot.

    Code:
    meologit q5_ i.procedure_t_c##pre_postno ||ptid:,vce(robust) or level(95)
    margins i.procedure_t_c#pre_postno
    marginsplot, by(procedure_t_c)

    Comment


    • #3
      Andrew Musau Thanks apologies I forgot to show my margins command- and yes that’s what I had

      but my question is the above code produced two graphs for procedure_t_c =1 and procedure_t_c=0 at the pre_post=1 and pre_post=2 (which is what I want)

      but with lots of lines (of course since q_5 is an ordinal variable of 1-5)

      I'm unable to tell which one belongs to q5_ =1 etc

      can you help ? Is this perhaps due to the -order- and I must rename the lines ? In that case how do i know eg blue is q5=1 and so forth?

      Comment


      • #4
        The lowest valued category is always at the top of the legend. You can plot each individually using:

        Code:
        meologit q5_ i.procedure_t_c##pre_postno ||ptid:,vce(robust) or level(95)
        margins i.procedure_t_c#pre_postno, predict(outcome(1))
        marginsplot, by(procedure_t_c)


        Code:
        meologit q5_ i.procedure_t_c##pre_postno ||ptid:,vce(robust) or level(95)
        margins i.procedure_t_c#pre_postno, predict(outcome(2))
        marginsplot, by(procedure_t_c)
        and so on. As always, changing the legend labels is via the -order()- option:

        Code:
        legend(order(1 "Category 1" 2 "Category 2"))

        Comment

        Working...
        X