Announcement

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

  • Marginsplot - marginal effects for multiple dependent variables

    Hi Statalists,

    I'm estimating a model using:
    Code:
    reg Y i.treatment, robust
    margins, dydx(treatment)
    marginsplot, horizontal
    I'm trying to generate a graph for a placebo test displaying marginal effects for my regression of the effect of treatment (X) on four different Y variables.

    I've managed to create four separate graphs for each dependent variable, however, I'm struggling with how to put them all in the same graph (i.e. one graph showcasing four lines of the marginal effect for each of the four dependent variables). Essentially, I want it to look similar to this:

    Click image for larger version

Name:	Screenshot 2024-04-25 at 11.12.13.png
Views:	2
Size:	460.9 KB
ID:	1751228

    Anyone know the code for how to make one graph showing marginal effects for multiple dependent variables?

    In addition, I'm trying to create another graph displaying the marginal effects of the effect of treatment (X) on one dependent variable Y for three groups: women, men, and overall effect. It should look something like this:


    Click image for larger version

Name:	Screenshot 2024-04-25 at 11.16.16.png
Views:	2
Size:	253.8 KB
ID:	1751230

    I've managed to get the marginal effects for men and women using this code below, however, I'm struggling to add the full sample:

    Code:
    reg Y i.treatment##i.sex, rob 
    margins, dydx(treatment) at(sex=(0 1))
    marginsplot, recast(scatter)
    Anyone know the code for adding a line for the full sample (0 + 1) on the graph?

    Kind regards

    Attached Files

  • #2
    See coefplot from SSC.

    Code:
    ssc describe coefplot
    Also, to increase your chances of obtaining helpful replies, you need to present reproducible examples. Refer to FAQ Advice #12 and

    Code:
    help dataex

    Comment

    Working...
    X