Announcement

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

  • interaction term iw

    Hello everyone.
    I have a question regarding the interaction of a dummy with a continuous variable in a regression.

    I noticed that when I run the following commands


    Code:
    clear all
    set obs 1000
    set seed 123
    gen y=rnormal()
    gen x2=rnormal()
    gen dum = runiform() > 0.5
    reg y i.dum i.dum#c.x2
    I get the following output which is puzzling because I have a value for i.dum#c.x2 when dum=0

    Code:
    
          Source |       SS           df       MS      Number of obs   =     1,000
    -------------+----------------------------------   F(3, 996)       =      2.11
           Model |  5.95919858         3  1.98639953   Prob > F        =    0.0974
        Residual |  937.796739       996  .941562991   R-squared       =    0.0063
    -------------+----------------------------------   Adj R-squared   =    0.0033
           Total |  943.755937       999  .944700638   Root MSE        =    .97034
    
    ------------------------------------------------------------------------------
               y |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
           1.dum |  -.1102455   .0614268    -1.79   0.073    -.2307863    .0102952
                 |
        dum#c.x2 |
              0  |     .07283   .0439866     1.66   0.098    -.0134871     .159147
              1  |  -.0318478   .0414672    -0.77   0.443    -.1132208    .0495252
                 |
           _cons |   .0769639    .043772     1.76   0.079    -.0089321    .1628599
    ------------------------------------------------------------------------------
    I understood that is the same result when I include also x2 alone in a regression like:
    Code:
    reg y i.dum i.dum#c.x2 x2
    so it is like adding the x2 variable alone.

    Is there a way to write the regression so that i.dum is interacted with x2 but omitting the calculation for i.dum#c.x2 when dum=0 ?

    I know I could manually write a new variable like dum_x2=dum*x2, but I need to keep them separated to calculate margins with the margins code

    Any help would be so much appreciated!

  • #2
    Code:
     
     reg y dum c.dum#c.x2

    Comment


    • #3
      That was so easy, I don't know why did not think about it before. Probably that's why one should not do research the 12th of august.
      Thank you George.

      Comment


      • #4
        You could also explicitly declare "dum=0" to be omitted from the interaction term by using the "o." operator, so margins can recognise "dum" as a categorical variable rather than continuous and will compute "the discrete change" for it.
        .
        Code:
        reg y i.dum o0.dum#c.x2 c.x2
        margins, dydx(*)
        Code:
        help fvvarlist

        Comment

        Working...
        X