Announcement

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

  • Changing the base of a factor variable in a regression

    I am trying to change the omitted dummy variable from the smallest to some other. In other areas I have found people using the char command to change the base variable, however I cannot get it to work quite right.

    What I have essentially done:

    preserve
    sysuse auto, clear
    xtile mpgTiles = mpg, nquantiles(5)

    //changing the characteristics of mpgTiles based on the value
    char mpgTiles[omit] 5
    reg weight length i.mpgTiles

    //Trying to label mpgTile
    label define mpgs 1 "VHigh" 2 "High" 3 "Medium" 4 "Low" 5 "VLow"
    label values mpgTiles mpgs

    //Changing the characteristics of mpgTiles based on labels
    char mpgTiles[omit] "VLow"
    reg weight length i.mpgTiles

    restore

    both of these would include mpgTiles = 5 or "VLow" when I want that to be excluded and would exclude mpgTiles = 1 or "VHigh", as is the default.

    I know I could do it myself by creating dummy variables based on mpgTiles, but I have been suprised not to find a more elegant solution.

    Thanks,
    Eric

  • #2
    According to help fvvarlist

    You can specify the base level of a factor variable by using the ib. operator.
    Does that help you? See below. [Else, I've misunderstood what you want.]

    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    .
    .  xtile mpgTiles = mpg, nquantiles(5)
    
    . reg weight length i.mpgTiles
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(5, 68)        =    147.18
           Model |    40364277         5   8072855.4   Prob > F        =    0.0000
        Residual |  3729901.39        68  54851.4911   R-squared       =    0.9154
    -------------+----------------------------------   Adj R-squared   =    0.9092
           Total |  44094178.4        73  604029.841   Root MSE        =     234.2
    
    ------------------------------------------------------------------------------
          weight |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          length |   28.37779   2.159903    13.14   0.000     24.06777    32.68781
                 |
        mpgTiles |
              2  |  -270.6315   81.53305    -3.32   0.001    -433.3282   -107.9349
              3  |    -223.15   95.55277    -2.34   0.022    -413.8225    -32.4774
              4  |  -432.0571   119.9348    -3.60   0.001    -671.3833   -192.7309
              5  |   -354.634   133.7755    -2.65   0.010    -621.5788   -87.68913
                 |
           _cons |  -2075.117   454.4251    -4.57   0.000    -2981.908   -1168.325
    ------------------------------------------------------------------------------
    
    . reg weight length ib(last).mpgTiles
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(5, 68)        =    147.18
           Model |    40364277         5   8072855.4   Prob > F        =    0.0000
        Residual |  3729901.39        68  54851.4911   R-squared       =    0.9154
    -------------+----------------------------------   Adj R-squared   =    0.9092
           Total |  44094178.4        73  604029.841   Root MSE        =     234.2
    
    ------------------------------------------------------------------------------
          weight |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          length |   28.37779   2.159903    13.14   0.000     24.06777    32.68781
                 |
        mpgTiles |
              1  |    354.634   133.7755     2.65   0.010     87.68913    621.5788
              2  |   84.00246   120.0264     0.70   0.486    -155.5066    323.5115
              3  |    131.484   109.1087     1.21   0.232     -86.2391    349.2071
              4  |   -77.4231   94.79405    -0.82   0.417    -266.5817    111.7355
                 |
           _cons |  -2429.751   352.1182    -6.90   0.000    -3132.392    -1727.11
    ------------------------------------------------------------------------------
    
    . reg weight length ib(3).mpgTiles
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(5, 68)        =    147.18
           Model |    40364277         5   8072855.4   Prob > F        =    0.0000
        Residual |  3729901.39        68  54851.4911   R-squared       =    0.9154
    -------------+----------------------------------   Adj R-squared   =    0.9092
           Total |  44094178.4        73  604029.841   Root MSE        =     234.2
    
    ------------------------------------------------------------------------------
          weight |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          length |   28.37779   2.159903    13.14   0.000     24.06777    32.68781
                 |
        mpgTiles |
              1  |     223.15   95.55277     2.34   0.022      32.4774    413.8225
              2  |  -47.48154   89.52157    -0.53   0.598    -226.1191     131.156
              4  |  -208.9071   101.5776    -2.06   0.044    -411.6021   -6.212121
              5  |   -131.484   109.1087    -1.21   0.232    -349.2071     86.2391
                 |
           _cons |  -2298.267   413.0291    -5.56   0.000    -3122.453    -1474.08
    ------------------------------------------------------------------------------

    Comment


    • #3
      Ah perfect! Thanks very much

      Comment

      Working...
      X