Announcement

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

  • marginsplot after svy mlogit

    Dear Statalisters.

    Hope this question/message finds you well. I am posting regarding an issue with marginsplot after running svy mlogit. So here I have a five-category response variable, usualpl, which was label valued with a format. Then I run the following svy mlogit of usualpl on a series of dummy variables for race/ethnicity (raceethn), along with a series of controls. Then I use the margins command to run prediction, followed by marginsplot to plot the predictions. There are 14 racial/ethnic groups and five outcomes for the response variable. My problems are with the plot. Although the five-category response variable, usualpl, was properly valued and labelled, the legend of the marginsplot still shows text descriptions like outcome 1, outcome 2,..., outcome 5. Also note that in the following I specified the symbol shapes in msymbol option, but the program only uses the first marker shape Oh. So my specific questions would be how to vary the markers and change the symbols and text description in the legend of marginsplot. Any pointer or good examples would be much appreciated.

    Jun Xu, PhD
    Professor
    Data Analytics/Science Program
    Department of Sociology
    Ball State University
    Web: sites.google.com/site/socjunxu

    Code:
        svy: mlogit usualpl i.raceethn educ age fmle married nativeVar income engprof insured genhlth, base(5)
        margins i.raceethn
    
        marginsplot, xlabel(, angle(45)) ///
                    xtitle("Race/Ethnicity", size(*0.8)) ytitle("Pr(Usual Place of Care|x)") ///
                    title("Prob. of Usual Place of Care by Race/Ethnicity") ///
                    plotopts(msymbol(Oh Dh Sh Th +))        ///
                    legend(size(*0.5) title("Usual Source of Care") row(1) ///
                          lab(1 "1Office" 2 "2Clinc" 3 "3ER" 4 "4Other" 5 "5No"))
    marginsPlot5c.png

  • #2
    I'm not 100% sure this will work, but try placing each of the labels in separate parentheses.
    Code:
    legend(size(*0.5) title("Usual Source of Care") row(1) ///
    lab(1 "1Office") lab(2 "2Clinc") lab(3 "3ER") lab(4 "4Other") lab(5 "5No"))

    Comment


    • #3
      Dear Erik,

      I tried the new codes with lab, and it still didn't work. I am using Stata 17.

      Comment


      • #4
        Of course, the least I can do is to access the results right after the margins command, and then create graph by avoiding marginsplot. Any pointer or suggestion would be much appreciated.

        Comment


        • #5
          marginsplot plots the CIs before the connected lines and uses legend(order()) for labelling the plots. So you need to account for the CIs in your plot index and use legend(order()) to override the labels. Based on the original example/code, the following should work as requested.
          Code:
          svy: mlogit usualpl i.raceethn educ age fmle married nativeVar income engprof insured genhlth, base(5)
              margins i.raceethn
          
              marginsplot, xlabel(, angle(45)) ///
                          xtitle("Race/Ethnicity", size(*0.8)) ytitle("Pr(Usual Place of Care|x)") ///
                          title("Prob. of Usual Place of Care by Race/Ethnicity") ///
                          plotopts(msymbol(Oh Dh Sh Th +))        ///
                          legend(size(*0.5) title("Usual Source of Care") row(1) ///
                                order(6 "1Office" 7 "2Clinc" 8 "3ER" 9 "4Other" 10 "5No"))
          Last edited by Jeff Pitblado (StataCorp); 21 Sep 2023, 09:18.

          Comment


          • #6
            Dear Jeff,

            Thanks a lot! It works magically. Support from the Stata Corp and Stata's ease to work with data is why I love using it so much!. Below I post the Stata code snippet to make it final just in case others might have similar questions,

            Code:
               
            marginsplot, xlabel(, angle(45))  ///
                            xtitle("Race/Ethnicity", size(*0.8)) ytitle("Pr(Usual Place of Care|x)", size(*0.8)) ///
                            title("Prob. of Usual Place of Care by Race/Ethnicity", size(*0.8)) ///
                            plot1opts(msymbol(Oh))    ///
                            plot2opts(msymbol(Dh))  ///
                            plot3opts(msymbol(Sh))  ///
                            plot4opts(msymbol(Th))  ///
                            plot5opts(msymbol(+))   ///
                            legend(size(*0.5) title("Usual Source of Care", size(*0.8)) row(1) ///
                                order(6 "1Office" 7 "2Clinic" 8 "3ER" 9 "4Other" 10 "5No"))
            marginsPlot5c.png

            Comment

            Working...
            X