Announcement

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

  • Testing interaction term?

    Dear All, How can I test whether the interaction term (c.mpg#i.foreign) of the following regression is 0? Thanks.
    Code:
    sysuse auto, clear
    reg price mpg foreign c.mpg#i.foreign
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    I just found that the following might be the answer.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . 
    . reg price mpg foreign c.mpg#i.foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(3, 70)        =      9.48
           Model |   183435281         3  61145093.6   Prob > F        =    0.0000
        Residual |   451630115        70  6451858.79   R-squared       =    0.2888
    -------------+----------------------------------   Adj R-squared   =    0.2584
           Total |   635065396        73  8699525.97   Root MSE        =    2540.1
    
    -------------------------------------------------------------------------------
            price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    --------------+----------------------------------------------------------------
              mpg |  -329.2551   74.98545    -4.39   0.000    -478.8088   -179.7013
          foreign |  -13.58741   2634.664    -0.01   0.996    -5268.258    5241.084
                  |
    foreign#c.mpg |
         Foreign  |   78.88826   112.4812     0.70   0.485    -145.4485     303.225
                  |
            _cons |   12600.54   1527.888     8.25   0.000     9553.261    15647.81
    -------------------------------------------------------------------------------
    
    . test c.mpg#i1.foreign = 0
    
     ( 1)  1.foreign#c.mpg = 0
    
           F(  1,    70) =    0.49
                Prob > F =    0.4854
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

    Comment


    • #3
      testparm is often easier when using factor variable notation. You don't have to figure out what the factor variable notation expanded to. It would be especially easier if, say, foreign had more than two categories.

      Code:
      . testparm c.mpg#i.foreign
      
       ( 1)  1.foreign#c.mpg = 0
      
             F(  1,    70) =    0.49
                  Prob > F =    0.4854
      Another example where testparm is even more useful:

      Code:
      . sysuse auto, clear
      (1978 Automobile Data)
      
      . reg price mpg i.rep78 c.mpg#i.rep78
      
            Source |       SS           df       MS      Number of obs   =        69
      -------------+----------------------------------   F(9, 59)        =      3.65
             Model |   206362465         9  22929162.7   Prob > F        =    0.0011
          Residual |   370434494        59  6278550.75   R-squared       =    0.3578
      -------------+----------------------------------   Adj R-squared   =    0.2598
             Total |   576796959        68  8482308.22   Root MSE        =    2505.7
      
      ------------------------------------------------------------------------------
             price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               mpg |  -123.1667      590.6    -0.21   0.836    -1304.955    1058.621
                   |
             rep78 |
                2  |   10881.12   13452.68     0.81   0.422    -16037.64    37799.87
                3  |   8973.281   12725.58     0.71   0.483    -16490.55    34437.11
                4  |   651.7399    12823.1     0.05   0.960    -25007.23    26310.71
                5  |   4363.191   12794.52     0.34   0.734    -21238.58    29964.96
                   |
       rep78#c.mpg |
                2  |  -507.6563   642.1123    -0.79   0.432     -1792.52    777.2075
                3  |  -375.7209   601.1921    -0.62   0.534    -1578.704    827.2618
                4  |   43.26329   603.3025     0.07   0.943    -1163.942    1250.469
                5  |  -81.52802     597.53    -0.14   0.892    -1277.183    1114.127
                   |
             _cons |       7151   12528.52     0.57   0.570    -17918.51    32220.51
      ------------------------------------------------------------------------------
      
      . testparm c.mpg#i.rep78
      
       ( 1)  2.rep78#c.mpg = 0
       ( 2)  3.rep78#c.mpg = 0
       ( 3)  4.rep78#c.mpg = 0
       ( 4)  5.rep78#c.mpg = 0
      
             F(  4,    59) =    2.28
                  Prob > F =    0.0710
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

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

      Comment


      • #4
        Of course, if the interaction is a single term, as it is in the original example, all you have to do is look at its t-value and associated p-value. For a single term, the F value produced by test or testparm is just the square of the t-value reported in the table. (.70^2 = .49)
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

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

        Comment


        • #5
          Dear Richard, Many thanks for the useful suggestion.
          Ho-Chuan (River) Huang
          Stata 19.0, MP(4)

          Comment

          Working...
          X