Announcement

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

  • Marginal effects eydx of dummy variables

    Suppose that we have a linear regression model E[y|x] = a +bx, where x is a dummy variable. Why does Stata calculate the proportional marginals of dummy variables (eydx) calculated as:
    ln(y(x=1)) - ln(y(x=0)) ? Would it be meaningful to calculate the margins manually as (y(x=1) - y(x=0))/ y(x=0) instead, so that the marginal effect is interpreted as the average proportional gain or loss from going from x=0 to x=1, for an individual for whom x=0. That is, if this calculation is 0.09, a subject with x=0 would gain, on average, 9% more of y if x=1 instead. Would this make sense? Any help is appreciated. Thank you!

  • #2
    Why does Stata calculate the proportional marginals of dummy variables (eydx) calculated as:
    ln(y(x=1)) - ln(y(x=0)) ?
    I don't believe that is what Stata does if you properly specify the indicator ("dummy") variable using factor variable notation. If you used factor variable notation correctly, I believe the -margins- command does calculate (y(x=1) - y(x=0))/ y(x=0).

    In any case, if the semi-elasticity is close to zero, the two formulas give almost the same results, to a couple of decimal places. That comes from taking the Taylor series for ln and stopping at the linear term. This approximation breaks down, however, once we get beyond about 0.1.

    Added: Hmm, no. Your observation seems to be correct. It's actually the opposite of what I said. If you use factor variable notation you get the difference of logarithms, and if you don't use it you get the relative difference calculated directly. That's strange--it should be the other way around, I believe. But here it is:
    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    .
    . //  WITH FACTOR VARIABLE NOTATION
    . regress mpg i.foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =     13.18
           Model |  378.153515         1  378.153515   Prob > F        =    0.0005
        Residual |  2065.30594        72  28.6848048   R-squared       =    0.1548
    -------------+----------------------------------   Adj R-squared   =    0.1430
           Total |  2443.45946        73  33.4720474   Root MSE        =    5.3558
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
         foreign |
        Foreign  |   4.945804   1.362162     3.63   0.001     2.230384    7.661225
           _cons |   19.82692   .7427186    26.70   0.000     18.34634    21.30751
    ------------------------------------------------------------------------------
    
    . margins foreign
    
    Adjusted predictions                                        Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
         foreign |
       Domestic  |   19.82692   .7427186    26.70   0.000     18.34634    21.30751
        Foreign  |   24.77273   1.141865    21.69   0.000     22.49646    27.04899
    ------------------------------------------------------------------------------
    
    . matrix M = r(table)
    
    . display (M["b", "1.foreign"]-M["b", "0.foreign"]) / M["b", "0.foreign"]
    .2494489
    
    . margins, eydx(foreign)
    
    Conditional marginal effects                                Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    ey/dx wrt:  1.foreign
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      ey/dx   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
         foreign |
        Foreign  |   .2227026    .059396     3.75   0.000     .1042989    .3411063
    ------------------------------------------------------------------------------
    Note: ey/dx for factor levels is the discrete change from the base level.
    
    .
    .
    . //  WITHOUT FACTOR VARIABLE NOTATION
    . regress mpg foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =     13.18
           Model |  378.153515         1  378.153515   Prob > F        =    0.0005
        Residual |  2065.30594        72  28.6848048   R-squared       =    0.1548
    -------------+----------------------------------   Adj R-squared   =    0.1430
           Total |  2443.45946        73  33.4720474   Root MSE        =    5.3558
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
         foreign |   4.945804   1.362162     3.63   0.001     2.230384    7.661225
           _cons |   19.82692   .7427186    26.70   0.000     18.34634    21.30751
    ------------------------------------------------------------------------------
    
    . margins, at(foreign = (0 1))
    
    Adjusted predictions                                        Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    1._at: foreign = 0
    2._at: foreign = 1
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |     Margin   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             _at |
              1  |   19.82692   .7427186    26.70   0.000     18.34634    21.30751
              2  |   24.77273   1.141865    21.69   0.000     22.49646    27.04899
    ------------------------------------------------------------------------------
    
    . matrix M = r(table)
    
    . display log(M["b", "2._at"]) - log(M["b", "1._at"])
    .22270258
    
    . margins, eydx(foreign) at(foreign = 0)
    
    Conditional marginal effects                                Number of obs = 74
    Model VCE: OLS
    
    Expression: Linear prediction, predict()
    ey/dx wrt:  foreign
    At: foreign = 0
    
    ------------------------------------------------------------------------------
                 |            Delta-method
                 |      ey/dx   std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
         foreign |   .2494489   .0742122     3.36   0.001     .1015095    .3973883
    ------------------------------------------------------------------------------
    Bug?
    Last edited by Clyde Schechter; 04 Feb 2022, 23:17.

    Comment


    • #3
      Thank you so much Clyde!!! I will make sure I do not use the factor variable notation for dummy variables to calculate eydx then.

      Comment


      • #4
        I contacted Stata about this. They made the following post inc ase anyone is interested: https://blog.stata.com/2022/04/05/us...rithm-changes/

        Comment

        Working...
        X