Announcement

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

  • test and testparm for interaction terms

    reg y x1 x2 x1#x2

    If the coefficient of x1 is significant, the coefficient of x2 is not significant, and the coefficient of x1#x2 is significant. How can I say that there is a joint effect of x1 and x2 on y?

    Should I use the following code 1:
    test x1=x2= x1#x2=0

    or the code 2:
    testparm x1#x2

    or the code 3:
    testparm x1 x2 x1#x2

    What are the differences among those three codes?
    Thanks a lot!

  • #2
    For the joint effect of x1 and x2, code 3 is the one. If, by the way, the only terms in the model are x1, x2, and x1#x2, then even simpler is just the F-test of the entire model (which will give the same result as your code 3), which is shown in the header that precedes the coefficient table in the output.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      For the joint effect of x1 and x2, code 3 is the one. If, by the way, the only terms in the model are x1, x2, and x1#x2, then even simpler is just the F-test of the entire model (which will give the same result as your code 3), which is shown in the header that precedes the coefficient table in the output.
      Thanks so much for the quick response! very helpful! If this is the code 4: test x1 x2 x1#x2. What is the difference between code 3 and code 4?

      Comment


      • #4
        The difference is that, I believe, code 4 will not run. This is -test- will not recognize foreign#rep78, but -testparm- will. See this:
        Code:
        . sysuse auto, clear
        (1978 automobile data)
        
        . regress price foreign rep78 foreign#rep78
        note: 1.foreign#1b.rep78 identifies no observations in the sample.
        note: 1.foreign#2.rep78 identifies no observations in the sample.
        note: 1.foreign#4.rep78 omitted because of collinearity.
        note: 1.foreign#5.rep78 omitted because of collinearity.
        
              Source |       SS           df       MS      Number of obs   =        69
        -------------+----------------------------------   F(7, 61)        =      0.39
               Model |    24684607         7  3526372.43   Prob > F        =    0.9049
            Residual |   552112352        61  9051022.16   R-squared       =    0.0428
        -------------+----------------------------------   Adj R-squared   =   -0.0670
               Total |   576796959        68  8482308.22   Root MSE        =    3008.5
        
        -------------------------------------------------------------------------------
                price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
        --------------+----------------------------------------------------------------
              foreign |   1603.278   5446.764     0.29   0.769      -9288.2    12494.76
                rep78 |   31.22222   1418.217     0.02   0.983    -2804.677    2867.122
                      |
        foreign#rep78 |
          Domestic#2  |   1371.903   2769.156     0.50   0.622    -4165.368    6909.173
          Domestic#3  |    1980.13   3592.504     0.55   0.584    -5203.527    9163.786
          Domestic#4  |   1223.389   4861.401     0.25   0.802    -8497.584    10944.36
          Domestic#5  |  -484.8889   6421.249    -0.08   0.940    -13324.97    12355.19
           Foreign#1  |          0  (empty)
           Foreign#2  |          0  (empty)
           Foreign#3  |  -1401.556   2836.433    -0.49   0.623    -7073.354    4270.243
           Foreign#4  |          0  (omitted)
           Foreign#5  |          0  (omitted)
                      |
                _cons |   4533.278   2556.726     1.77   0.081    -579.2124    9645.768
        -------------------------------------------------------------------------------
        
        . testparm foreign rep78 foreign#rep78
        
         ( 1)  foreign = 0
         ( 2)  rep78 = 0
         ( 3)  0b.foreign#2.rep78 = 0
         ( 4)  0b.foreign#3.rep78 = 0
         ( 5)  0b.foreign#4.rep78 = 0
         ( 6)  0b.foreign#5.rep78 = 0
         ( 7)  1.foreign#3.rep78 = 0
        
               F(  7,    61) =    0.39
                    Prob > F =    0.9049
        
        . test foreign rep78 foreign#rep78
        foreign#rep78 not found
        r(111);

        Comment


        • #5
          Thanks very much, Clyde! If I add the i. as prefix. Why the result is different from yours? Seems like my code here only focus on the F statistics of the " i.foreign#i.rep78"?

          . testparm i.foreign i.rep78 i.foreign#i.rep78

          ( 1) 0b.foreign#2.rep78 = 0
          ( 2) 0b.foreign#3.rep78 = 0
          ( 3) 0b.foreign#4.rep78 = 0
          ( 4) 0b.foreign#5.rep78 = 0
          ( 5) 1.foreign#3.rep78 = 0

          F( 5, 61) = 0.54
          Prob > F = 0.7482
          Last edited by Eve Wang; 11 Jul 2023, 11:02.

          Comment

          Working...
          X