Announcement

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

  • Having Two Margin Plots on One Graph

    Hi everyone. I am struggling with a presentation issue. I have run a probit regression and I am collecting margins and displaying it on a graph. I have two variables that are categorial that both have the same categories, making the x-axis the same. I want to have both of them plotted on the same graph, and I have tried using 'combomarginsplot' but this has not helped and does not show two lines. It is confusing what it is actually doing and I would appreciate any help on this matter.

    My commands are:

    margins life_satisfaction, atmeans saving(file1)

    margins income_satisfaction, atmeans saving(file2)

    combomarginsplot file1 file2

    The result shows:

    Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	35.5 KB
ID:	1609342

  • #2
    The two categorical variables may have the same categories but only one is being plotted on the y-axis of the combined plot. Perhaps, like this:

    Code:
    clear
    set seed 5132021
    sysuse auto
    gen y = ceil(6*runiform())
    gen x = ceil(6*runiform())
    
    probit foreign mpg i.y
    margins y, atmeans  saving(file1, replace)
    probit foreign mpg i.x
    margins x, atmeans  saving(file2, replace)
    combomarginsplot file1 file2, name(gr1,replace ) offset off(.1) legend(pos(6) row(1)) scheme(white_tableau)
    
    
    rename y y_original
    rename x y
    probit foreign mpg i.y
    margins y, atmeans saving(file2, replace)
    combomarginsplot file1 file2, offset off(.1) scheme(white_tableau) legend(pos(6) row(1))
    graph combine gr1 Graph
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	68.5 KB
ID:	1609353

    Comment


    • #3
      Scott Merryman thank you so much! This has worked perfectly!

      Click image for larger version

Name:	Whether Saves by Life AND Income Satisfaction.jpg
Views:	1
Size:	34.6 KB
ID:	1609375

      Comment

      Working...
      X