Announcement

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

  • plot with margins from different variables in one model

    I'd like to make a plot with the margins results for multiple variables

    Simply, using auto, I do this:

    reg price i.foreign i.rep78
    margins foreign rep78

    ------------------------------------------------------------------------------
    | Delta-method
    | Margin Std. Err. t P>|t| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    foreign |
    Domestic | 6134.857 474.7025 12.92 0.000 5186.239 7083.474
    Foreign | 6171.614 790.5026 7.81 0.000 4591.92 7751.307
    |
    rep78 |
    1 | 4575.687 2146.133 2.13 0.037 286.9831 8864.391
    2 | 5978.812 1105.625 5.41 0.000 3769.397 8188.227
    3 | 6436.745 585.9965 10.98 0.000 5265.724 7607.765
    4 | 6064.308 735.0801 8.25 0.000 4595.368 7533.249
    5 | 5894.113 1043.948 5.65 0.000 3807.949 7980.277
    ------------------------------------------------------------------------------

    Now I'd like one figure for these margins, with two groups of scatter, one for each variable. As if I did this:

    margins foreign
    marginsplot, recast(scatter)

    margins rep78
    marginsplot, recast(scatter)

    But got them in one figure using the same x- and y-axis.

    Appreciate any tips!

  • #2
    It's not clear what you want on the x-axis, as you are plotting two different variables. But perhaps something like this is a step in the direction you have in mind?

    Code:
    margins foreign
    marginsplot, name(f)
    margins rep78
    marginsplot, name(r) yscale(off)
    graph combine f r, ycommon

    Comment


    • #3
      Thanks. Yes, that's the gist. I can customize off that. e.g.,
      reg price i.foreign i.rep78
      margins foreign
      marginsplot, title("") recast(bar) name(g, replace) plotopts(barw(.6) color(khaki))
      margins rep78
      marginsplot, title("") recast(bar) name(r, replace) yscale(off) plotopts(barw(.6) color(khaki))
      graph combine g r, ycommon title(combined)

      Comment

      Working...
      X