Announcement

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

  • Saving the Confidence Intervals Values after Margins

    I'm trying to get more control over the graph (from marginsplot) after using the margins command (Graph1 attached). What I need is to make Graph1 looks like Graph2.
    My intuition is that if I can save the margins and the top and bottom values of the confidence intervals I could do the graph as I want without any problem. But, I do not know how to save them.
    Most likely this is a very basic question, but I have tried and the only solution is estimating the margins using asdoc to create the table and I could copy the values from that file. However, I'm wondering if there is any other faster option to do it.
    Thanks in advance.
    Click image for larger version

Name:	Graph1.png
Views:	1
Size:	95.3 KB
ID:	1750509

    Click image for larger version

Name:	graph2.png
Views:	1
Size:	54.8 KB
ID:	1750510

  • #2
    Something like this:
    Code:
    serset clear
    // YOUR REGRESSION COMMAND HERE
    // YOUR MARGINS COMMAND HERE
    marginsplot // WITH WHATEVER -at()- OR OTHER OPTIONS YOU NEED
    serset dir
    serset use, clear
    save data_for_margins_plot, replace
    The file data_for_margins_plot will contain the data on the predictive margins and the upper and lower confidence limits, with readily recognizable names. The variable that goes on the horizontal axis will be named bizarrely, probably something like __000000, but you can rename it. Then you can write whatever graph commands you want for this data.

    Note: An alternative approach uses the undocumented -saving()- option of -margins-. This, too, saves the data that the margins plot is based on. But there is a lot of other stuff in there, and it is not always easy to identify what variable names in that data set corresponds to the things you want to plot. The -serset- based approach gives you all and only the data you need for the plot and most of it is clearly named.

    Added: This use of -serset- commands is not restricted to -marginsplot- graphs. Any Stata graph that has been -graph use-d creates a serset that contains exactly the data underlying the plot and can be accessed in this way. This enables you to revise the graph using any graph commands you like.
    Last edited by Clyde Schechter; 18 Apr 2024, 18:45.

    Comment


    • #3
      Clyde Schechter I highly appreciate your help. It worked perfectly. I will use the -serset- commands, which will save me a lot of time and avoid any potential mistake using the -asdoc- approach I thought was the only way to get that data. And knowing that -serset- also works with other graphs is great I had a bad experience with some old works of losing the original dataset but having the Graph file, then now I can recover the data used for those graphs. Many thanks for this.

      Comment

      Working...
      X