Announcement

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

  • Requested Base Level Ignored in Interaction Syntax

    I am trying to run an regression of this form:

    Code:
    clear
    set seed 1729
    set obs 1000
    gen T = ceil(runiform() * 3)
    gen W = mod(_n, 3)
    gen C = 1
    gen Y = C + T + runiform()
    reg Y ibn.T#(C b0.W), noconstant
    For some reason this excludes the last level of W instead of the first. Is that always the case? How can I know which level will be omitted? The following works as expected

    Code:
    reg Y ibn.T b0.W, noconstant
    I don't care which level I omit as long as I can omit the same base level in both regressions. Many thanks for any suggestions!

  • #2
    Originally posted by Mauricio Caceres View Post

    Code:
    reg Y ibn.T#(C b0.W), noconstant
    For some reason this excludes the last level of W instead of the first. Is that always the case? How can I know which level will be omitted? The following works as expected

    Code:
    reg Y ibn.T b0.W, noconstant
    I don't think that there is any such thing as the base level for an interaction term in the absence of a main effect and therefore I agree with the default behavior. Starting with this principle, you can ask for interactions and main effects and then omit the latter.

    Code:
    clear
    set seed 1729
    set obs 1000
    gen T = ceil(runiform() * 3)
    gen W = mod(_n, 3)
    gen C = 1
    gen Y = C + T + runiform()
    reg Y ibn.T##(C b0.W) o(1/2).W, noconstant
    Res.:

    Code:
    . reg Y ibn.T##(C b0.W) o(1/2).W, noconstant
    note: 1.C omitted because of collinearity.
    note: 1.T#1.C omitted because of collinearity.
    note: 2.T#1.C omitted because of collinearity.
    note: 3.T#1.C omitted because of collinearity.
    
          Source |       SS           df       MS      Number of obs   =     1,000
    -------------+----------------------------------   F(9, 991)       =  16387.97
           Model |   12899.352         9  1433.26133   Prob > F        =    0.0000
        Residual |  86.6710214       991  .087458145   R-squared       =    0.9933
    -------------+----------------------------------   Adj R-squared   =    0.9933
           Total |   12986.023     1,000   12.986023   Root MSE        =    .29573
    
    ------------------------------------------------------------------------------
               Y | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
               T |
              1  |   2.526311   .0281971    89.59   0.000     2.470979    2.581644
              2  |   3.458505   .0279442   123.76   0.000     3.403668    3.513341
              3  |   4.479736   .0280698   159.59   0.000     4.424653    4.534819
                 |
             1.C |          0  (omitted)
                 |
               W |
              1  |          0  (omitted)
              2  |          0  (omitted)
                 |
             T#C |
            1 1  |          0  (omitted)
            2 1  |          0  (omitted)
            3 1  |          0  (omitted)
                 |
             T#W |
            1 1  |  -.0463275   .0401552    -1.15   0.249    -.1251265    .0324715
            1 2  |  -.0416716   .0396111    -1.05   0.293    -.1194029    .0360596
            2 1  |   .0117188   .0400743     0.29   0.770    -.0669215    .0903591
            2 2  |   .0499672   .0392604     1.27   0.203    -.0270759    .1270104
            3 1  |   .0207667   .0388678     0.53   0.593    -.0555059    .0970394
            3 2  |   .0258527   .0402597     0.64   0.521    -.0531515    .1048568
    ------------------------------------------------------------------------------

    Comment


    • #3
      I think this might be a matter of terminology; I just mean the level that will end up being excluded. But you do give me an idea, thanks! This seems to work:

      Code:
      clear
      set seed 1729
      set obs 1000
      gen T = ceil(runiform() * 3)
      gen W = mod(_n, 3)
      gen C = 1
      gen Y = C + T + runiform()
      
      tempname ivars
      fvexpand C b0.W
      local varlist `r(varlist)'
      matrix `ivars' = J(1, `:list sizeof varlist', .)
      matrix colnames `ivars' = `varlist'
      _ms_omit_info `ivars'
      mata st_local("varlist", invtokens(select(tokens(st_local("varlist")), !st_matrix("r(omit)"))))
      reg Y ibn.T#(`varlist'), noconstant

      Comment

      Working...
      X