Announcement

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

  • Store significant variables in Logistic Regression

    Hi,

    I am running a logistic regression with about 30 variables, most of which are categorical variables, and I would like to run a command afterwards that creates a list containing all the significant variables (say at the 5% level) to run some further analysis on those specific variables.

    Do you have any idea on how to do this ?

    Thanks,
    Diego

  • #2
    Code:
    . sysuse auto, clear
    (1978 automobile data)
    
    . // I am deliberately using a model with ommited
    . // variables, empty cells, adding the same variable twice,
    . // to see if my solution works under difficult circumstances
    . logit foreign i.rep78 mpg mpg weight length, or
    
    note: 1.rep78 != 0 predicts failure perfectly;
          1.rep78 omitted and 2 obs not used.
    
    note: 2.rep78 != 0 predicts failure perfectly;
          2.rep78 omitted and 8 obs not used.
    
    note: 5.rep78 omitted because of collinearity.
    note: mpg omitted because of collinearity.
    Iteration 0:   log likelihood = -38.411464  
    Iteration 1:   log likelihood = -18.363164  
    Iteration 2:   log likelihood = -16.168782  
    Iteration 3:   log likelihood = -15.891852  
    Iteration 4:   log likelihood = -15.889134  
    Iteration 5:   log likelihood = -15.889132  
    Iteration 6:   log likelihood = -15.889132  
    
    Logistic regression                                     Number of obs =     59
                                                            LR chi2(5)    =  45.04
                                                            Prob > chi2   = 0.0000
    Log likelihood = -15.889132                             Pseudo R2     = 0.5863
    
    ------------------------------------------------------------------------------
         foreign | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
    -------------+----------------------------------------------------------------
           rep78 |
              1  |          1  (empty)
              2  |          1  (empty)
              3  |   .0275865    .038135    -2.60   0.009     .0018366    .4143617
              4  |   .2909225   .3771016    -0.95   0.341     .0229312    3.690861
              5  |          1  (omitted)
                 |
             mpg |   .7868654   .0960931    -1.96   0.050     .6193704    .9996556
             mpg |          1  (omitted)
          weight |    .994905   .0028337    -1.79   0.073     .9893666    1.000474
          length |   1.033117   .0850567     0.40   0.692     .8791641    1.214029
           _cons |    2469905   2.56e+07     1.42   0.155     .0037979    1.61e+15
    ------------------------------------------------------------------------------
    Note: _cons estimates baseline odds.
    
    .
    .
    . local k = colsof(e(b))
    
    . local x : colnames(e(b))
    
    .
    . tempname table
    
    . matrix `table' = r(table)
    
    .
    . forvalues i = 1/`k' {
      2.    if `table'[4,`i'] < 0.05 {        
      3.        local res = `"`res' `:word `i' of `x''"'
      4.     }
      5. }
    
    . di "`res'"
     3.rep78 mpg
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment

    Working...
    X