Announcement

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

  • DiD Model with multiple interactions

    Hi!

    I am running a DiD model with multiple interactions and want to plot them using the margins, dydx() command.
    More specifically I am looking into how turnout changes after a payment is introduced in a specific state relative to all other states.

    the normal DiD model (without additional interactions) looks like this:

    Code:
     reg y i.post##i.treated i.year i.state education othercontrolvars, vce(cluster state)
    Now I want to display the marginal effect of the treatment (a payment) on turnout at different levels of educational attainment.

    Code:
     (A) reg y i.post##i.treated##c.education i.year i.state othercontrolvars, vce(cluster state)
    To simplify this (and be able to use the margins command) I decided to generate a payment variable which is the interaction of post*treated=payment

    Code:
     gen payment=post*treated
    (B) reg y post treatyear i.payment##c.education i.year i.state othercontrolvars, vce(cluster state)
    margins, dydx(payment) at(education=(0(1)7))
    marginsplot
    Running (A)- i.post##i.treated##c.education and running (B)- i.payment##c.education however leads to different results.
    Can someone explain to me why this is the case?

    Thank you!

    Best
    Hannah
    Last edited by Hannah Pareik; 10 Mar 2022, 09:13.

  • #2
    Originally posted by Hannah Pareik View Post
    gen payment=post*treated
    A categorical by categorical interaction is not a single variable, even in the case where both variables are binary. For two 0/1 binary variables, the interaction leads to 4 variables:

    Code:
    0#0
    0#1
    1#0
    1#1

    A straight multiplication works for two continuous variables or a binary and continuous variable.

    Comment


    • #3
      Hi Andrew,

      thank you for clarifying!

      Do you know what I could to instead / do you know how I can run the margins, dydx command for the payment then?

      The following command does not work so I was was wondering how I could implement this in order to plot the marginal effect of the payment by different levels of education.

      Code:
      margins, dydx(post#treated) at(education=(0(1)7))
      Thank you!
      Best
      Hannah

      Comment


      • #4
        Originally posted by Hannah Pareik View Post

        Code:
        margins, dydx(post#treated) at(education=(0(1)7))
        You cannot have a marginal effect for an interaction because it is not possible to change the interaction by one unit holding constant all other variables, where all other variables include the variables used to create the interaction. Therefore, there is no notion of a marginal effect for an interaction term. In case you want to disassociate the interaction terms from the variables defining the interaction, as implied in #1, you can do so specifying the full set of interactions and replicating the underlying regression. Here is how.

        Code:
        webuse nlswork, clear
        set seed 03112022
        keep if idcode<10
        gen treat = idcode > 5
        gen byte post = year >= 80
        gen education = runiformint(1,7)
        *SIMILAR TO YOUR REGRESSION
        reg y i.post##i.treat##c.education i.idcode
        *FULL SET OF INTERACTIONS
        gen pay00= 0.post#0.treat
        gen pay01= 0.post#1.treat
        gen pay10= 1.post#0.treat
        gen pay11= 1.post#1.treat
        *RECREATE REGRESSION
        regress y post treat education c.pay01#c.treat  c.pay01#c.education c.pay10#c.treat  c.pay10#c.education c.pay11#c.treat c.pay11#c.education i.idcode
        *MARGINS
        margins, dydx(pay??) at(education=(1/7))
        marginsplot, recast(line) scheme(s1color)
        Res.:

        Code:
        . *SIMILAR TO YOUR REGRESSION
        
        . 
        . reg y i.post##i.treat##c.education i.idcode
        note: 9.idcode omitted because of collinearity
        
              Source |       SS           df       MS      Number of obs   =        97
        -------------+----------------------------------   F(13, 83)       =     25.41
               Model |  3131.91474        13  240.916519   Prob > F        =    0.0000
            Residual |  786.971856        83  9.48158863   R-squared       =    0.7992
        -------------+----------------------------------   Adj R-squared   =    0.7677
               Total |   3918.8866        96  40.8217354   Root MSE        =    3.0792
        
        ----------------------------------------------------------------------------------------
                          year |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        -----------------------+----------------------------------------------------------------
                        1.post |   11.15809   2.011975     5.55   0.000     7.156349    15.15982
                       1.treat |  -2.152177   1.994364    -1.08   0.284    -6.118886    1.814532
                               |
                    post#treat |
                          1 1  |    2.69253   3.367028     0.80   0.426    -4.004353    9.389413
                               |
                     education |   .2272526   .2852377     0.80   0.428    -.3400737    .7945789
                               |
              post#c.education |
                            1  |  -.1266925   .4573676    -0.28   0.782    -1.036378    .7829933
                               |
             treat#c.education |
                            1  |   .2858844   .4266369     0.67   0.505    -.5626792    1.134448
                               |
        post#treat#c.education |
                          1 1  |   -.315252   .7020794    -0.45   0.655     -1.71166    1.081156
                               |
                        idcode |
                            2  |  -.0686068   1.279731    -0.05   0.957     -2.61394    2.476727
                            3  |  -1.143307   1.238566    -0.92   0.359    -3.606765    1.320151
                            4  |  -1.190976   1.352399    -0.88   0.381    -3.880843    1.498892
                            5  |  -1.984296   1.368529    -1.45   0.151    -4.706244    .7376534
                            6  |  -.7973263   1.179724    -0.68   0.501    -3.143749    1.549096
                            7  |  -1.481915   1.413745    -1.05   0.298    -4.293797    1.329967
                            9  |          0  (omitted)
                               |
                         _cons |   73.14695   1.249922    58.52   0.000     70.66091      75.633
        ----------------------------------------------------------------------------------------
        
        . 
        . *RECREATE REGRESSION
        
        . 
        . regress y post treat education c.pay01#c.treat  c.pay01#c.education c.pay10#c.treat  c.pay10#c.education c.pay11#c.treat c.pay11#c
        > .education i.idcode
        note: c.pay10#c.treat omitted because of collinearity
        note: c.pay11#c.treat omitted because of collinearity
        note: 9.idcode omitted because of collinearity
        
              Source |       SS           df       MS      Number of obs   =        97
        -------------+----------------------------------   F(13, 83)       =     25.41
               Model |  3131.91474        13  240.916519   Prob > F        =    0.0000
            Residual |  786.971856        83  9.48158863   R-squared       =    0.7992
        -------------+----------------------------------   Adj R-squared   =    0.7677
               Total |   3918.8866        96  40.8217354   Root MSE        =    3.0792
        
        -------------------------------------------------------------------------------------
                       year |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        --------------------+----------------------------------------------------------------
                       post |   11.15809   2.011975     5.55   0.000     7.156349    15.15982
                      treat |   .5403531    2.96346     0.18   0.856    -5.353849    6.434555
                  education |   .2272526   .2852377     0.80   0.428    -.3400737    .7945789
                            |
            c.pay01#c.treat |   -2.69253   3.367028    -0.80   0.426    -9.389413    4.004353
                            |
        c.pay01#c.education |   .2858844   .4266369     0.67   0.505    -.5626792    1.134448
                            |
            c.pay10#c.treat |          0  (omitted)
                            |
        c.pay10#c.education |  -.1266925   .4573676    -0.28   0.782    -1.036378    .7829933
                            |
            c.pay11#c.treat |          0  (omitted)
                            |
        c.pay11#c.education |  -.1560601   .5138954    -0.30   0.762    -1.178177    .8660572
                            |
                     idcode |
                         2  |  -.0686068   1.279731    -0.05   0.957     -2.61394    2.476727
                         3  |  -1.143307   1.238566    -0.92   0.359    -3.606765    1.320151
                         4  |  -1.190976   1.352399    -0.88   0.381    -3.880843    1.498892
                         5  |  -1.984296   1.368529    -1.45   0.151    -4.706244    .7376534
                         6  |  -.7973263   1.179724    -0.68   0.501    -3.143749    1.549096
                         7  |  -1.481915   1.413745    -1.05   0.298    -4.293797    1.329967
                         9  |          0  (omitted)
                            |
                      _cons |   73.14695   1.249922    58.52   0.000     70.66091      75.633
        -------------------------------------------------------------------------------------

        Comment

        Working...
        X