Announcement

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

  • Marginsplot: y scale (plot) different of scale of original variable

    Dear Stata users,
    I have a problem with the range of y scale's marginsplot. I have a (0 100) dependent variable, but the y-scale of the marginsplot has a different range:
    HTML Code:
    . regress  INCOME    c.MONTER1##c.MONTER2 , r
    
    
    . margins, at( MONTER1= (200 1202222) MONTER2=(0 0.5)) vsquish
    
     . marginsplot, xsize(13) ysize(9) scale(0.8)  noci noseparator recast(line) plotopts(lwidth(medthick) lcolor(black) cmissing(n)  connect(direct))  plot1opts( lpattern(dash_dot_dot)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle(" ")   legend(order(1 "Low MONTER2" 2 "High MONTER2") size(medsmall) ) clegend(region(fcolor(white) lcolor(white))) title("") xlabel(200 "Low MONTER1"   1150000 "High MONTER2") yline(0) yline(100) 
    Click image for larger version

Name:	Graph 1.jpg
Views:	1
Size:	120.2 KB
ID:	1685857



    HTML Code:
     . marginsplot, xsize(13) ysize(9) scale(0.8)  noci noseparator recast(line) plotopts(lwidth(medthick) lcolor(black) cmissing(n)  connect(direct))  plot1opts( lpattern(dash_dot_dot)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle(" ")   legend(order(1 "Low MONTER2" 2 "High MONTER2") size(medsmall) ) clegend(region(fcolor(white) lcolor(white))) title("") xlabel(200 "Low MONTER1"   1150000 "High MONTER2") yline(0) yline(100) yscale(r(0 100)) ylabel(0(10)100) 



    Click image for larger version

Name:	Graph 2.jpg
Views:	1
Size:	147.7 KB
ID:	1685858




    Sorry, but I don't understant why the range of de y scale of the marginsplot is not (0 100) as the range of the dependent variable.
    I would appreciate yours advices.
    Thanks in advance,
    Rocio

  • #2
    What margins shows is the predicted outcome, and apperently your model predicts outcomes way outside the range of your dependent variable. Your model is a linear regression (regress), and that model does not impose a constraint on the values of the outcome; it just plots a straight line through your data. My guess is that most of your data is concentrated around the low end of monter1, so your regression tries to fit a straight line that fits best in this lower part, and it fits pretty awfully at the higher end of monter1. So the problem is not margins or marginsplot. The problem is that your model is wrong. Since it just the lower bound that seems to be the problem you could use poisson with robust standard errors https://blog.stata.com/2011/08/22/us...tell-a-friend/ . Alternative, you can use a model that respects both the upper and lower bound by dividing your dependent variable by 100 and use fracreg.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Maarten has good ideas. When I need to predict interval data, I often use:

      Code:
      glm y x , family(binomial) link(logit)

      Comment


      • #4
        For the solution proposed by George Ford you typically need to add the vice(robust) option. In that case it is the same as fracreg.
        ---------------------------------
        Maarten L. Buis
        University of Konstanz
        Department of history and sociology
        box 40
        78457 Konstanz
        Germany
        http://www.maartenbuis.nl
        ---------------------------------

        Comment


        • #5
          Thank you very much for your answers. However, in the case of using fracreg, I think it is necessary logit or probit after fracreg. I get the following results:
          HTML Code:
          . quiet  fracreg  INCOME10 c.MONTER1##c.MONTER2, vce(robust)
          . quiet  margins, at( MONTER1= (200 1202222) MONTER2=(0 0.5)) vsquish
          . marginsplot, xsize(13) ysize(9) scale(0.8)  noci noseparator recast(line) plotopts(lwidth(medthick) lcolor(black) cmissing(n)  connect(direct))  plot1opts( lpattern(dash_dot_dot)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle(" ")   legend(order(1 "Low MONTER2" 2 "High MONTER2") size(medsmall) ) clegend(region(fcolor(white) lcolor(white))) title("") xlabel(200 "Low MONTER1"   1150000 "High MONTER2") yline(0) yline(100) yscale(r(0 100)) ylabel(0(10)100)
          Click image for larger version

Name:	Graph1.jpg
Views:	1
Size:	134.1 KB
ID:	1686835




          HTML Code:
           . marginsplot, xsize(13) ysize(9) scale(0.8)  noci noseparator recast(line) plotopts(lwidth(medthick) lcolor(black) cmissing(n)  connect(direct))  plot1opts( lpattern(dash_dot_dot)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle(" ")   legend(order(1 "Low MONTER2" 2 "High MONTER2") size(medsmall) ) clegend(region(fcolor(white) lcolor(white))) title("") xlabel(200 "Low MONTER1"   1150000 "High MONTER2") yline(0) yline(100)
          Click image for larger version

Name:	Graph2.jpg
Views:	1
Size:	131.5 KB
ID:	1686834





          Thank you very much for your advice, but I don't think it will help me in my case.

          Please help if something is wrong.


          In the case of glm, the results are also strange.

          HTML Code:
          . quiet glm INCOME10 c.MONTER110##c.MONTER210, family(binomial) link(logit) vce(robust)
          . quiet margins, at( MONTER1= (2 12000) MONTER2=(0 0.003)) vsquish
          . marginsplot, xsize(13) ysize(9) scale(0.8)  noci noseparator recast(line) plotopts(lwidth(medthick) lcolor(black) cmissing(n)  connect(direct))  plot1opts( lpattern(dash_dot_dot)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle(" ")   legend(order(1 "Low MONTER2" 2 "High MONTER2") size(medsmall) ) clegend(region(fcolor(white) lcolor(white))) title("") xlabel(200 "Low MONTER1"   1150000 "High MONTER2") yline(0) yline(100) yscale(r(0 100)) ylabel(0(10)100)
          Click image for larger version

Name:	Graph11.jpg
Views:	1
Size:	126.4 KB
ID:	1686839



          HTML Code:
          . marginsplot, xsize(13) ysize(9) scale(0.8)  noci noseparator recast(line) plotopts(lwidth(medthick) lcolor(black) cmissing(n)  connect(direct))  plot1opts( lpattern(dash_dot_dot)) plotregion(fcolor(white)) graphregion(fcolor(white)) xtitle(" ")   legend(order(1 "Low MONTER2" 2 "High MONTER2") size(medsmall) ) clegend(region(fcolor(white) lcolor(white))) title("") xlabel(200 "Low MONTER1"   1150000 "High MONTER2")
          Click image for larger version

Name:	Graph22.jpg
Views:	1
Size:	102.2 KB
ID:	1686840




          Thanks you very much for you advice.
          Best
          Last edited by Rocio Aguilar; 26 Oct 2022, 05:34.

          Comment


          • #6
            Why do you think it won't help?
            ---------------------------------
            Maarten L. Buis
            University of Konstanz
            Department of history and sociology
            box 40
            78457 Konstanz
            Germany
            http://www.maartenbuis.nl
            ---------------------------------

            Comment


            • #7
              Dear Maarten, I think that it is not the same graph.
              Thanks for you interest.
              Rocio

              Comment


              • #8
                Ofcourse, when done correctly you will get a better graph.
                ---------------------------------
                Maarten L. Buis
                University of Konstanz
                Department of history and sociology
                box 40
                78457 Konstanz
                Germany
                http://www.maartenbuis.nl
                ---------------------------------

                Comment

                Working...
                X