Announcement

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

  • Interaction dummy-continuous variable: Preventing the automatic inclusion of the continuous variable

    The specification I would like is the following:
    y = a + b x + c d*z

    where x and z are continuous variable and d a dummy. Now I know that there are arguments against having the interaction without the interacted terms on their own (i.e. not including z as such in this case) but I believe that in my case this is appropriate.
    The problem is that the command
    Code:
    reg y x i.d#c.z
    automatically includes z as a variable, meaning it is equivalent to the command
    Code:
    reg y x z i.d#c.z
    I have not been able to find any way around this. I should also mention that the "naive" way of solving this by creating the interaction by hand is very problematic in my case because I very much need to use margins after the estimation, which is made impossible by that solution.

    Thank you for your help!

  • #2
    The example below attempts to reproduce the problem, but regress dose not include the continuous variable separately, so I'm not sure I understand the statement of your problem.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . regress price weight i.foreign#c.mpg
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(3, 70)        =     18.57
           Model |   281459158         3  93819719.5   Prob > F        =    0.0000
        Residual |   353606238        70  5051517.68   R-squared       =    0.4432
    -------------+----------------------------------   Adj R-squared   =    0.4193
           Total |   635065396        73  8699525.97   Root MSE        =    2247.6
    
    -------------------------------------------------------------------------------
            price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    --------------+----------------------------------------------------------------
           weight |    2.70761    .614654     4.41   0.000     1.481721    3.933499
                  |
    foreign#c.mpg |
        Domestic  |  -87.42007   77.51779    -1.13   0.263    -242.0244    67.18428
         Foreign  |   36.07147    79.5086     0.45   0.651    -122.5034    194.6464
                  |
            _cons |  -1057.949   3289.443    -0.32   0.749    -7618.535    5502.637
    -------------------------------------------------------------------------------

    Comment


    • #3
      Does this do what you want?

      Code:
      webuse nhanes2f, clear
      constraint 1 tibc = 0
      cnsreg weight height tibc i.female#c.tibc, constraint(1)
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      Stata Version: 17.0 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Or else maybe

        Code:
        webuse nhanes2f, clear
        reg weight height 1.female#c.tibc
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        Stata Version: 17.0 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment


        • #5
          Note that both of the above produce the same results as

          Code:
          webuse nhanes2f, clear
          gen femtibc = fem *tibc
          reg weight height femtibc
          Factor variable notation can be tricky and confusing, especially if you are trying to do something a little unconventional. Constraints are one way of forcing unwanted coefficients to be 0, but I suspect there are usually other ways using only factor variable notation.
          -------------------------------------------
          Richard Williams, Notre Dame Dept of Sociology
          Stata Version: 17.0 MP (2 processor)

          EMAIL: [email protected]
          WWW: https://www3.nd.edu/~rwilliam

          Comment


          • #6
            Originally posted by William Lisowski View Post
            The example below attempts to reproduce the problem, but regress dose not include the continuous variable separately, so I'm not sure I understand the statement of your problem.
            So it actually doesn't, and I think that Statas somewhat confusing notation can be blamed here. Indeed if you run
            Code:
            regress price weight mpg i.foreign#c.mpg
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(3, 70)        =     18.57
                   Model |   281459158         3  93819719.5   Prob > F        =    0.0000
                Residual |   353606238        70  5051517.68   R-squared       =    0.4432
            -------------+----------------------------------   Adj R-squared   =    0.4193
                   Total |   635065396        73  8699525.97   Root MSE        =    2247.6
            
            -------------------------------------------------------------------------------
                    price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            --------------+----------------------------------------------------------------
                   weight |    2.70761    .614654     4.41   0.000     1.481721    3.933499
                      mpg |  -87.42007   77.51779    -1.13   0.263    -242.0244    67.18428
                          |
            foreign#c.mpg |
                 Foreign  |   123.4915   28.45584     4.34   0.000     66.73816    180.2449
                          |
                    _cons |  -1057.949   3289.443    -0.32   0.749    -7618.535    5502.637
            -------------------------------------------------------------------------------
            you see that the "Domestic" coefficient on your specification is the one of the continuous variable.
            Last edited by Simon Loewe; 05 Jul 2018, 02:01.

            Comment


            • #7
              Originally posted by Richard Williams View Post
              Or else maybe

              Code:
              webuse nhanes2f, clear
              reg weight height 1.female#c.tibc
              Thank you for your quick answer. This option does seem to work. I didn't think of doing it in that way at all, but I tried using the omitted notation of factor variables, which didn't work.

              Anyway thank you very much for your help.

              Comment

              Working...
              X