Announcement

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

  • Suppressing "aobserved" in marginsplot?

    Hello,

    I want to plot an interaction between a binary variable (0 = control, 1 = treatment) and a categorical variable (0 = risk class 1, 1 = risk class 2, 2 = risk class 3). I am using margins and marginsplot and the plot comes out fine, except that I keep getting data for "aobserved." I can delete the aobserved data manually, but how do I suppress it from being printed in my graph using syntax? Example below.

    Click image for larger version

Name:	Picture1.png
Views:	1
Size:	60.9 KB
ID:	1613200


    Thank you for your help.

  • #2
    I should add that I am using Stata 16.1. Thank you!

    Comment


    • #3
      In the future, create a reproducible example that exhibits your problem. You can suppress the "asobserved" plot as below:

      Code:
      webuse nhanes2f, clear
      logit diabetes i.female##i.race weight height
      set scheme s1color
      margins i.female##i.race
      marginsplot, xdim(race) saving(gr1, replace)
      marginsplot, xdim(race) plot3opts(lc(none) mc(none)) ci3opts(col(none)) leg(order(4 "Male" 5 "Female")) saving(gr2, replace)
      gr combine gr1.gph gr2.gph
      Res.:
      Click image for larger version

Name:	Graph.png
Views:	1
Size:	32.3 KB
ID:	1613237

      Comment


      • #4
        Thank you!

        Comment


        • #5
          There is an easier way to suppress the "asobserved" from the marginsplot; you simply do not ask for them in you margins command!
          In you margins command do not type i.a##i.b; - instead just type i.a#i.b !

          Code:
          sysuse auto.dta
          gen displacement_gt_100= displacement>100
          regress weight i.foreign##i.displacement_gt_100

          margins foreign##displacement_gt_100
          marginsplot, plot(displacement_gt_100 ) name(xx) ti(i.a##i.b)

          Instead code:
          margins foreign#displacement_gt_100
          marginsplot, plot(displacement_gt_100 ) name(i.a#i.b)

          xx.gph x.gph
          Attached Files
          Last edited by Kim Lyngby Mikkelsen; 15 Nov 2021, 07:55.

          Comment


          • #6
            Code:
            regress weight age sex

            Comment


            • #7
              Dear Andrew,

              If I want to make a triple interaction and I am using the option by(), how can I suppress the "asobserved"?

              Comment


              • #8
                Just look at the plot position from the legend, where you count from the top column left=1, top-right =2 , second column top-left=3 and so on.

                Code:
                webuse nhanes2f, clear
                qui sum weight, d
                gen hiweight = weight> r(p50)
                logit diabetes i.female##i.race##i.hiweight height
                set scheme s1color
                margins i.female##i.race##i.hiweight
                marginsplot, xdim(race) saving(gr1, replace)
                Res.:
                Click image for larger version

Name:	Graph.png
Views:	1
Size:	50.0 KB
ID:	1704403



                So "as observed" plots are at positions 3, 6, 7, 8 and 9. Therefore, just repeat the options in #3 to suppress these plots.

                Code:
                marginsplot, xdim(race) plot3opts(lc(none) mc(none)) ci3opts(col(none)) ///
                    plot6opts(lc(none) mc(none)) ci6opts(col(none)) ///
                    plot7opts(lc(none) mc(none)) ci7opts(col(none)) ///
                    plot8opts(lc(none) mc(none)) ci8opts(col(none)) ///
                    plot9opts(lc(none) mc(none)) ci9opts(col(none)) ///
                    leg(order(10 "Male low-weight" 11 "Male high-weight" ///
                    13 "Female low-weight" 14 "Female high-weight" ))
                Click image for larger version

Name:	Graph.png
Views:	1
Size:	31.6 KB
ID:	1704404

                Comment

                Working...
                X