Announcement

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

  • Single marginsplot from two models

    Hello, I would like to create a marginsplot that shows results from two different iterations of a model (one contains the full dataset, and one contains only a subset) simultaneously. Is this possible? I tried addplot:

    marginsplot, addplot(marginsplot if variable!=x)

    While the plot runs (ie there is no error message), all I get is a margins plot that looks identical to what I get when I simply use the margins plot command without any modifiers. Any suggestions would be much appreciated!

  • #2
    I don't think there is a simple way to do this. -marginsplot- is a somewhat brittle command: you may have already noticed that it can only be used immediately after the -margins- command that generates its data. You certainly won't be able to cajole it to do two things at once like that.

    I think the solution to your problem is to bypass -marginsplot- altogether. The -margins- command has an undocumented -saving()- option, which creates a data file containing the generated statistics with their confidence intervals and the values of the variables they are associated with. I would run -margins- with that option after each of the two models. Then I would merge the two saved files together (renaming some variables as needed) and simply make the desired plot using -graph twoway-. It's a pain, but I don't think there's any easier way.

    Comment


    • #3
      Thanks so much, this is a great workaround. I have everything in the newly merged file, and can graph the two connected lines on the same plot like this:

      twoway (connected _margin _group if newvar==0) (connected _margin _m1 if newvar==1)

      However, I'm having trouble figuring out how to include the confidence intervals for each of the points. There may be a simple answer, but I'm fairly new to graphing in Stata and my reading hasn't uncovered anything appropriate to this situation, since the CIs are their now their own variables (not part of model output I've generated). Would appreciate your advice, and thanks again!

      Comment


      • #4
        Update: solved my problem. I was able to generate range spikes with caps, from the CI low and high variables, that overlay on the appropriate points.

        twoway (connected _margin _groupvar if newvar==0) (connected _margin _groupvar if newvar==1)
        (rcap low_ci high_ci _groupvar if newvar==0) (rcap low_ci high_ci groupvar if var12==1)

        I hope someone else will find this useful if they encounter a similar issue.

        Comment


        • #5
          You might also want to check out Nick Winter's combomarginsplot, available from SSC. The description says "module to combine the saved results from multiple calls to margins into one marginsplot."
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          StataNow Version: 19.5 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment

          Working...
          X