Announcement

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

  • test for equality of absolute value of marginal effects

    Hello and thank you in advance for what is likely a simple answer to a question I am struggling with!

    I am trying to test for the equality of the absolute value of marginal effects in the same regression that have interaction terms. The marginal effects are sometimes negative and sometimes positive but I am only interested in their magnitudes. I have the coding to do the test if all the marginal effects were either positive or negative but the complication of requiring the absolute value of the marginal effects is throwing me for a loop!

    Here is the coding for the regression and the marginal effects:
    quietly xtreg y_var x i.levels i.levels##c.var_x, fe
    margins levels, dydx(var_x) pwcompare(cim) post

    The problem at this point is that the marginal effects are positive and negative. So the pairwise comparison test from Stata will just tell me if the nominal marginal effects differ from each other, not if the difference in the absolute value of the marginal effects differ from one another.

    I have been pursuing two solutions for this problem:
    1. Replacing the post-estimation e(b) matrix with absolute values in all the cells. I can do this with a mata command:
    st_matrix("abs_eb",abs(st_matrix("e(b)")))
    But then I can't figure out how to make Stata use matrix abs_eb instead of e(b) when running a test of equality of the marginal effects. Is this possible? If so, please help with the command for that.

    2. Trying to calculate the test on my own using abs_eb matrix that I created and the var-cov post-estimation matrix but I am having a surprising amount of difficulty with this fairly simple formula. I think the formula for equity of coefficients (or marginal effects) in the same regression is: (B1-B2)/sqrt(VAR(B1)+VAR(B2)-2COV(B1,B2)) where B1 is the estimated coefficient for variable 1. Is this the right formula?

    Thank you very much!

  • #2
    The sign of the coefficient is something that you can specify in the test command.

    Comment


    • #3
      Hello and thank you. The problem is that when you are testing for the equality of marginal effects of a variable that is involved in interaction terms, you can only use the pwcompare option on the margins command, as far as I know. You cannot use the test command. The pwcompare option in the margins command does not allow you to change the sign of the marginal effect, unfortunately. But it does give the actual marginal effects and their variances/covariances. That information should allow me to create the test myself but I am really struggling with how to do that.

      Comment


      • #4
        For your suggestion in #1:

        Code:
        ssc install erepost
        Code:
        sysuse auto, clear
        set seed 01152022
        gen somevar=rnormal()
        regress somevar weight i.rep78##c.mpg disp
        margins rep78, dydx(mpg)
        
        *REPOST e(b)
        local cols: coln e(b)
        mata: st_matrix("b",abs(st_matrix("e(b)")))
        mat colnames b= `cols'
        erepost b=b, rename
        margins rep78, dydx(mpg)
        Res.:

        Code:
        . margins rep78, dydx(mpg)
        
        Average marginal effects                        Number of obs     =         69
        Model VCE    : OLS
        
        Expression   : Linear prediction, predict()
        dy/dx w.r.t. : mpg
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
        mpg          |
               rep78 |
                  1  |  -.1626976   .2787295    -0.58   0.562    -.7208439    .3954486
                  2  |  -.0358381   .1288549    -0.28   0.782    -.2938657    .2221895
                  3  |  -.0126129   .0775983    -0.16   0.871    -.1680008     .142775
                  4  |   .0045003   .0871856     0.05   0.959    -.1700859    .1790865
                  5  |  -.0549541   .0455239    -1.21   0.232    -.1461141    .0362059
        ------------------------------------------------------------------------------
        
        .
        .
        .
        . *REPOST e(b)
        
        .
        . local cols: coln e(b)
        
        .
        . mata: st_matrix("b",abs(st_matrix("e(b)")))
        
        .
        . mat colnames b= `cols'
        
        .
        . erepost b=b, rename
        
        .
        . margins rep78, dydx(mpg)
        Warning: cannot perform check for estimable functions.
        
        Average marginal effects                        Number of obs     =         69
        Model VCE    : OLS
        
        Expression   : Linear prediction, predict()
        dy/dx w.r.t. : mpg
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -------------+----------------------------------------------------------------
        mpg          |
               rep78 |
                  1  |   .1626976   .2787295     0.58   0.562    -.3954486    .7208439
                  2  |   .2895571   .1288549     2.25   0.029     .0315296    .5475847
                  3  |   .3127824   .0775983     4.03   0.000     .1573944    .4681703
                  4  |   .3298956   .0871856     3.78   0.000     .1553094    .5044818
                  5  |   .2704411   .0455239     5.94   0.000     .1792812    .3616011
        ------------------------------------------------------------------------------
        
        .

        Comment


        • #5
          *erepost*
          Brilliant. Thank you. I never would have found that command.

          Comment

          Working...
          X