Announcement

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

  • -margins, dydx- with a log-transformed covariate

    Hello,

    I am estimating a panel data model as follows:
    Code:
    xtreg y c.x_log##c.m##c.z
    where x_log is the natural logarithm of x, and m and z are continuous moderators. I want to obtain the marginal effect of x (not x_log) on y, for a grid of m and z values. So, -margins, dydx(x_log) at(m=(0(1)10) z=(0 1))- would not work.
    I understand the effect of a one-unit increase in x is:
    dydx = (_b[x_log] + _b[c.x_log#c.m]*m + _b[c.x_log#c.z]*z + _b[c.x_log#c.m#c.z]*m*z) / x

    Would it be correct to use the following -margins- command to calculate the marginal effect of x (not x_log)?
    Code:
    margins, at(m = (0(1)10) z = (0 1)) expression((_b[x_log] + _b[c.x_log#c.m]*m + _b[c.x_log#c.z]*z + _b[c.x_log#c.m#c.z]*m*z) / x)
    Thanks.

  • #2
    Code:
    clear all
    
    sysuse auto, clear
    
    summ weight
    local wgt = r(mean)
    
    reg mpg weight
    
    reg mpg weight_log
    
    di _b[weight_log] / `wgt'
    
    
    . reg mpg weight
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =    134.62
           Model |   1591.9902         1   1591.9902   Prob > F        =    0.0000
        Residual |  851.469256        72  11.8259619   R-squared       =    0.6515
    -------------+----------------------------------   Adj R-squared   =    0.6467
           Total |  2443.45946        73  33.4720474   Root MSE        =    3.4389
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
          weight |  -.0060087   .0005179   -11.60   0.000    -.0070411   -.0049763
           _cons |   39.44028   1.614003    24.44   0.000     36.22283    42.65774
    ------------------------------------------------------------------------------
    
    
    . reg mpg weight_log
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(1, 72)        =    147.33
           Model |  1641.35428         1  1641.35428   Prob > F        =    0.0000
        Residual |  802.105178        72  11.1403497   R-squared       =    0.6717
    -------------+----------------------------------   Adj R-squared   =    0.6672
           Total |  2443.45946        73  33.4720474   Root MSE        =    3.3377
    
    ------------------------------------------------------------------------------
             mpg | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
      weight_log |  -17.80317   1.466715   -12.14   0.000    -20.72702   -14.87933
           _cons |   163.3444   11.70898    13.95   0.000      140.003    186.6858
    ------------------------------------------------------------------------------
    
    . di _b[weight_log] / `wgt'
    -.00589615

    Comment

    Working...
    X