Announcement

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

  • Reference category in logistic regression??

    I have a variable where 0 is coded for X, 1 for Y, 2 for Z... etc. (numeric variable). How do I then vary between reference category when running a logistic regression to get result for each category?

    Whats the code?


    Im sorry if the questions is a bit stupid but Im totally new to this.. and my googling have failed so far!

  • #2
    Choose one base category and then use the test command for comparisons of non base categories. Otherwise, use ibn.catvar to choose a base, e.g., ib0.catvar for 0, ib1.catvar for 1, etc. See

    Code:
    help fvvarlist
    Code:
    webuse lbw, clear
    tab race, nolab
    logit low age smoke ib1.race
    test 2.race= 3.race
    logit low age smoke ib2.race

    Res.:

    Code:
    . tab race, nolab
    
           race |      Freq.     Percent        Cum.
    ------------+-----------------------------------
              1 |         96       50.79       50.79
              2 |         26       13.76       64.55
              3 |         67       35.45      100.00
    ------------+-----------------------------------
          Total |        189      100.00
    
    .
    . logit low age smoke ib1.race
    
    Iteration 0:   log likelihood =   -117.336  
    Iteration 1:   log likelihood = -109.57893  
    Iteration 2:   log likelihood = -109.43115  
    Iteration 3:   log likelihood =  -109.4311  
    Iteration 4:   log likelihood =  -109.4311  
    
    Logistic regression                             Number of obs     =        189
                                                    LR chi2(4)        =      15.81
                                                    Prob > chi2       =     0.0033
    Log likelihood =  -109.4311                     Pseudo R2         =     0.0674
    
    ------------------------------------------------------------------------------
             low |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |  -.0348828   .0334024    -1.04   0.296    -.1003502    .0305847
           smoke |    1.10055   .3719453     2.96   0.003     .3715511     1.82955
                 |
            race |
          black  |   1.011413   .4934234     2.05   0.040     .0443209    1.978505
          other  |    1.05673   .4059583     2.60   0.009     .2610665    1.852394
                 |
           _cons |  -1.007554   .8616628    -1.17   0.242    -2.696382    .6812744
    ------------------------------------------------------------------------------
    
    .
    . test 2.race= 3.race
    
     ( 1)  [low]2.race - [low]3.race = 0
    
               chi2(  1) =    0.01
             Prob > chi2 =    0.9265
    
    .
    . logit low age smoke ib2.race
    
    Iteration 0:   log likelihood =   -117.336  
    Iteration 1:   log likelihood = -109.57893  
    Iteration 2:   log likelihood = -109.43115  
    Iteration 3:   log likelihood =  -109.4311  
    Iteration 4:   log likelihood =  -109.4311  
    
    Logistic regression                             Number of obs     =        189
                                                    LR chi2(4)        =      15.81
                                                    Prob > chi2       =     0.0033
    Log likelihood =  -109.4311                     Pseudo R2         =     0.0674
    
    ------------------------------------------------------------------------------
             low |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             age |  -.0348828   .0334024    -1.04   0.296    -.1003502    .0305847
           smoke |    1.10055   .3719453     2.96   0.003     .3715511     1.82955
                 |
            race |
          white  |  -1.011413   .4934234    -2.05   0.040    -1.978505   -.0443209
          other  |   .0453171   .4909151     0.09   0.926    -.9168588    1.007493
                 |
           _cons |   .0038592   .8443829     0.00   0.996    -1.651101    1.658819
    ------------------------------------------------------------------------------
    
    .

    Comment


    • #3
      Cathrine:
      welcome to this forum.
      This is not a stupid question at all.
      The following toy-example can be helpful:
      Code:
      . sysuse auto.dta
      . logit foreign i.rep78 if rep78>=3
      
      Iteration 0:   log likelihood = -38.411464
      Iteration 1:   log likelihood = -27.676628
      Iteration 2:   log likelihood = -27.446054
      Iteration 3:   log likelihood = -27.444671
      Iteration 4:   log likelihood = -27.444671
      
      Logistic regression                             Number of obs     =         59
                                                      LR chi2(2)        =      21.93
                                                      Prob > chi2       =     0.0000
      Log likelihood = -27.444671                     Pseudo R2         =     0.2855
      
      ------------------------------------------------------------------------------
           foreign |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
             rep78 |
                4  |   2.197225   .7698004     2.85   0.004     .6884436    3.706006
                5  |   3.701302   .9906975     3.74   0.000     1.759571    5.643033
                   |
             _cons |  -2.197225   .6085806    -3.61   0.000    -3.390021   -1.004428
      ------------------------------------------------------------------------------
      
      .
      predict fitted, xb
      
      ///To be compared to the fitted values calculated by hand///
      /// -2.197225 if rep78==3///
      ///. di -2.197225 + 2.197225///
      ///0 if rep78==4///
      ///. di -2.197225 + 3.701302///
      ///1.504077 if rep78==5///
      .

      See -fvvarlist- notation for more details about creating categorical variables and interactions.

      PS: crossed in the cyber-space with Andrew's helpdful reply,that focuses on a different topic.
      Last edited by Carlo Lazzaro; 10 Feb 2021, 04:33.
      Kind regards,
      Carlo
      (Stata 19.0)

      Comment

      Working...
      X