Announcement

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

  • marginsplot after ordered logit model

    Hi there,

    I've been struggling with getting my marginsplot the way I would like it. I will use the example data fullauto show my problem.

    Code:
    clear all
    webuse fullauto
    I have a DV rep77 with 5 categories, ranging from 1 (poor) to 5 (excellent). I have 2 EV, namely mpg (continuous) and the dummy variable foreign.

    I have the following ordered logit model

    Code:
    ologit rep77 mpg i.foreign
    When I follow up with the commands below, I get 10 curves, because of the 5 categories of the DV and 2 categories of the EV foreign

    Code:
    margins, at(mpg=(10(5)45) foreign=(0(1)1))
    marginsplot
    I would like it if only the curves of the probabilities of outcome 1 and outcome 2 would show (for both foreign and domestic, so 4 curves in total). How do I do this?



    In addition, I would like to have this graph with 2 curves: the predicted probabilities of outcome < 3 (so either 1 or 2), for both foreign and domestic.
    Is this possible to obtain with a marginsplot?
    I learned that after estimating the model, you could do the following to obtain the predicted probability for y < 3.

    Code:
    predict p1-p5
    generate p12 = p1 + p2
    Then with -scatter-, you can get the graph. Is there another way?


    I hope everything is clear. Thank you in advance



    Complete do file down below

    Code:
    clear all
    webuse fullauto
    
    ologit rep77 mpg i.foreign
    margins, at(mpg=(10(5)45) foreign=(0(1)1))
    marginsplot
    
    
    * The 2 graphs I would like to obtain with marginsplot
    
    ologit rep77 mpg i.foreign
    predict p1-p5
    
    scatter p1 p2 mpg
    
    
    generate p12 = p1 + p2
    
    scatter p12 mpg



  • #2
    Code:
    margins, at(mpg=(10(5)45) foreign=(0/1)) predict(outcome(1)) predict(outcome(2))
    marginsplot

    Comment


    • #3
      Andrew Musau T
      Thank you so much! (:

      Comment


      • #4
        Does Someone know whether or not I can get margin to estimate the Probability than more than 1 of several outcomes is attained?

        For example,

        ologit Y X1 X2 X3

        margins at(X1=0(10)100), predict(outcome(1)) predict(outcome(2))

        would give me two lines in marginsplot... one for Pr(outcome=1) and for Pr(outcome=2) at various points of X1


        But I want to combine to get the Pr of outcome 1 OR outcome 2 (i.e., one line on the graph)

        I've tried various syntax... like

        .margins at(X1=0(10)100), predict(outcome(1 2))

        or
        .margins at(X1=0(10)100), predict(outcome(1/2))

        but this just returns this error:

        outcome() must be either a value of Y or #1, #2, ...


        I could recode my dependent variable Y to combine outcomes 1 and 2

        recode Y (1/2 =1) (3=2) (4=3), generate(Y2)

        but I am not sure that

        ologit Y2 X1 X2 X3


        Comment


        • #5
          margins has an -expression()- option which will allow you to define such an expression.

          Code:
          clear all
          webuse fullauto
          ologit rep77 mpg
          margins, at(mpg=(10(5)45)) predict(outcome(1)) predict(outcome(2))
          set scheme s1mono
          marginsplot, recast(line) saving(gr1, replace)
          margins, at(mpg=(10(5)45)) expression(predict(outcome(1)) + predict(outcome(2)))
          marginsplot, recast(line) saving(gr2, replace) leg(on order(2 "Outcome 1 or Outcome 2"))
          gr combine gr1.gph gr2.gph, ycommon
          Click image for larger version

Name:	Graph.png
Views:	1
Size:	36.7 KB
ID:	1697043

          Last edited by Andrew Musau; 12 Jan 2023, 14:44.

          Comment


          • #6
            thanks much!

            Comment

            Working...
            X