Announcement

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

  • Lasso for selection of variables and running logit regression using selected variables in lasso

    Hi all,
    Can someone help me please,
    I am assessing the impact of income(X1) on economic growth (Y) by using Logit regression approach. Income is my interest variable while i have also control variables (X2, X3, .....X9).
    I was told to use lasso to select my variables to use in the regression. Can anyone help me with the command here for my case to select variables using lasso, and command to see the selected variables and finally how can i put the selected variables in my Logit approach to run the regression?

    Thank you

  • #2
    Code:
    webuse lbw, clear
    set seed 08052022
    lasso logit low c.age c.lwt i.race i.smoke i.ptl i.ht i.ui i.ftv, nolog
    *DISPLAY POST SELECTION VARIABLES
    di "`e(post_sel_vars)'"
    *LOGIT WITH POST SELECTION VARIABLES
    logit `e(post_sel_vars)'
    Res.:

    Code:
    . lasso logit low c.age c.lwt i.race i.smoke i.ptl i.ht i.ui i.ftv, nolog
    note: 3.ptl dropped because it is constant in C.V. subsamples
    note: 6.ftv dropped because it is constant in C.V. subsamples
    
    Lasso logit model                           No. of obs        =        189
                                                No. of covariates =         19
    Selection: Cross-validation                 No. of CV folds   =         10
    
    --------------------------------------------------------------------------
             |                                No. of      Out-of-
             |                               nonzero       sample      CV mean
          ID |     Description      lambda     coef.   dev. ratio     deviance
    ---------+----------------------------------------------------------------
           1 |    first lambda       .1352         0      -0.0154     1.260739
           5 |   lambda before    .0931881         1       0.0076     1.232177
         * 6 | selected lambda    .0849095         1       0.0076     1.232166
           7 |    lambda after    .0773664         1       0.0040     1.236699
           9 |     last lambda    .0642309         6      -0.0050     1.247864
    --------------------------------------------------------------------------
    * lambda selected by cross-validation.
    
    . 
    . *DISPLAY POST SELECTION VARIABLES
    
    . 
    . di "`e(post_sel_vars)'"
    low ptl
    
    . 
    . *LOGIT WITH POST SELECTION VARIABLES
    
    . 
    . logit `e(post_sel_vars)'
    
    Iteration 0:   log likelihood =   -117.336  
    Iteration 1:   log likelihood = -113.96986  
    Iteration 2:   log likelihood = -113.94631  
    Iteration 3:   log likelihood = -113.94631  
    
    Logistic regression                             Number of obs     =        189
                                                    LR chi2(1)        =       6.78
                                                    Prob > chi2       =     0.0092
    Log likelihood = -113.94631                     Pseudo R2         =     0.0289
    
    ------------------------------------------------------------------------------
             low |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             ptl |   .8018056   .3171535     2.53   0.011     .1801963    1.423415
           _cons |  -.9641889   .1749607    -5.51   0.000    -1.307106   -.6212722
    ------------------------------------------------------------------------------

    Comment


    • #3
      Thank you so much

      Comment

      Working...
      X