Announcement

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

  • Secondary axis and adding texts to margins plot

    Hi everyone.

    Can someone please guide me through how to make this margins plot more visible, (probably making 'Outcome 4' a secondary y-axis) and also adding texts to the graphs(e.g p=0.01)?
    graphstatlist.gph

    mlogit mental c.year i.agecat i.sex
    margins
    sort year
    margins, at(year=(2012(2)2021))
    marginsplot, name(graph1, replace)

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(mental year agecat sex)
    1 2012 3 1
    4 2012 1 2
    4 2012 0 2
    4 2012 0 2
    4 2012 1 1
    4 2012 1 1
    4 2012 1 1
    4 2012 0 1
    4 2012 3 2
    3 2012 1 1
    4 2012 1 2
    4 2012 2 2
    4 2012 0 2
    4 2012 3 2
    4 2012 0 2
    4 2012 0 1
    4 2012 0 2
    4 2012 2 2
    4 2012 1 2
    4 2012 3 2
    4 2012 1 1
    4 2012 3 2
    4 2012 0 2
    4 2012 2 1
    4 2012 3 1
    4 2012 2 1
    4 2012 3 2
    4 2012 2 2
    4 2012 3 1
    4 2012 1 1
    4 2012 3 1
    4 2012 1 1
    4 2012 2 2
    4 2012 3 2
    4 2012 0 2
    4 2012 2 2
    4 2012 3 1
    4 2012 0 2
    4 2012 2 1
    4 2012 3 2
    4 2012 3 2
    4 2012 3 2
    4 2012 3 2
    4 2012 1 1
    4 2012 3 1
    4 2012 1 2
    4 2012 2 2
    4 2012 1 1
    4 2012 2 2
    2 2012 3 2
    end
    Attached Files

  • #2
    In the future, please upload images in PNG format as advised in FAQ Advice #12. You should probably graph the margins separately and then combine using gr combine. Having 3 lines correspond to one y-axis and one line to a second y-axis in the same graph will just cause confusion.

    Code:
    mlogit mental c.year i.agecat i.sex
    estimates store m1
    margins, at(year=(2012(2)2021))  predict(outcome(1)) predict(outcome(2)) predict(outcome(3))
    marginsplot, saving(gr1, replace)
    est restore m1
    margins, at(year=(2012(2)2021))  predict(outcome(4))
    marginsplot, saving(gr2, replace)
    gr combine gr1.gph gr2.gph
    For adding text, consider:

    Code:
    sysuse auto, clear
    mlogit rep78 mpg displ
    margins, atmeans
    set scheme s1mono
    marginsplot, xtitle("") plotopts(text(.5 2 "{it: p}<0.01"))
    where the highlighted numbers specify where the text is placed (the number in blue corresponds to the y-axis value and the number in red, the x-axis value).

    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	26.7 KB
ID:	1695724




    Last edited by Andrew Musau; 03 Jan 2023, 00:27.

    Comment


    • #3
      Good evening Prof Musau,
      Thank you so much for your correction and for your help. The codes worked perfectly. I am so happy, I v been working on it for so many days without a solution.
      Thank you so much.

      Comment

      Working...
      X