Announcement

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

  • Set base level for interaction with factor variable and continuous variable

    I am trying to set the base level to be 8 for an interaction of a factor variable (ib8.year) with a continuous variable (c.lntrips). Therefore, my interaction term is ib8.year#c.lntrips.

    Code:
    reg y ib8.year#c.lntrips ib8.year i.locationcode, coeflegend allbaselevels
    Code:
           
    lnvalue_adj2009    Coef.    Legend
                
    year#c.lntrips    
    1    .1626311    _b[1.year#c.lntrips]
    2    .2049545    _b[2.year#c.lntrips]
    3    .3396218    _b[3.year#c.lntrips]
    4    .4795658    _b[4.year#c.lntrips]
    5    .5988731    _b[5.year#c.lntrips]
    6    .6452115    _b[6.year#c.lntrips]
    7    .4231633    _b[7.year#c.lntrips]
    8    .4718695    _b[8b.year#c.lntrips]
    9    .4286197    _b[9.year#c.lntrips]
    10    .3784935    _b[10.year#c.lntrips]
    11    .4589129    _b[11.year#c.lntrips]
    12    .5920118    _b[12.year#c.lntrips]
    13    .6741337    _b[13.year#c.lntrips]
        
    year    
    1    2.296849    _b[1.year]
    2    2.064134    _b[2.year]
    3    1.097247    _b[3.year]
    4    .2270842    _b[4.year]
    5    -.8567594    _b[5.year]
    6    -1.335968    _b[6.year]
    7    .6330328    _b[7.year]
    8    0    _b[8b.year]
    9    .4042452    _b[9.year]
    10    .7734908    _b[10.year]
    11    .2596141    _b[11.year]
    12    -.6904781    _b[12.year]
    13    -1.272918    _b[13.year]
    ...
    When I review the output, the factor variable ib8.year has year 8 as the base year with the coefficient equal to zero. The problem is with the interaction term. I was expecting the coefficient for _b[8b.year#c.lntrips] to be marked as the base level and the coefficient equal to zero. How do I set the base level for interaction term ib8.year#c.lntrips?



    Thank you!

  • #2
    Consider
    Code:
    sysuse auto, clear
    
    reg price c.mpg##ib1.foreign, coeflegend allbaselevels
    produces
    Code:
          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.  Legend
    --------------+----------------------------------------------------------------
              mpg |  -250.3668  _b[mpg]
                  |
          foreign |
        Domestic  |   13.58741  _b[0.foreign]
         Foreign  |          0  _b[1b.foreign]
                  |
    foreign#c.mpg |
        Domestic  |  -78.88826  _b[0.foreign#c.mpg]
         Foreign  |          0  _b[1b.foreign#co.mpg]
                  |
            _cons |   12586.95  _b[_cons]
    -------------------------------------------------------------------------------
    whereas
    Code:
     reg price c.mpg#ib1.foreign ib1.foreign, coeflegend allbaselevels
    produces
    Code:
          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.  Legend
    --------------+----------------------------------------------------------------
    foreign#c.mpg |
        Domestic  |  -329.2551  _b[0.foreign#c.mpg]
         Foreign  |  -250.3668  _b[1b.foreign#c.mpg]
                  |
          foreign |
        Domestic  |   13.58741  _b[0.foreign]
         Foreign  |          0  _b[1b.foreign]
                  |
            _cons |   12586.95  _b[_cons]
    -------------------------------------------------------------------------------
    You're not including lntrips by itself, only as an interaction term. Therefore, the interaction term for your base level will capture the slope of lntrips which is not zero, and all other slopes for the different interaction levels will be scaled accordingly by adding that slope.
    Last edited by Alfonso Sánchez-Peñalver; 04 Oct 2016, 15:48.
    Alfonso Sanchez-Penalver

    Comment


    • #3
      Hi Alfonso. Thank you for the clear explanation and example. I revised my code per your suggestion and now have the base levels working for all variables.

      Comment


      • #4
        You're welcome. Notice that there wasn't anything wrong with your previous estimation. They both produce the same estimates since the slope is included in the interaction estimates. It's just a question of how you interpret those interaction estimates. In the one you sent it's the total effect of lntrips at the different categories. If you include lntrips by itself it's the additional effect of lntrips on all other categories with respect to the base.
        Alfonso Sanchez-Penalver

        Comment

        Working...
        X