Announcement

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

  • Marginsplot not working

    I would like to display a plot with the average marginal effect of nb_ygsibs5 with 95% CIs.

    This is what I do :
    Code:
    reg mort5 nb_ygsibs5 nb_ygsibs_fem female urban yob RBR birth_sp yobm twin educlvl
    margins
    marginsplot
    But then the graph looks like this :
    Click image for larger version

Name:	Graph1111.png
Views:	1
Size:	19.6 KB
ID:	1498485


    But I would like to have the effects on mort5 on the Y axis and nb_ygsibs5 on the X axis.

    What command can I use ?

    Attached Files

  • #2
    The marginsplot command plots the output from the previous margins command. Your margins command produced only a single overall prediction at the mean of all the independent variables, including nb_ygsibs5. You need to request margins at a range of values of nb_ygsibs5. Below is an example that first reproduces the sort of plot you achieved, and then produces the sort I think you wanted.
    Code:
    sysuse auto, clear
    regress weight length
    margins
    marginsplot
    margins, at(length=(150(25)225))
    marginsplot
    We note that the first margins command produces the following output
    Code:
    . margins
    
    Predictive margins                              Number of obs     =         74
    Model VCE    : OLS
    
    Expression   : Linear prediction, predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           _cons |   3019.459   29.48784   102.40   0.000     2960.677    3078.242
    ------------------------------------------------------------------------------
    while the second margins command is more voluble
    Code:
    . margins, at(length=(150(25)225))
    
    Adjusted predictions                            Number of obs     =         74
    Model VCE    : OLS
    
    Expression   : Linear prediction, predict()
    
    1._at        : length          =         150
    
    2._at        : length          =         175
    
    3._at        : length          =         200
    
    4._at        : length          =         225
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |   1766.935   58.54605    30.18   0.000     1650.226    1883.645
              2  |   2592.432   34.15957    75.89   0.000     2524.336    2660.528
              3  |   3417.929    33.5922   101.75   0.000     3350.964    3484.894
              4  |   4243.426   57.55275    73.73   0.000     4128.697    4358.155
    ------------------------------------------------------------------------------
    If you are not already familiar with these papers, you may find useful the nice overview of margins prepared by Richard Williams, a frequent contributor here, at https://www3.nd.edu/~rwilliam/xsoc73994/Margins01.pdf with a more detailed paper in the Stata Journal at http://www.stata-journal.com/article...article=st0260. I'll also note that Margins01.pdf is followed by Margins02.pdf ... Margins05.pdf covering more specialized topics.

    And all five of these PDFs, and plenty more of use to someone learning about the analysis of categorical data, are linked to from https://www3.nd.edu/~rwilliam/xsoc73994/index.html - the material mentioned above is found in the section headed Interpreting results: Adjusted Predictions and Marginal effects.

    Comment

    Working...
    X