Announcement

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

  • Average marginal effects with clustered standard errors

    Hi everyone,

    I have just run the code
    Code:
    logistic high_conflict i.ses i.single_parent i.gender i.immigrant i.age, vce(cluster individual_id)
    followed by
    Code:
    margins, dydx(*)
    , but I noticed that the standard errors for the margins command are robust standard errors rather than clustered standard errors. It seems that only the vce(robust) and the vce(unconditional) options are available for average marginal effects, which do not provide the correct confidence intervals for my study. My question is: is it possible to estimate average marginal effects with clustered standard errors in Stata?

    Thank you!

  • #2
    Here is an example of the data:
    Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input float(child ved_SES) long aleneforeldre byte gender long immigrant float age
          1 2 0 1 1  9
          1 2 0 1 1 10
          1 2 0 1 1 11
          2 1 1 1 3 12
          3 2 0 1 1  9
          4 2 1 1 1 10
          5 2 1 1 1 10
          6 2 0 0 1 11
          7 3 0 1 3  8
          7 3 0 1 3  8
          end
          label values aleneforeldre aleneforeldre
          label def aleneforeldre 0 "Partnerskap", modify
          label def aleneforeldre 1 "Aleneforeldre", modify
          label values immigrant immigrant
          label def immigrant 1 "Uten innvandringsbakgrunn", modify
          label def immigrant 3 "2 utenlandsfødte foreldre", modify

    Comment


    • #3
      That is probably a typographical error in the output.
      If you do the math, you can check for yourself that margins is providing Clustered Standard errors after margins.

      Specifically, margins doesn't really re-estimate Standard errors. It simply uses previously obtained ones on its estimations.

      So if logit is estimated using Clustered Standard errors, Margins will simply apply those in the computation

      Comment


      • #4
        A thought: The dydx from margins is not the coefficient after logistic, so the SE and CI must change to reflect that fact.

        Code:
        sysuse auto, clear
        
        logistic foreign mpg weight , vce(cluster rep78)
        margins, dydx(*) 
        
        reg foreign mpg weight , vce(cluster rep78)
        margins, dydx(*)
        Code:
        logistic foreign mpg weight , vce(cluster rep78)
        
        Logistic regression                                     Number of obs =     69
                                                                Wald chi2(2)  =  31.57
                                                                Prob > chi2   = 0.0000
        Log pseudolikelihood = -22.677963                       Pseudo R2     = 0.4652
        
                                          (Std. err. adjusted for 5 clusters in rep78)
        ------------------------------------------------------------------------------
                     |               Robust
             foreign | Odds ratio   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 mpg |   .8586435   .0232937    -5.62   0.000     .8141812    .9055339
              weight |   .9957808   .0007988    -5.27   0.000     .9942164    .9973478
               _cons |    1493883    3035310     7.00   0.000     27849.89    8.01e+07
        ------------------------------------------------------------------------------
        Note: _cons estimates baseline odds.
        
        . margins, dydx(*) 
        
        Average marginal effects                                    Number of obs = 69
        Model VCE: Robust
        
        Expression: Pr(foreign), predict()
        dy/dx wrt:  mpg weight
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 mpg |  -.0157453   .0012612   -12.48   0.000    -.0182173   -.0132734
              weight |  -.0004368   8.18e-06   -53.42   0.000    -.0004529   -.0004208
        ------------------------------------------------------------------------------
        
        
        
        . reg foreign mpg weight , vce(cluster rep78)
        
        Linear regression                               Number of obs     =         69
                                                        F(2, 4)           =      27.15
                                                        Prob > F          =     0.0047
                                                        R-squared         =     0.4299
                                                        Root MSE          =     .35523
        
                                          (Std. err. adjusted for 5 clusters in rep78)
        ------------------------------------------------------------------------------
                     |               Robust
             foreign | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 mpg |  -.0149674   .0038453    -3.89   0.018    -.0256436   -.0042912
              weight |  -.0004669   .0000824    -5.66   0.005    -.0006957    -.000238
               _cons |   2.038506   .4047721     5.04   0.007     .9146782    3.162333
        ------------------------------------------------------------------------------
        
        . margins, dydx(*) 
        
        Average marginal effects                                    Number of obs = 69
        Model VCE: Robust
        
        Expression: Linear prediction, predict()
        dy/dx wrt:  mpg weight
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                 mpg |  -.0149674   .0038453    -3.89   0.018    -.0256436   -.0042912
              weight |  -.0004669   .0000824    -5.66   0.005    -.0006957    -.000238
        ------------------------------------------------------------------------------

        Comment

        Working...
        X