Announcement

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

  • How to use -margins- to interpret linear models with very high order interactions, say 4th and 5th order interactions?

    Good afternoon,

    We are contemplating a linear model that reached very high order of interactions, by now we are about at 4th and 5th order interactions. Think of something like:
    Y = a + b1*X + b2*Z + b3*W + c1*X*Z + c2*X*W + c3*Z*W + d*X*Z*W + e,
    but this thing done up to 4th and 5th level of interactions.

    Estimating such models is trivial. What is a pain is to make sense after that of what you have estimated. For up to 3rd level interactions I just take derivatives, say d[EY]/dX = b1 + c1*Z + c2*W + d*Z*W, and I interpret the marginal effect of X on the EY through this derivative.

    I do not really want to do that for 4th and 5th level interaction models. I know that -margins- can be used to make sense of such models.

    Can you suggest how I go about to learning how to use -margins- in such high level interactions models?

  • #2
    Hi Joro
    Not sure what is th e problem you are facing
    if you estimate the model, regardless of how many times it is interacted, just typing
    margins, dydx(var)
    should produce what you want.
    are you having problems with this approach?

    Comment


    • #3
      Originally posted by FernandoRios View Post
      Hi Joro
      Not sure what is th e problem you are facing
      if you estimate the model, regardless of how many times it is interacted, just typing
      margins, dydx(var)
      should produce what you want.
      are you having problems with this approach?
      Hi Fernando, I think that far I know, I think I have done this
      margins, dydx(var) at(points)

      I am looking for some sort of a best practice and advanced use of -margins-.

      Look at my example in #1. Say my main variable of interest is X, and Z is binary, and W is a continuous control. What I would do is
      1. Plot the derivative d(EY)/dX at say Z=1 and Z=0, and for interesting points of W, say median and 75th percentile.
      2. Evaluate whether the derivative is significant at said points of Z, W, and at chosen important points of X.
      3. Produce some confidence intervals following 2., etc.

      So my question was more on this more "advanced" used of -margins-. And probably a good reading which explains such use, and probably user contributed packages which facilitate such use.

      Comment


      • #4
        Joro, my reaction is that with the use of such high-order interactions you are moving in the direction of series or nonparametric regression and might consider interpreting your results accordingly.

        https://www.stata.com/features/overv...es-regression/

        Consider two examples. The first uses two 0-1 dummy variables and one continuous variable as covariates; the second uses three 0-1 variables as covariates. In the first case the nonparametric results are roughly similar to the interaction model's margins results; in the second case they are identical.
        Code:
        set seed 2345
        
        set obs 500
        
        forval j=1/2 {
         gen x`j'=uniform()>.5
        }
        
        gen x3a=uniform()
        gen x3b=uniform()>.5
        
        gen ya=x1+x2+x3a+rnormal()
        gen yb=x1+x2+x3b+rnormal()
        
        qui reg ya x1##x2##c.x3a, vce(robust)
        margins, dydx(*)
        npregress series ya i.(x1 x2) x3a
        
        qui reg yb x1##x2##x3b, vce(robust)
        margins, dydx(*)
        npregress series yb i.(x1 x2 x3b)
        Results:
        Code:
        .
        . qui reg ya x1##x2##c.x3a, vce(robust)
        
        . margins, dydx(*)
        
        Average marginal effects                                   Number of obs = 500
        Model VCE: Robust
        
        Expression: Linear prediction, predict()
        dy/dx wrt:  1.x1 1.x2 x3a
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                1.x1 |   .9505992   .0882261    10.77   0.000     .7772528    1.123946
                1.x2 |   .8961316   .0878443    10.20   0.000     .7235352    1.068728
                 x3a |   1.364333   .1519637     8.98   0.000     1.065755    1.662911
        ------------------------------------------------------------------------------
        Note: dy/dx for factor levels is the discrete change from the base level.
        
        . npregress series ya i.(x1 x2) x3a
        
        Computing approximating function
        
        Minimizing cross-validation criterion
        
        Iteration 0:  Cross-validation criterion =  1.007096
        
        Computing average derivatives
        
        Cubic B-spline estimation                  Number of obs      =            500
        Criterion: cross-validation                Number of knots    =              1
        ------------------------------------------------------------------------------
                     |               Robust
                  ya |     Effect   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                  x1 |
           (1 vs 0)  |   .9675273   .0894778    10.81   0.000      .792154    1.142901
                     |
                  x2 |
           (1 vs 0)  |   .9027294   .0881242    10.24   0.000     .7300092     1.07545
                 x3a |   1.100125   .2934568     3.75   0.000     .5249598    1.675289
        ------------------------------------------------------------------------------
        Note: Effect estimates are averages of derivatives for continuous covariates and averages of
              contrasts for factor covariates.
        
        .
        . qui reg yb x1##x2##x3b, vce(robust)
        
        . margins, dydx(*)
        
        Average marginal effects                                   Number of obs = 500
        Model VCE: Robust
        
        Expression: Linear prediction, predict()
        dy/dx wrt:  1.x1 1.x2 1.x3b
        
        ------------------------------------------------------------------------------
                     |            Delta-method
                     |      dy/dx   std. err.      t    P>|t|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                1.x1 |   .8740968   .0905656     9.65   0.000     .6961538     1.05204
                1.x2 |   .9139274   .0901445    10.14   0.000     .7368116    1.091043
               1.x3b |   .8633006   .0912618     9.46   0.000     .6839897    1.042611
        ------------------------------------------------------------------------------
        Note: dy/dx for factor levels is the discrete change from the base level.
        
        . npregress series yb i.(x1 x2 x3b)
        
        Computing approximating function
        
        Minimizing cross-validation criterion
        
        Iteration 0:  Cross-validation criterion =  1.020892
        
        Computing average derivatives
        
        Cubic B-spline estimation                  Number of obs      =            500
        Criterion: cross-validation                Number of knots    =              0
        ------------------------------------------------------------------------------
                     |               Robust
                  yb |     Effect   std. err.      z    P>|z|     [95% conf. interval]
        -------------+----------------------------------------------------------------
                  x1 |
           (1 vs 0)  |   .8740968   .0905656     9.65   0.000     .6965915    1.051602
                     |
                  x2 |
           (1 vs 0)  |   .9139274   .0901445    10.14   0.000     .7372473    1.090607
                     |
                 x3b |
           (1 vs 0)  |   .8633006   .0912618     9.46   0.000     .6844308     1.04217
        ------------------------------------------------------------------------------
        Note: Effect estimates are averages of contrasts of factor covariates.

        Comment

        Working...
        X