Announcement

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

  • How can I obtain the constant term from dslogit?

    Hi lasso fans,

    After lasso logit, I can run lassoknots, then lassoselect, then lassocoef, then store e(b) and it contains all the betas I would expect, along with _cons. So far, so good. When I use dslogit, and follow the same steps, there's no _cons. I don't think I'm missing some subtlety of the DS algorithm that means there is no _cons, or whatever; after all, \beta_0 is right there in the regression formula on p.44 of the [LASSO] manual (under dslogit, Methods and Formulas). Does anyone have any clues on how to get the constant term? Should it be somehow included in the must-must predictor variables? And if so, how?

    Robert

    example code:

    import delimited "http://www.robertgrantstats.co.uk/data/cp3.csv", varnames(1) clear delimiters(",")
    order la ofsted4 cinrpriorreferral2012 wfragencyworkerrate2012 cinrassessmentinitial10days2012

    // run double-selection logistic regression
    dslogit ofsted4 cinrpriorreferral2012 ///
    wfragencyworkerrate2012 ///
    cinrassessmentinitial10days2012, ///
    controls(cinrduring2012-wfrturnoverrate2012) coef selection(cv)

    // choose lambda*
    lassoknots, for(cinrpriorreferral2012) alllambdas

    // set lambda*
    lassoselect id=13, for(cinrpriorreferral2012)

    // get coefficients
    lassocoef (., for(cinrpriorreferral2012))
    matrix DSLASSOBETA = e(b)
    matrix list DSLASSOBETA





  • #2
    Apologies but in the code above, three instances of "for(cinrpriorreferral2012)" should be "for(ofsted4)".

    Comment


    • #3
      Thanks for the reproducible example. lassocoef will not overwrite the estimation results from dslogit, so you need to first request that the values of the postselection coefficients be displayed and then pick these up from the matrix -r(coef)- from return list. Note that the command dslogit does not itself output a constant term.

      Code:
      import delimited "http://www.robertgrantstats.co.uk/data/cp3.csv", varnames(1) clear delimiters(",")
      order la ofsted4 cinrpriorreferral2012 wfragencyworkerrate2012 cinrassessmentinitial10days2012
      
      // run double-selection logistic regression
      dslogit ofsted4 cinrpriorreferral2012 ///
      wfragencyworkerrate2012 ///
      cinrassessmentinitial10days2012, ///
      controls(cinrduring2012-wfrturnoverrate2012) coef selection(cv)
      
      // choose lambda*
      lassoknots, for(ofsted4) alllambdas
      
      // set lambda*
      lassoselect id=13, for(ofsted4)
      
      // get coefficients
      lassocoef (., for(ofsted4)), display(coef, postselection)
      
      matrix DSLASSOBETA = r(coef)
      matrix list DSLASSOBETA
      Res.:

      Code:
      . matrix DSLASSOBETA = r(coef)
      
      . matrix list DSLASSOBETA
      
      DSLASSOBETA[7,1]
                       ofsted4
      cinrsec~2012   .00917287
      fincinr~2012    .0003098
      wfrvaca~2012   .02597505
      cinrpri~2012    .1340174
      wfragen~2012   .13723109
      ci~0days2012  -.08845932
             _cons  -3.5980897
      Last edited by Andrew Musau; 08 Apr 2020, 15:13.

      Comment


      • #4
        Superb! Thank you Andrew.

        Robert

        Comment

        Working...
        X