-------------
      name:  <unnamed>
       log:  /Users/kahrens/Dropbox (PP)/StataLasso/lassoLogit/cs_lassologit_all.smcl
  log type:  smcl
 opened on:  16 Oct 2019, 09:09:39

.
. which lassologit
./lassologit.ado
*! lassologit (v0.3)
*! part of lassopack v1.3.1
*! last edited: 15oct2019
*! authors: aa/ms/cbh

. which lassologit_p
./lassologit_p.ado
*! lassologit_p
*! part of lassopack v1.3.1
*! last edited: 6may2019
*! authors: aa/ms

. which cvlassologit
./cvlassologit.ado
*! cvlassologit
*! part of lassopack v1.3.1
*! last edited: 6may2019
*! authors: aa/ms

. which rlassologit
./rlassologit.ado
*! rlassologit
*! part of lassopack v1.3.1
*! last edited: 6may2019
*! authors: aa/ms

.
. do "cs_lassologit.do"

. clear all

.
.
.
. ********************************************************************************
. *** Prostate data                                                            ***
. *** comparison with glmnet                                                                                                       ***
. ********************************************************************************
.
. insheet using prostate.data, clear
(11 vars, 97 obs)

.
. gen ybin = lpsa > 2

.
. lassologit ybin lcavol-pgg45, lam(10 1 0.1 0.05 0.03 0.01) lambdan
Obtaining solution for 6 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   10.00000    0     0.75567    121.55230   0.0000  | Added _cons.
     2 |   3    0.10000    3     4.61264     97.36078   0.2488  | Added lcavol
      |                                                         | lweight
      |                                                         | gleason.
     3 |   4    0.05000    5    10.56586     90.27006   0.3403  | Added lbph
      |                                                         | svi.
     4 |   6    0.01000    8    18.32126     86.17998   0.4238  | Added age
      |                                                         | lcp pgg45.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S =  e(betas)'

. mat list S

S[9,6]
                 r1          r2          r3          r4          r5
 lcavol           0           0   .50144272   .60356877   .65136862
lweight           0           0   .46623224   1.0222793   1.1985052
    age           0           0           0           0           0
   lbph           0           0           0   .02322241    .0977888
    svi           0           0           0   .34760389   .81834702
    lcp           0           0           0           0           0
gleason           0           0   .27433896   .63999954   .80482493
  pgg45           0           0           0           0           0
  _cons   .75566754   .75566754  -3.3706217  -7.9291814  -9.7345202

                 r6
 lcavol    .8262603
lweight   1.4897915
    age  -.02639874
   lbph   .23427909
    svi   2.1914669
    lcp  -.20264117
gleason   1.2161025
  pgg45  -.00227197
  _cons  -12.132043

. mat G = ( 0,0,0.501461115822691,0.603583899226737,0.651411524139352,0.826374502058559 \ 0,0,0.466224946596217,1.02233825499837,1.19858862440819,1.48996763937638 \ 0,0,0,0,0,-0.0264071147625507 \ 0,0,0,0.0232111786772005,0.0977733878125449,0.234278942429968 \ 0,0,0,0.347557333713614,0.818269071194786,2.19023312954913 \ 0,0,0,0,0,-0.20284502575343 \ 0,0,0.274327168187838,0.639999602733867,0.804810602155823,1.21666269887086 \ 0,0,0,0,0,-0.00227895781755522 \ 0.755667537541278,0.755667537541278,-3.37053747374121,-7.92940124760532,-9.73475850480416,-12.1358873874818 )

. di mreldif(S,G)
.00038672

. assert mreldif(S,G)<0.01

.
. lassologit ybin lcavol-pgg45, nostd l(10 1 0.1 0.05 0.03 0.01) lambdan
Obtaining solution for 6 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   10.00000    0     0.75567    121.55230   0.0000  | Added _cons.
     2 |   2    1.00000    1     0.29844    112.28197   0.0929  | Added pgg45.
     3 |   3    0.10000    4     1.21117    101.42219   0.2320  | Added lcavol
      |                                                         | age lbph.
     4 |   4    0.05000    3     1.51415     93.41464   0.2813  | Removed age.
     5 |   5    0.03000    6     5.20432     94.24763   0.3242  | Added
      |                                                         | lweight age
      |                                                         | gleason.
     6 |   6    0.01000    8    15.75758     87.63211   0.4118  | Added svi
      |                                                         | lcp.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S = e(betas)'

. mat list S

S[9,6]
                 r1          r2          r3          r4          r5
 lcavol           0           0   .48999457    .7693653   .85524862
lweight           0           0           0           0   .31595678
    age           0           0   .00567835           0  -.00508425
   lbph           0           0   .06331262   .20851714    .2390665
    svi           0           0           0           0           0
    lcp           0           0           0           0           0
gleason           0           0           0           0   .32609954
  pgg45           0   .02309655   .02194763   .01826891   .01115514
  _cons   .75566754   .27534735  -.63023247  -.51799615  -3.4517119

                 r6
 lcavol   .90587387
lweight   1.2171285
    age  -.03184618
   lbph   .28322545
    svi   1.1479567
    lcp  -.14337938
gleason    1.221161
  pgg45  -.00506532
  _cons  -10.801948

. mat G = ( 0,0,0.49000229764977,0.769318675648317,0.85526320111666,0.906069187273262 \ 0,0,0,0,0.315948623488018,1.21721663534913 \ 0,0,0.00568091171074165,0,-0.00508198583263728,-0.0318566587040123 \ 0,0,0.0633097982098456,0.208509405869272,0.239053556251706,0.283238055284736 \ 0,0,0,0,0,1.14829028427382 \ 0,0,0,0,0,-0.143667092495639 \ 0,0,0,0,0.325877300407054,1.22138220662723 \ 0,0.0230961215196978,0.0219472306702984,0.0182648564510364,0.0111575320234226,-0.00506567179207975 \ 0.755667537541278,0.27535477007396,-0.630396562134161,-0.517881010344681,-3.45041705660254,-10.8034348672065 )

. di mreldif(S,G)
.00029096

. assert mreldif(S,G)<0.01

.
. lassologit ybin lcavol-pgg45, nocons l(10 1 0.1 0.05 0.03 0.01) lambdan
Obtaining solution for 6 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   2    1.00000    1     0.05598    124.89448  -0.0138  | Added
      |                                                         | gleason.
     2 |   3    0.10000    2     0.61149    101.12678   0.1954  | Added lcavol
      |                                                         | lweight.
      |                                                         | Removed
      |                                                         | gleason.
     3 |   4    0.05000    5     1.57115     96.27282   0.2764  | Added age
      |                                                         | lbph svi
      |                                                         | pgg45.
      |                                                         | Removed
      |                                                         | lweight.
     4 |   5    0.03000    6     2.41099     92.88880   0.3179  | Added
      |                                                         | lweight.
     5 |   6    0.01000    8     4.49415     90.64406   0.3638  | Added lcp
      |                                                         | gleason.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S = e(betas)'

. mat list S

S[8,6]
                 r1          r2          r3          r4          r5
 lcavol           0           0   .59802782   .72616476   .79875667
lweight           0           0   .01346455           0   .18176699
    age           0           0           0  -.00300917  -.01637452
   lbph           0           0           0   .17547015   .25947085
    svi           0           0           0    .6652651   1.1500101
    lcp           0           0           0           0           0
gleason           0   .05597523           0           0           0
  pgg45           0           0           0   .00123892   .00461519

                 r6
 lcavol   .92255846
lweight   .48238405
    age  -.06134834
   lbph   .40786672
    svi   2.3420168
    lcp  -.03583815
gleason   .23659329
  pgg45   .00554119

. mat G = ( 0,0,0.597904154552661,0.726122023990401,0.798790726486026,0.921752657257945 \ 0,0,0.0135028969542606,0,0.171947048951238,0.49056370807684 \ 0,0,0,-0.00300756283054592,-0.0158227880543364,-0.060846846460528 \ 0,0,0,0.175476249674279,0.259990447474341,0.405507212738994 \ 0,0,0,0.665451061416816,1.15151187861837,2.33678717583705 \ 0,0,0,0,0,-0.0347040277832361 \ 0,0.0559752315024908,0,0,5.66530864443488e-05,0.227283007307124 \ 0,0,0,0.00123728745272919,0.00458124613535244,0.0056859742231097 )

. di mreldif(S,G)
.00837916

. assert mreldif(S,G)<0.01

.
. lassologit ybin lcavol-pgg45,  nostd nocons l(10 1 0.1 0.05 0.03 0.01) lambdan
Obtaining solution for 6 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   10.00000    1     0.00208    131.65873  -0.0695  | Added age.
     2 |   2    1.00000    2     0.02767    113.17565   0.0963  | Added pgg45.
     3 |   3    0.10000    4     0.58558    100.15828   0.2308  | Added lcavol
      |                                                         | lbph.
     4 |   5    0.03000    6     1.29587     95.27151   0.2983  | Added
      |                                                         | lweight
      |                                                         | gleason.
     5 |   6    0.01000    8     3.41425     91.81365   0.3541  | Added svi
      |                                                         | lcp.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S = e(betas)'

. mat list S

S[8,6]
                 r1          r2          r3          r4          r5
 lcavol           0           0   .48036643   .76668272    .9011587
lweight           0           0           0           0     .074323
    age   .00208321   .00314937  -.00374366  -.00798619  -.01462656
   lbph           0           0    .0794793   .22121772   .28416574
    svi           0           0           0           0           0
    lcp           0           0           0           0           0
gleason           0           0           0           0    .0042549
  pgg45           0   .02451818   .02198798   .01847529   .01734401

                 r6
 lcavol   .99537589
lweight   .46323122
    age  -.06097121
   lbph   .40829837
    svi    1.184281
    lcp  -.07020165
gleason   .22032571
  pgg45   .01156431

. mat G = ( 0,0,0.480318888302968,0.766488329771494,0.901293514420413,0.994357503579643 \ 0,0,0,0,0.0675008486192263,0.471956582881281 \ 0.00208320818573869,0.00315326759834838,-0.00374253486037605,-0.00798207623817391,-0.013826952207498,-0.0604790391537946 \ 0,0,0.0794801700546684,0.221208787323384,0.283793361154338,0.405919890396927 \ 0,0,0,0,0,1.17906428190479 \ 0,0,0,0,0,-0.0688739335594197 \ 0,0,0,0,0.000169219253455043,0.210870371872184 \ 0,0.0245128044360127,0.0219880300010344,0.018475718697768,0.0173742626600768,0.0117069696335417 )

. di mreldif(S,G)
.00780871

. assert mreldif(S,G)<0.01

.
. // penalization and standardization
. lassologit ybin lcavol-pgg45, l(10)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
           lcavol |       0.4943305      0.9095492
          lweight |       0.4337542      2.0564072
          gleason |       0.2539834      1.3449179
            _cons |      -3.1109989    -16.4802012
------------------+--------------------------------

. mat bdense=e(beta_dense)

. mat psi=e(Psi)

. mat spsi=e(sPsi)

. lassologit ybin lcavol-pgg45, l(10) stdfly

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
           lcavol |       0.4943480      0.9095492
          lweight |       0.4337418      2.0564072
          gleason |       0.2539189      1.3449179
            _cons |      -3.1105448    -16.4802012
------------------+--------------------------------

. assert mreldif(bdense,e(beta_dense))<0.001

. lassologit ybin lcavol-pgg45, l(10) psi(psi)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
           lcavol |       0.4943305      0.9095492
          lweight |       0.4337542      2.0564072
          gleason |       0.2539834      1.3449179
            _cons |      -3.1109989    -16.4802012
------------------+--------------------------------

. assert mreldif(bdense,e(beta_dense))<0.001

. lassologit ybin lcavol-pgg45, l(10) spsi(spsi)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
           lcavol |       0.4943305      0.9095492
          lweight |       0.4337542      2.0564072
          gleason |       0.2539834      1.3449179
            _cons |      -3.1109989    -16.4802012
------------------+--------------------------------

. assert mreldif(bdense,e(beta_dense))<0.001

. // vs notpen
. mat psi0=psi

. mat psi0[1,1]=0

. mat spsi0=spsi

. mat spsi0[1,1]=0

. lassologit ybin lcavol-pgg45, l(10) notpen(lcavol)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
           lcavol |       1.2543043      1.1966898
          lweight |       0.0677157      1.7891419
            _cons |      -0.8951812     -6.9732078
------------------+--------------------------------

. mat bdense=e(beta_dense)

. lassologit ybin lcavol-pgg45, l(10) psi(psi0)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
           lcavol |       1.2543043      1.1966898
          lweight |       0.0677157      1.7891419
            _cons |      -0.8951812     -6.9732078
------------------+--------------------------------

. assert mreldif(bdense,e(beta_dense))<0.001

. lassologit ybin lcavol-pgg45, l(10) spsi(spsi0)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
           lcavol |       1.2543043      1.1966898
          lweight |       0.0677157      1.7891419
            _cons |      -0.8951812     -6.9732078
------------------+--------------------------------

. assert mreldif(bdense,e(beta_dense))<0.001

.
.
.
. ********************************************************************************
. *** Spam data                                                                ***
. *** comparison with glmnet                                                                                                       ***
. ********************************************************************************
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. lassologit v58 v1-v57 , ///
>         l(0.18 .1 .05 .01 0.005 0.001) lambdan
Obtaining solution for 6 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.18000    1     0.47598   6122.83847   0.0083  | Added v21
      |                                                         | _cons.
     2 |   2    0.10000    7     2.81070   5083.09675   0.1804  | Added v7 v16
      |                                                         | v23 v25 v53
      |                                                         | v57.
     3 |   3    0.05000   19     6.90816   3913.66594   0.3772  | Added v5 v6
      |                                                         | v8 v9 v17 v18
      |                                                         | v19 v20 v24
      |                                                         | v26 v27 v52.
     4 |   4    0.01000   37    17.62002   2616.28668   0.5984  | Added v2 v3
      |                                                         | v4 v10 v12
      |                                                         | v22 v33 v37
      |                                                         | v39 v42 v43
      |                                                         | v44 v45 v46
      |                                                         | v47 v48 v49
      |                                                         | v56.
     5 |   5    0.00500   45    23.77112   2369.70055   0.6433  | Added v1 v14
      |                                                         | v15 v29 v35
      |                                                         | v38 v41 v51.
     6 |   6    0.00100   53    42.66342   2121.90778   0.6883  | Added v11
      |                                                         | v28 v30 v31
      |                                                         | v36 v40 v50
      |                                                         | v54.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S = e(betas)'

. mat list S

S[58,6]
               r1          r2          r3          r4          r5          r6
   v1           0           0           0           0  -.04225664  -.27214275
   v2           0           0           0  -.00374091  -.05127575  -.12567998
   v3           0           0           0   .10113755   .11881682    .1390962
   v4           0           0           0   .01737589   .05267573   .19596475
   v5           0           0    .1727807   .42960602   .48472386   .52680103
   v6           0           0   .21529305   .43995289    .4920479    .6398607
   v7           0   .54124424   1.1426365   2.0688244    2.229753   2.2994845
   v8           0           0   .13686861   .48085682   .53116372   .55860011
   v9           0           0   .11944365   .36017472    .4285708   .57228097
  v10           0           0           0   .03639786   .06618343   .09890413
  v11           0           0           0           0           0  -.08911314
  v12           0           0           0  -.03081446  -.08906859   -.1347646
  v13           0           0           0           0           0           0
  v14           0           0           0           0   .00804803   .09629843
  v15           0           0           0           0    .1881181   .76789388
  v16           0   .05695022   .26102054   .47444417   .58307517   .99205468
  v17           0           0    .1633635   .53762305   .66652873   .84922582
  v18           0           0   .01860956   .22357567   .23252779   .15251566
  v19           0           0   .03546808   .06846787   .07442523    .0809274
  v20           0           0   .06231727   .30238904   .40107559   .68173141
  v21   .02516619   .24481679   .28506916   .23123314   .21751699     .226894
  v22           0           0           0   .15242899   .21254888   .24812337
  v23           0   .51267335   .90878927   1.6218806   1.8809046   2.2554731
  v24           0           0   .13648679   .50236483    .5536729   .54017396
  v25           0  -.00711341  -.11940898   -.6504895  -.94776068  -1.5416988
  v26           0           0  -.03652637  -.31180458  -.47637893  -.86518479
  v27           0           0  -.00214557  -.15015757  -.46485457  -1.4429289
  v28           0           0           0           0           0   .29930437
  v29           0           0           0           0  -.11315754  -.97465088
  v30           0           0           0           0           0  -.21465474
  v31           0           0           0           0           0  -.15177803
  v32           0           0           0           0           0           0
  v33           0           0           0  -.26480919  -.46531758  -.76406289
  v34           0           0           0           0           0           0
  v35           0           0           0           0  -.06375784  -.97099141
  v36           0           0           0           0           0   .66586659
  v37           0           0           0  -.12502434  -.08893621  -.01147064
  v38           0           0           0           0  -.00646467  -.43690013
  v39           0           0           0  -.10631926  -.22456488  -.58807676
  v40           0           0           0           0           0  -.35701544
  v41           0           0           0           0   -.2996689  -2.1216478
  v42           0           0           0  -.44593572  -.70821005  -1.4707508
  v43           0           0           0  -.11633198  -.27122313  -.71018955
  v44           0           0           0  -.12871699  -.37395878  -1.0508246
  v45           0           0           0  -.30072458  -.43262396  -.67343948
  v46           0           0           0  -.41740057  -.70460002  -1.2119074
  v47           0           0           0  -.15060387  -.71411759  -1.5974548
  v48           0           0           0  -.16425604  -.58718251  -2.0645792
  v49           0           0           0  -.31893943  -.61866224  -1.0606296
  v50           0           0           0           0           0    -.127849
  v51           0           0           0           0  -.13709839  -.67051869
  v52           0           0   .18374361   .45211158   .45808122   .41951366
  v53           0   .63102486   1.5733686   3.7605486   4.4062321   5.0716909
  v54           0           0           0           0           0   1.0462338
  v55           0           0           0           0           0           0
  v56           0           0           0   .00137845   .00227828   .00462671
  v57           0   .00002668   .00028159   .00046685   .00050695   .00061037
_cons  -.45081192  -.81685285  -1.3345408  -1.6707147  -1.6005077   -1.532364

. mat G = ( 0,0,0,0,-0.0422529146575627,-0.272031262707042 \ 0,0,0,-0.00373203418724297,-0.0512671410498323,-0.125632626238845 \ 0,0,0,0.101141846279635,0.11883214230586,0.139109364166967 \ 0,0,0,0.0173756561991167,0.0526745401803319,0.195886595110133 \ 0,0,0.172804595227024,0.429605013071812,0.484763002454668,0.526731240528818 \ 0,0,0.215391390316697,0.439944587424189,0.491919474006125,0.638892239188151 \ 0,0.541244393029207,1.14272230384219,2.06887558871726,2.23002699666492,2.30014269388336 \ 0,0,0.136927707286204,0.480868178278047,0.531197496280493,0.55864194969041 \ 0,0,0.119571529292932,0.3601313065449,0.428423569813396,0.571760019260457 \ 0,0,0,0.0363964738545447,0.0661874609011232,0.0988644526800415 \ 0,0,0,0,0,-0.0886237382535084 \ 0,0,0,-0.0308097278466257,-0.089081775600141,-0.134749875433312 \ 0,0,0,0,0,0 \ 0,0,0,0,0.00795793603714984,0.0959052969098513 \ 0,0,0,0,0.187956709982398,0.766748734310841 \ 0,0.0569499824412161,0.261053578737326,0.474455181680385,0.582556859865158,0.992084036782018 \ 0,0,0.163352298428151,0.537635721901667,0.666555390326264,0.849404169191338 \ 0,0,0.0186179136972665,0.223578006225662,0.232610416364506,0.152792625551643 \ 0,0,0.0354864953419262,0.0684739350799352,0.0744387727276772,0.0809881016277326 \ 0,0,0.0623296656451264,0.30237957050336,0.401066076630547,0.680630170947902 \ 0.0251657497800995,0.244816018569017,0.285089535713845,0.231235215294809,0.21751235961023,0.226819320440981 \ 0,0,0,0.152438807435518,0.212558463696679,0.248079809754775 \ 0,0.512678317278518,0.908939351449302,1.62189944870526,1.88098268266277,2.25700936855849 \ 0,0,0.136512396818573,0.502377361626912,0.553687448356407,0.540585164364761 \ 0,-0.00711373831549181,-0.119341797786071,-0.650488655022833,-0.947791899988904,-1.5422976600939 \ 0,0,-0.0365713377744791,-0.311724419804555,-0.476376985691428,-0.865174810478425 \ 0,0,-0.00214239923991577,-0.150103996240846,-0.464229167129705,-1.43091728235785 \ 0,0,0,0,0,0.299518215687398 \ 0,0,0,0,-0.11287556060371,-0.970189677158865 \ 0,0,0,0,0,-0.213188194988553 \ 0,0,0,0,0,-0.15111484640071 \ 0,0,0,0,0,0 \ 0,0,0,-0.264763346644653,-0.465222166671986,-0.763495947479959 \ 0,0,0,0,0,0 \ 0,0,0,0,-0.0635939140607186,-0.963847734942651 \ 0,0,0,0,0,0.666907685726506 \ 0,0,0,-0.125014730751495,-0.0889334412435665,-0.011300721151613 \ 0,0,0,0,-0.00632977917857363,-0.436818510247387 \ 0,0,0,-0.106301779679491,-0.224438789391816,-0.586944463758824 \ 0,0,0,0,0,-0.358234655091931 \ 0,0,0,0,-0.299579530075859,-2.10564311868802 \ 0,0,0,-0.44588873213617,-0.708035508405983,-1.46655172058406 \ 0,0,0,-0.116295099407099,-0.271023655797981,-0.707676526963956 \ 0,0,0,-0.128692659562944,-0.373788716012293,-1.04867026256564 \ 0,0,0,-0.300713167088696,-0.432600838003125,-0.673078767971861 \ 0,0,0,-0.4173345191239,-0.704321130319187,-1.21019326162314 \ 0,0,0,-0.150587748961614,-0.714086849502039,-1.59652543630244 \ 0,0,0,-0.164230301991611,-0.586985955993564,-2.06052061918955 \ 0,0,0,-0.318945414490126,-0.61863047152071,-1.0603371670279 \ 0,0,0,0,0,-0.12810459024372 \ 0,0,0,0,-0.136996306452528,-0.671500830778917 \ 0,0,0.183754285937407,0.452118980142298,0.458172676826618,0.419905830636866 \ 0,0.631023867075545,1.57316434164323,3.76088285698889,4.4075093667459,5.07598763000083 \ 0,0,0,0,0,1.04898040886094 \ 0,0,0,0,0,0 \ 0,0,0,0.00137880130961895,0.00227997634698044,0.00463646241774424 \ 0,2.66765929383284e-05,0.000281563589013347,0.000466850681408009,0.000506933757806273,0.000609848729430626 \ -0.450811556523643,-0.816852292048691,-1.33465923808859,-1.67080357834546,-1.60068995272926,-1.53391838418534 )

. di mreldif(S,G)
.00515341

. assert mreldif(S,G)<0.01

.
. lassologit v58 v1-v57 , ///
>         l(.15 .1 .05 .025 0.01 0.005) nocons  lambdan
Obtaining solution for 6 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.15000    1     0.02234   6328.73191  -0.0251  | Added v25.
     2 |   2    0.10000    8     1.01900   5756.45348   0.0718  | Added v7 v21
      |                                                         | v23 v26 v27
      |                                                         | v37 v53.
     3 |   3    0.05000   19     4.75354   4429.24805   0.2935  | Added v12
      |                                                         | v16 v17 v20
      |                                                         | v24 v33 v42
      |                                                         | v45 v46 v50
      |                                                         | v52.
     4 |   4    0.02500   31     9.77793   3492.58347   0.4525  | Added v2 v5
      |                                                         | v6 v8 v9 v39
      |                                                         | v43 v44 v48
      |                                                         | v49 v56 v57.
     5 |   5    0.01000   41    18.75168   2807.93625   0.5695  | Added v1 v15
      |                                                         | v18 v19 v22
      |                                                         | v29 v35 v41
      |                                                         | v47 v51.
     6 |   6    0.00500   47    26.67062   2521.58283   0.6195  | Added v4 v13
      |                                                         | v30 v31 v38
      |                                                         | v40.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S = e(betas)'

. mat list S

S[57,6]
             r1          r2          r3          r4          r5          r6
 v1           0           0           0           0  -.02006146  -.18090915
 v2           0           0           0  -.04397075  -.11544876  -.15729578
 v3           0           0           0           0           0           0
 v4           0           0           0           0           0   .02487242
 v5           0           0           0   .06679465   .19566852    .2595454
 v6           0           0           0   .00224677   .11656607   .20003938
 v7           0   .26501312   .79336838   1.2430608   1.7000844   1.9126355
 v8           0           0           0   .15221167    .2964563   .35787464
 v9           0           0           0   .02503226   .13771482    .2228854
v10           0           0           0           0           0           0
v11           0           0           0           0           0           0
v12           0           0   -.0629518  -.19501881  -.29156238  -.31418649
v13           0           0           0           0           0  -.08752765
v14           0           0           0           0           0           0
v15           0           0           0           0   .12040248   .35415977
v16           0           0   .10674838   .21247738   .32846378   .50138712
v17           0           0   .07100616   .21720529   .42037042   .56911052
v18           0           0           0           0   .04861229   .05754801
v19           0           0           0           0   -.0207722  -.04358666
v20           0           0   .02388992   .14960086   .29274787   .39807502
v21           0    .0024332   .06800583   .08331972   .08944981   .10543508
v22           0           0           0           0   .07750573   .14207058
v23           0    .2750091   .72503215   1.0667761   1.4427915   1.7201123
v24           0           0   .04791781    .2176692   .39468616   .47242716
v25   -.0223441  -.13268058  -.31353422  -.54830069  -.93692639  -1.2345624
v26           0  -.06089072  -.17754863  -.27709908   -.4647039  -.63136187
v27           0  -.01037416  -.07015976  -.12790323  -.25766454  -.51781556
v28           0           0           0           0           0           0
v29           0           0           0           0   -.0450506  -.35917998
v30           0           0           0           0           0  -.16185654
v31           0           0           0           0           0  -.04609584
v32           0           0           0           0           0           0
v33           0           0  -.08286867  -.28532324  -.58998655  -.79166097
v34           0           0           0           0           0           0
v35           0           0           0           0  -.09188217  -.21969196
v36           0           0           0           0           0           0
v37           0  -.06303259  -.30753902  -.38442604  -.35838327  -.31491949
v38           0           0           0           0           0  -.19187318
v39           0           0           0  -.04027656  -.21187894  -.35221793
v40           0           0           0           0           0  -.04833423
v41           0           0           0           0  -.10331514  -.40679861
v42           0           0  -.10372879  -.30584167  -.65985754   -.9641552
v43           0           0           0  -.03729477  -.33016877  -.57401122
v44           0           0           0  -.12648919  -.43642652  -.76291731
v45           0           0  -.16845035  -.36942115  -.60394324  -.73782218
v46           0           0  -.15989831  -.39750034  -.80081566  -1.1105821
v47           0           0           0           0  -.51157757  -.90202991
v48           0           0           0  -.09682151  -.49240934  -.92725786
v49           0           0           0   -.1204262  -.55872185  -.85199978
v50           0           0  -.25640046  -.73441925  -1.0800519  -1.1075618
v51           0           0           0           0   -.6243036  -1.1961592
v52           0           0   .02453401   .11323843   .19691359   .22739505
v53           0   .20956966   1.1899609   2.1372702     3.28624   3.9489588
v54           0           0           0           0           0           0
v55           0           0           0           0           0           0
v56           0           0           0   .00045081   .00094955   .00149993
v57           0           0           0   .00004226   .00014186   .00021363

. mat G = ( 0,0,0,0,-0.0200867422123263,-0.180963081874258 \ 0,0,0,-0.0439725562644103,-0.115450410602825,-0.157305593166378 \ 0,0,0,0,0,0 \ 0,0,0,0,0,0.0248737630594846 \ 0,0,0,0.0667434523874724,0.195672120448769,0.259593231810163 \ 0,0,0,0.00222441489484255,0.116547135797629,0.199900956245658 \ 0,0.265014956681658,0.793520363853869,1.24314797930455,1.70013010830079,1.91290049195925 \ 0,0,0,0.152197580164138,0.296452514725046,0.357887094370555 \ 0,0,0,0.0250243043582219,0.137697541543941,0.222761802503909 \ 0,0,0,0,0,0 \ 0,0,0,0,0,0 \ 0,0,-0.0630453430573573,-0.195111020480451,-0.291546951127566,-0.314161971862145 \ 0,0,0,0,0,-0.08756211017273 \ 0,0,0,0,0,0 \ 0,0,0,0,0.120424279364554,0.354187006038407 \ 0,0,0.106750439452276,0.21245760092625,0.328425173653119,0.500696339873835 \ 0,0,0.0709425995331555,0.217156375324238,0.420379234649733,0.56920674322488 \ 0,0,0,0,0.048629175049587,0.057696989533041 \ 0,0,0,0,-0.020789895089672,-0.0436000934364041 \ 0,0,0.0239005584077038,0.149615451999137,0.292733534056024,0.398108722332453 \ 0,0.00243201716946116,0.0680387538806802,0.083328722308754,0.0894534268473376,0.105425668464145 \ 0,0,0,0,0.0775090077892467,0.142075075770615 \ 0,0.275009205461234,0.72537916118375,1.06698790895246,1.44280441321528,1.72027974501352 \ 0,0,0.0479845894262583,0.217738196069698,0.394705684203277,0.472496250592033 \ -0.0223440877877455,-0.132668414169889,-0.313488233648016,-0.54838389731916,-0.936938075822474,-1.23481713891759 \ 0,-0.0609006144400859,-0.177568921138646,-0.277026881054149,-0.464709312028651,-0.63142026128668 \ 0,-0.0103741892860181,-0.070161267233627,-0.127904803022036,-0.257652912101769,-0.517338734762027 \ 0,0,0,0,0,0 \ 0,0,0,0,-0.0450461646744678,-0.359265300176881 \ 0,0,0,0,0,-0.161867521620582 \ 0,0,0,0,0,-0.046122253319544 \ 0,0,0,0,0,0 \ 0,0,-0.0828692104212642,-0.285316225156789,-0.58997916306237,-0.791695735414731 \ 0,0,0,0,0,0 \ 0,0,0,0,-0.0918778074927649,-0.219650592530303 \ 0,0,0,0,0,0 \ 0,-0.0630371681660719,-0.307539958672982,-0.384470440494363,-0.358372967333063,-0.314884147985183 \ 0,0,0,0,0,-0.191588425277942 \ 0,0,0,-0.0403046841400879,-0.211868440351775,-0.352145422328576 \ 0,0,0,0,0,-0.0483661679280512 \ 0,0,0,0,-0.10331814625645,-0.406815105529768 \ 0,0,-0.103710299079598,-0.305807487194226,-0.659857431681319,-0.964166817374027 \ 0,0,0,-0.037295524567914,-0.330160931322528,-0.57400332534841 \ 0,0,0,-0.126478415974642,-0.436418725123807,-0.762901014782063 \ 0,0,-0.168444091298225,-0.369421777328527,-0.603931392308208,-0.737816371222742 \ 0,0,-0.159895066345096,-0.397474317934418,-0.800796674646007,-1.11051462265085 \ 0,0,0,0,-0.511551026426417,-0.901980884578981 \ 0,0,0,-0.0967782082998046,-0.492401520570917,-0.927186765734769 \ 0,0,0,-0.120380350625124,-0.558716653197135,-0.851922825943988 \ 0,0,-0.256214350603698,-0.734193287497686,-1.08003814069837,-1.1074304761778 \ 0,0,0,0,-0.624291484186726,-1.19610720319507 \ 0,0,0.0245878706303293,0.11327052634246,0.196926767089997,0.227467498113895 \ 0,0.209570688353242,1.18953467225439,2.1372473049678,3.28631916741697,3.94944398020316 \ 0,0,0,0,0,0 \ 0,0,0,0,0,0 \ 0,0,0,0.000450775511481365,0.000949618067924462,0.00150040170166375 \ 0,0,0,4.22564218203648e-05,0.000141854663994748,0.000213631540830992 )

. di mreldif(S,G)
.0004603

. assert mreldif(S,G)<0.03

.
. lassologit v58 v1-v57 , ///
>         l(10 0.1 0.05 0.01 .005 0.001) nostd lambdan
Obtaining solution for 6 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
......

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   10.00000    2     0.75408   5758.94875   0.0679  | Added v56
      |                                                         | v57 _cons.
     2 |   2    0.10000    6     1.87688   4632.59750   0.2528  | Added v19
      |                                                         | v21 v25 v27.
     3 |   3    0.05000    9     2.74988   4135.43661   0.3352  | Added v16
      |                                                         | v52 v55.
     4 |   4    0.01000   27    10.21759   2767.41411   0.5679  | Added v2 v4
      |                                                         | v5 v7 v8 v12
      |                                                         | v17 v18 v20
      |                                                         | v22 v23 v24
      |                                                         | v26 v33 v42
      |                                                         | v44 v45 v46
      |                                                         | v53. Removed
      |                                                         | v55.
     5 |   5    0.00500   31    15.55915   2431.09288   0.6248  | Added v6 v10
      |                                                         | v49 v55.
     6 |   6    0.00100   48    32.78656   2122.06825   0.6852  | Added v1 v3
      |                                                         | v9 v14 v15
      |                                                         | v28 v29 v30
      |                                                         | v35 v36 v37
      |                                                         | v38 v39 v41
      |                                                         | v43 v48 v54.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S = e(betas)'

. mat list S

S[58,6]
               r1          r2          r3          r4          r5          r6
   v1           0           0           0           0           0  -.19778409
   v2           0           0           0  -.02640737  -.06282796  -.11831854
   v3           0           0           0           0           0   .10221539
   v4           0           0           0   .00518221   .04337058   .25484087
   v5           0           0           0   .37784565   .45682998   .55176417
   v6           0           0           0           0   .26936548   .62339715
   v7           0           0           0   1.1006582   1.5430766   2.1306211
   v8           0           0           0   .32065644   .44505385   .54499121
   v9           0           0           0           0           0   .44496574
  v10           0           0           0           0   .02054731   .10119139
  v11           0           0           0           0           0           0
  v12           0           0           0  -.05321805  -.11009053  -.14445188
  v13           0           0           0           0           0           0
  v14           0           0           0           0           0   .05455388
  v15           0           0           0           0           0   .11401183
  v16           0           0   .21936492   .72878669   .82821067   .93594303
  v17           0           0           0   .23558133   .45950723   .79569813
  v18           0           0           0   .08954057   .14845751   .14070056
  v19           0   .10940662    .1294832   .10910207   .10041799   .08834172
  v20           0           0           0   .09607662   .21704328   .56898511
  v21           0   .15584491   .28833021   .29535417   .26434445   .22769464
  v22           0           0           0   .05732173   .08980879   .23328379
  v23           0           0           0   .89897318      1.2347   1.8468381
  v24           0           0           0   .21392671   .39514922   .50367481
  v25           0  -.13762482  -.42827084  -1.1855121  -1.4214046   -1.785415
  v26           0           0           0  -.04584883  -.23042398  -.69433495
  v27           0   -.0487535  -.14705382  -.81880034  -1.3521354  -3.9525403
  v28           0           0           0           0           0   .22122084
  v29           0           0           0           0           0   -.5740448
  v30           0           0           0           0           0  -.03702865
  v31           0           0           0           0           0           0
  v32           0           0           0           0           0           0
  v33           0           0           0   -.0939157  -.27757642  -.66033463
  v34           0           0           0           0           0           0
  v35           0           0           0           0           0  -.37652156
  v36           0           0           0           0           0    .4602056
  v37           0           0           0           0           0  -.02352392
  v38           0           0           0           0           0  -.13248341
  v39           0           0           0           0           0    -.433889
  v40           0           0           0           0           0           0
  v41           0           0           0           0           0  -.47952157
  v42           0           0           0  -.36844948  -.62316777  -1.3808727
  v43           0           0           0           0           0   -.1410597
  v44           0           0           0  -.01742596  -.18149697  -.89246981
  v45           0           0           0  -.26919949  -.38036262  -.61729771
  v46           0           0           0  -.54664452  -.86596257  -1.3275106
  v47           0           0           0           0           0           0
  v48           0           0           0           0           0  -.78504838
  v49           0           0           0           0  -.04177491  -.76203782
  v50           0           0           0           0           0           0
  v51           0           0           0           0           0           0
  v52           0           0   .03888133    .3910668   .40061504   .40088796
  v53           0           0           0   .29974488   1.5271148   4.1510453
  v54           0           0           0           0           0   .22281122
  v55           0           0   .00218539           0  -.00176158  -.01271967
  v56    .0002509   .02115678   .01910168   .01230366    .0102625   .00877865
  v57    .0011691   .00015296   .00024273   .00041311    .0004295   .00047305
_cons  -.75266054   -1.403943  -1.4769654  -1.5596371  -1.5558633  -1.5282169

. mat G = ( 0,0,0,0,0,-0.196606830871361 \ 0,0,0,-0.0263959141205755,-0.0627951579638412,-0.118426808731766 \ 0,0,0,0,0,0.102694111984808 \ 0,0,0,0.00516845136302719,0.0433845100498495,0.255066666352933 \ 0,0,0,0.377850977275016,0.456724641505493,0.551590006500719 \ 0,0,0,0,0.269285747828233,0.621688751483009 \ 0,0,0,1.10087981403029,1.54368806896071,2.13177925264091 \ 0,0,0,0.320728980387188,0.445263521331234,0.544826963080417 \ 0,0,0,0,0,0.443649074799542 \ 0,0,0,0,0.0204087663270599,0.100911255476619 \ 0,0,0,0,0,0 \ 0,0,0,-0.0531937638595258,-0.110026127046077,-0.144729540552861 \ 0,0,0,0,0,0 \ 0,0,0,0,0,0.0541979592970806 \ 0,0,0,0,0,0.115097436073612 \ 0,0,0.219337625782819,0.728276302338932,0.828344228043666,0.936568757145528 \ 0,0,0,0.235627862792052,0.459662402282917,0.794066489512141 \ 0,0,0,0.0896053571721042,0.148727268825427,0.141156832349543 \ 0,0.109401406887508,0.12949040110083,0.109114656531446,0.100431962365842,0.088465900027753 \ 0,0,0,0.0960780992452676,0.217083256616456,0.56966154977343 \ 0,0.155863471226981,0.288325708867917,0.295300028640053,0.2642762693284,0.227564580072034 \ 0,0,0,0.0573220238010432,0.0897145232657215,0.233672717839671 \ 0,0,0,0.899098761929624,1.23558597332666,1.84929666229257 \ 0,0,0,0.213989045389802,0.395496066797918,0.50471797450479 \ 0,-0.137633831311825,-0.428258460781284,-1.18581357954125,-1.42295663664892,-1.78665244112237 \ 0,0,0,-0.0457689200355376,-0.229636533094445,-0.693978642684788 \ 0,-0.0487632571003764,-0.147039973104196,-0.816361941819738,-1.33920940706366,-3.83283619415318 \ 0,0,0,0,0,0.221839810370222 \ 0,0,0,0,0,-0.571676198017221 \ 0,0,0,0,0,-0.034641955163953 \ 0,0,0,0,0,0 \ 0,0,0,0,0,0 \ 0,0,0,-0.0939506854962543,-0.277644336330768,-0.660202193225169 \ 0,0,0,0,0,0 \ 0,0,0,0,0,-0.375211673639146 \ 0,0,0,0,0,0.462589340216143 \ 0,0,0,0,0,-0.0233857855396148 \ 0,0,0,0,0,-0.13273040571758 \ 0,0,0,0,0,-0.432952185786407 \ 0,0,0,0,0,0 \ 0,0,0,0,0,-0.47832595201352 \ 0,0,0,-0.368318040619443,-0.622511232094226,-1.37637221332031 \ 0,0,0,0,0,-0.139810725682437 \ 0,0,0,-0.0174002302406321,-0.181242700957882,-0.891323650902357 \ 0,0,0,-0.269149657094932,-0.380150922271061,-0.616870622105827 \ 0,0,0,-0.546281049241329,-0.864630097661637,-1.32512423900005 \ 0,0,0,0,0,0 \ 0,0,0,0,0,-0.783172594822248 \ 0,0,0,0,-0.0417654564340482,-0.762406591054006 \ 0,0,0,0,0,0 \ 0,0,0,0,0,0 \ 0,0,0.0388465427763881,0.391143596322809,0.400821242459232,0.401755305686915 \ 0,0,0,0.299926255332921,1.528093609498,4.15578120724715 \ 0,0,0,0,0,0.224049518522976 \ 0,0,0.00228751649055222,0,-0.00149114153314493,-0.0126854106956653 \ 0.000251176249855191,0.0211531130365377,0.0190977387878989,0.0123128199830305,0.0102571927074542,0.0087378756648603 \ 0.00116904746155995,0.000153035327786397,0.000242754480855713,0.000412991010293585,0.000429815225601432,0.000473779800524816 \ -0.752661384082521,-1.40386117252347,-1.47716148408643,-1.56003952656892,-1.55744581223666,-1.5298166412315 )

. di mreldif(S,G)
.02476892

. assert mreldif(S,G)<0.03 // 3% deviation!

.
. lassologit v58 v1-v57 , ///
>         l(40 10 1  0.1  0.05) nocons nostd lambdan
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   40.00000    1     0.00003   6368.88594  -0.0316  | Added v57.
     2 |   3    1.00000    2     0.00561   6097.93229   0.0129  | Added v56.
     3 |   4    0.10000    5     0.59380   5138.62109   0.1702  | Added v25
      |                                                         | v27 v55.
     4 |   5    0.05000   11     1.66613   4497.91281   0.2776  | Added v2 v12
      |                                                         | v16 v21 v42
      |                                                         | v45 v46.
      |                                                         | Removed v57.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat S = e(betas)'

. mat list S

S[57,5]
             r1          r2          r3          r4          r5
 v1           0           0           0           0           0
 v2           0           0           0           0  -.00388742
 v3           0           0           0           0           0
 v4           0           0           0           0           0
 v5           0           0           0           0           0
 v6           0           0           0           0           0
 v7           0           0           0           0           0
 v8           0           0           0           0           0
 v9           0           0           0           0           0
v10           0           0           0           0           0
v11           0           0           0           0           0
v12           0           0           0           0  -.06085059
v13           0           0           0           0           0
v14           0           0           0           0           0
v15           0           0           0           0           0
v16           0           0           0           0   .06414037
v17           0           0           0           0           0
v18           0           0           0           0           0
v19           0           0           0           0           0
v20           0           0           0           0           0
v21           0           0           0           0   .07938986
v22           0           0           0           0           0
v23           0           0           0           0           0
v24           0           0           0           0           0
v25           0           0           0  -.43330804  -.82648479
v26           0           0           0           0           0
v27           0           0           0  -.14477986  -.27017973
v28           0           0           0           0           0
v29           0           0           0           0           0
v30           0           0           0           0           0
v31           0           0           0           0           0
v32           0           0           0           0           0
v33           0           0           0           0           0
v34           0           0           0           0           0
v35           0           0           0           0           0
v36           0           0           0           0           0
v37           0           0           0           0           0
v38           0           0           0           0           0
v39           0           0           0           0           0
v40           0           0           0           0           0
v41           0           0           0           0           0
v42           0           0           0           0  -.00074516
v43           0           0           0           0           0
v44           0           0           0           0           0
v45           0           0           0           0  -.14858306
v46           0           0           0           0  -.18729426
v47           0           0           0           0           0
v48           0           0           0           0           0
v49           0           0           0           0           0
v50           0           0           0           0           0
v51           0           0           0           0           0
v52           0           0           0           0           0
v53           0           0           0           0           0
v54           0           0           0           0           0
v55           0           0           0   -.0063939  -.01403062
v56           0           0   .00561154   .00927929   .01054754
v57   .00003411   .00038152  -9.444e-07  -.00004264           0

. mat G = ( 0,0,0,0,0 \ 0,0,0,0,-0.00388390194575201 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,-0.0608399932100172 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0.0641514339556632 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0.0793813559307355 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,-0.433326247098604,-0.826496410034253 \ 0,0,0,0,0 \ 0,0,0,-0.144784796466159,-0.270173956885227 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,-0.000744445387214381 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,-0.148578232510563 \ 0,0,0,0,-0.187291134609176 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,0,0 \ 0,0,0,-0.00636951077256207,-0.0140453997113308 \ 0,0,0.00561069230547681,0.00927731836362141,0.01054896589884 \ 3.41081748400473e-05,0.000381523296092164,-8.95105672525863e-07,-4.26170125134684e-05,0 )

. di mreldif(S,G)
.00002423

. assert mreldif(S,G)<0.01

.
.
. ********************************************************************************
. *** Verify largest lambda value: Spam data                                                                       ***
. *** comparison with glmnet                                                                                                       ***
. ********************************************************************************
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. // OK
. lassologit v58 v1-v57 , lambdan lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.18727    0     0.43034   6170.15284   0.0000  | Added _cons.
     2 |   2    0.01873   28    13.05968   2942.59413   0.5401  | Added v3 v5
      |                                                         | v6 v7 v8 v9
      |                                                         | v16 v17 v18
      |                                                         | v19 v20 v21
      |                                                         | v22 v23 v24
      |                                                         | v25 v26 v27
      |                                                         | v33 v37 v42
      |                                                         | v44 v45 v46
      |                                                         | v52 v53 v56
      |                                                         | v57.
     3 |   3    0.00187   52    35.30333   2183.44429   0.6777  | Added v1 v2
      |                                                         | v4 v10 v12
      |                                                         | v14 v15 v28
      |                                                         | v29 v30 v31
      |                                                         | v35 v36 v38
      |                                                         | v39 v40 v41
      |                                                         | v43 v47 v48
      |                                                         | v49 v50 v51
      |                                                         | v54.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
.18726511

. assert reldif(L[1,1],0.1872651)<10e-5

.
. // OK
. lassologit v58 v1-v57 , nostd lambdan  lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   73.81646    0     0.43034   6170.15284   0.0000  | Added _cons.
     2 |   2    7.38165    2     0.78779   5653.70028   0.0849  | Added v56
      |                                                         | v57.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
73.816459

. assert reldif(L[1,1],73.81646)<10e-5

.
. // OK
. lassologit v58 v1-v57 , nocons lambdan  lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   2    0.01603   37    13.90974   3103.63775   0.5191  | Added v2 v5
      |                                                         | v6 v7 v8 v9
      |                                                         | v12 v15 v16
      |                                                         | v17 v18 v20
      |                                                         | v21 v22 v23
      |                                                         | v24 v25 v26
      |                                                         | v27 v33 v35
      |                                                         | v37 v39 v42
      |                                                         | v43 v44 v45
      |                                                         | v46 v47 v48
      |                                                         | v49 v50 v51
      |                                                         | v52 v53 v56
      |                                                         | v57.
     2 |   3    0.00160   51    40.48332   2295.62807   0.6585  | Added v1 v4
      |                                                         | v10 v13 v14
      |                                                         | v19 v28 v29
      |                                                         | v30 v31 v38
      |                                                         | v40 v41 v54.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
.16028589

. assert reldif(L[1,1],0.1602859)<10e-5

.
. // OK
. lassologit v58 v1-v57 , nocons nostd lambdan  lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   43.80048    0     0.00000   6378.34036  -0.0337  | Added v57.
     2 |   2    4.38005    2     0.00246   6170.28359   0.0012  | Added v56.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
43.800478

. assert reldif(L[1,1],43.80048)<10e-5

.
.
. ********************************************************************************
. *** Verify largest lambda value: Prostate data                                                           ***
. *** comparison with glmnet                                                                                                       ***
. ********************************************************************************
.
. insheet using prostate.data, clear
(11 vars, 97 obs)

.
. gen ybin = lpsa > 2

.
. // OK
. lassologit ybin lcavol-pgg45 , lambdan  lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.24793    0     0.75567    121.55230   0.0000  | Added _cons.
     2 |   2    0.02479    5    14.15184     85.09286   0.3829  | Added lcavol
      |                                                         | lweight lbph
      |                                                         | svi gleason.
     3 |   3    0.00248    8    25.01865     83.24043   0.4479  | Added age
      |                                                         | lcp pgg45.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
.2479347

. assert reldif(L[1,1],0.2479347)<10e-5

.
. // OK
. lassologit ybin lcavol-pgg45 , nostd lambdan  lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    4.28685    0     0.75567    121.55230   0.0000  | Added pgg45
      |                                                         | _cons.
     2 |   3    0.04287    3     1.62046     92.81631   0.2862  | Added lcavol
      |                                                         | lbph.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
4.286853

. assert reldif(L[1,1],4.286853)<10e-5

.
. // OK
. lassologit ybin lcavol-pgg45, nocons lambdan lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   2    0.18871    3     0.29577    113.64207   0.1061  | Added lcavol
      |                                                         | lweight
      |                                                         | gleason.
     2 |   3    0.01887    7     3.32475     91.25771   0.3450  | Added age
      |                                                         | lbph svi
      |                                                         | pgg45.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
1.8870631

. assert reldif(L[1,1],1.887063)<10e-5

.
. // OK
. lassologit ybin lcavol-pgg45 , nocons nostd lambdan lcount(3)
Obtaining solution for 3 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
...

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   12.14948    0     0.00000    134.47055  -0.1063  | Added age.
     2 |   2    1.21495    2     0.02635    113.45851   0.0940  | Added pgg45.
     3 |   3    0.12149    4     0.42297    103.64897   0.2020  | Added lcavol
      |                                                         | lbph.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat L= e(lambdas)

. di L[1,1]
12.149485

. assert reldif(L[1,1],12.14948)<10e-5

.
.
. ********************************************************************************
. *** plotting                                                                 ***
. ********************************************************************************
.
. clear all

.
. insheet using prostate.data, clear
(11 vars, 97 obs)

.
. gen ybin = lpsa > 2

.
. lassologit ybin lcavol-pgg45, plotpath(lambda)
Obtaining solution for 50 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50


  Knot|  ID     Lambda    s      L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   24.04967    0     0.75567    121.55230   0.0000  | Added _cons.
     2 |   2   21.89237    1     0.72708    118.88228   0.0386  | Added
      |                                                         | lcavol.
     3 |   7   13.68394    3     0.69877    107.79964   0.1629  | Added
      |                                                         | lweight
      |                                                         | gleason.
     4 |  14    7.08756    4     7.64951     93.43198   0.2977  | Added svi.
     5 |  17    5.34623    5     9.95724     91.46466   0.3305  | Added lbph.
     6 |  28    1.90138    6    15.02132     86.13353   0.3909  | Added age.
     7 |  31    1.43423    7    15.84016     86.71472   0.4028  | Added lcp.
     8 |  34    1.08186    8    17.52795     86.80734   0.4186  | Added pgg45.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

.
. lassologit ybin lcavol-pgg45, plotpath(lnlambda) plotvar(age svi)
Obtaining solution for 50 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50


  Knot|  ID     Lambda    s      L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   24.04967    0     0.75567    121.55230   0.0000  | Added _cons.
     2 |   2   21.89237    1     0.72708    118.88228   0.0386  | Added
      |                                                         | lcavol.
     3 |   7   13.68394    3     0.69877    107.79964   0.1629  | Added
      |                                                         | lweight
      |                                                         | gleason.
     4 |  14    7.08756    4     7.64951     93.43198   0.2977  | Added svi.
     5 |  17    5.34623    5     9.95724     91.46466   0.3305  | Added lbph.
     6 |  28    1.90138    6    15.02132     86.13353   0.3909  | Added age.
     7 |  31    1.43423    7    15.84016     86.71472   0.4028  | Added lcp.
     8 |  34    1.08186    8    17.52795     86.80734   0.4186  | Added pgg45.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.
(50 real changes made)

.
. lassologit ybin lcavol-pgg45, plotpath(norm)
Obtaining solution for 50 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50


  Knot|  ID     Lambda    s      L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1   24.04967    0     0.75567    121.55230   0.0000  | Added _cons.
     2 |   2   21.89237    1     0.72708    118.88228   0.0386  | Added
      |                                                         | lcavol.
     3 |   7   13.68394    3     0.69877    107.79964   0.1629  | Added
      |                                                         | lweight
      |                                                         | gleason.
     4 |  14    7.08756    4     7.64951     93.43198   0.2977  | Added svi.
     5 |  17    5.34623    5     9.95724     91.46466   0.3305  | Added lbph.
     6 |  28    1.90138    6    15.02132     86.13353   0.3909  | Added age.
     7 |  31    1.43423    7    15.84016     86.71472   0.4028  | Added lcp.
     8 |  34    1.08186    8    17.52795     86.80734   0.4186  | Added pgg45.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

.
.
. ********************************************************************************
. *** verify post-logit and log-lik value                                                                          ***
. ********************************************************************************
.
. clear all

.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. foreach lam of numlist 0.187 0.1 0.07 0.05 0.01 0.005 {
  2.
.         lassologit v58 v1-v57, l(`lam')   postl lambdan
  3.         mat b1 = e(b)
  4.         local L1 = e(ll)
  5.
.         local sel = e(selected)
  6.         di "lambda=`lam'; selected=`sel'"
  7.
.         logit v58 `sel', iterate(100)
  8.         mat b2 = e(b)
  9.         local L2 = e(ll)
 10.
.         di mreldif(b1,b2)
 11.
.         assert mreldif(b1,b2)<0.0001
 12.
.         // verify loglik
.         assert reldif(`L1',`L2')<0.01
 13.
. }

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v21 |       0.0009245      0.8584517
            _cons |      -0.4310903     -1.1097109
------------------+--------------------------------
lambda=.187; selected=v21

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -2704.3835
Iteration 2:   log likelihood = -2703.6411
Iteration 3:   log likelihood = -2703.6409

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(1)        =     762.87
                                                Prob > chi2       =     0.0000
Log likelihood = -2703.6409                     Pseudo R2         =     0.1236

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
         v21 |    .8584517    .0368163     23.32    0.000       .786293     .9306104
       _cons |   -1.109711    .0423539    -26.20    0.000     -1.192723    -1.026699
-------------+----------------------------------------------------------------
2.234e-14

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5412442      4.2194397
              v16 |       0.0569502      0.8984170
              v21 |       0.2448168      0.3940148
              v23 |       0.5126734      3.8072262
              v25 |      -0.0071134     -2.7490367
              v53 |       0.6310249      7.5984195
              v57 |       0.0000267      0.0011889
            _cons |      -0.8168528     -1.7667647
------------------+--------------------------------
lambda=.1; selected=v7 v16 v21 v23 v25 v53 v57

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1756.6861
Iteration 2:   log likelihood = -1569.5018
Iteration 3:   log likelihood = -1512.4228
Iteration 4:   log likelihood = -1506.6144
Iteration 5:   log likelihood = -1506.5064
Iteration 6:   log likelihood = -1506.5064

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(7)        =    3157.14
                                                Prob > chi2       =     0.0000
Log likelihood = -1506.5064                     Pseudo R2         =     0.5117

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v7 |     4.21944    .3657308     11.54    0.000      3.502621     4.936259
         v16 |     .898417    .0914536      9.82    0.000      .7191713     1.077663
         v21 |    .3940148     .036492     10.80    0.000      .3224919     .4655378
         v23 |    3.807226    .4987968      7.63    0.000      2.829602      4.78485
         v25 |   -2.749037    .2717015    -10.12    0.000     -3.281562    -2.216512
         v53 |    7.598419    .6620765     11.48    0.000      6.300773     8.896066
         v57 |    .0011889    .0001322      8.99    0.000      .0009298     .0014481
       _cons |   -1.766765    .0655888    -26.94    0.000     -1.895316    -1.638213
-------------+----------------------------------------------------------------


Note: 79 failures and 21 successes completely determined.


1.460e-14
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.0887044      0.4964612
               v6 |       0.0811235      0.6855995
               v7 |       0.8573039      3.7048664
               v9 |       0.0064684      0.9253495
              v16 |       0.1696675      0.7676800
              v17 |       0.0894093      1.3384307
              v19 |       0.0204993      0.0869667
              v21 |       0.2812394      0.2667653
              v23 |       0.7421537      3.4884730
              v24 |       0.0176598      0.9186041
              v25 |      -0.0664837     -2.5250532
              v52 |       0.0938832      0.6999923
              v53 |       1.1233156      6.3545899
              v57 |       0.0001765      0.0011362
            _cons |      -1.0934878     -2.3874793
------------------+--------------------------------
lambda=.07; selected=v5 v6 v7 v9 v16 v17 v19 v21 v23 v24 v25 v52 v53 v57

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1562.0991
Iteration 2:   log likelihood = -1386.1929
Iteration 3:   log likelihood = -1344.9381
Iteration 4:   log likelihood = -1339.1676
Iteration 5:   log likelihood = -1339.1627
Iteration 6:   log likelihood = -1339.1627  (backed up)
Iteration 7:   log likelihood = -1339.1627  (backed up)
Iteration 8:   log likelihood = -1339.1627  (backed up)
Iteration 9:   log likelihood = -1339.1627  (backed up)
Iteration 10:  log likelihood = -1339.1627  (backed up)
Iteration 11:  log likelihood = -1339.1627  (backed up)
Iteration 12:  log likelihood = -1339.1627  (backed up)
Iteration 13:  log likelihood = -1339.1627  (backed up)
Iteration 14:  log likelihood = -1339.1627  (backed up)
Iteration 15:  log likelihood = -1339.1627  (backed up)
Iteration 16:  log likelihood = -1339.1627  (backed up)
Iteration 17:  log likelihood = -1339.1627  (backed up)
Iteration 18:  log likelihood = -1339.1627  (backed up)
Iteration 19:  log likelihood = -1339.1627  (backed up)
Iteration 20:  log likelihood = -1339.1627  (backed up)
Iteration 21:  log likelihood = -1339.1627  (backed up)
Iteration 22:  log likelihood = -1339.1627  (backed up)
Iteration 23:  log likelihood = -1339.1627  (backed up)
Iteration 24:  log likelihood = -1339.1627  (backed up)
Iteration 25:  log likelihood = -1339.1627  (backed up)
Iteration 26:  log likelihood = -1339.1627  (backed up)
Iteration 27:  log likelihood = -1339.1627  (backed up)
Iteration 28:  log likelihood = -1339.1627  (backed up)
Iteration 29:  log likelihood = -1339.1627  (backed up)
Iteration 30:  log likelihood = -1339.1627  (backed up)
Iteration 31:  log likelihood = -1339.1627  (backed up)
Iteration 32:  log likelihood = -1339.1627  (backed up)
Iteration 33:  log likelihood = -1339.1627  (backed up)
Iteration 34:  log likelihood = -1339.1627  (backed up)
Iteration 35:  log likelihood = -1339.1627  (backed up)
Iteration 36:  log likelihood = -1339.1627  (backed up)
Iteration 37:  log likelihood = -1339.1627  (backed up)
Iteration 38:  log likelihood = -1339.1627  (backed up)
Iteration 39:  log likelihood = -1339.1627  (backed up)
Iteration 40:  log likelihood = -1339.1627  (backed up)
Iteration 41:  log likelihood = -1339.1627  (backed up)
Iteration 42:  log likelihood = -1339.1627  (backed up)
Iteration 43:  log likelihood = -1339.1627  (backed up)
Iteration 44:  log likelihood = -1339.1627  (backed up)
Iteration 45:  log likelihood = -1339.1627  (backed up)
Iteration 46:  log likelihood = -1339.1627  (backed up)
Iteration 47:  log likelihood = -1339.1627  (backed up)
Iteration 48:  log likelihood = -1339.1627  (backed up)
Iteration 49:  log likelihood = -1339.1627  (backed up)
Iteration 50:  log likelihood = -1339.1627  (backed up)
Iteration 51:  log likelihood = -1339.1627  (backed up)
Iteration 52:  log likelihood = -1339.1627  (backed up)
Iteration 53:  log likelihood = -1339.1627  (backed up)
Iteration 54:  log likelihood = -1339.1627  (backed up)
Iteration 55:  log likelihood = -1339.1627  (backed up)
Iteration 56:  log likelihood = -1339.1627  (backed up)
Iteration 57:  log likelihood = -1339.1627  (backed up)
Iteration 58:  log likelihood = -1339.1627  (backed up)
Iteration 59:  log likelihood = -1339.1627  (backed up)
Iteration 60:  log likelihood = -1339.1627  (backed up)
Iteration 61:  log likelihood = -1339.1627  (backed up)
Iteration 62:  log likelihood = -1339.1627  (backed up)
Iteration 63:  log likelihood = -1339.1627  (backed up)
Iteration 64:  log likelihood = -1339.1627  (backed up)
Iteration 65:  log likelihood = -1339.1627  (backed up)
Iteration 66:  log likelihood = -1339.1627  (backed up)
Iteration 67:  log likelihood = -1339.1627  (backed up)
Iteration 68:  log likelihood = -1339.1627  (backed up)
Iteration 69:  log likelihood = -1339.1627  (backed up)
Iteration 70:  log likelihood = -1339.1627  (backed up)
Iteration 71:  log likelihood = -1339.1627  (backed up)
Iteration 72:  log likelihood = -1339.1627  (backed up)
Iteration 73:  log likelihood = -1339.1627  (backed up)
Iteration 74:  log likelihood = -1339.1627  (backed up)
Iteration 75:  log likelihood = -1339.1627  (backed up)
Iteration 76:  log likelihood = -1339.1627  (backed up)
Iteration 77:  log likelihood = -1339.1627  (backed up)
Iteration 78:  log likelihood = -1339.1627  (backed up)
Iteration 79:  log likelihood = -1339.1627  (backed up)
Iteration 80:  log likelihood = -1339.1627  (backed up)
Iteration 81:  log likelihood = -1339.1627  (backed up)
Iteration 82:  log likelihood = -1339.1627  (backed up)
Iteration 83:  log likelihood = -1339.1627  (backed up)
Iteration 84:  log likelihood = -1339.1627  (backed up)
Iteration 85:  log likelihood = -1339.1627  (backed up)
Iteration 86:  log likelihood = -1339.1627  (backed up)
Iteration 87:  log likelihood = -1339.1627  (backed up)
Iteration 88:  log likelihood = -1339.1627  (backed up)
Iteration 89:  log likelihood = -1339.1627  (backed up)
Iteration 90:  log likelihood = -1339.1627  (backed up)
Iteration 91:  log likelihood = -1339.1627  (backed up)
Iteration 92:  log likelihood = -1339.1627  (backed up)
Iteration 93:  log likelihood = -1339.1627  (backed up)
Iteration 94:  log likelihood = -1339.1627  (backed up)
Iteration 95:  log likelihood = -1339.1627  (backed up)
Iteration 96:  log likelihood = -1339.1627  (backed up)
Iteration 97:  log likelihood = -1339.1627  (backed up)
Iteration 98:  log likelihood = -1339.1627  (backed up)
Iteration 99:  log likelihood = -1339.1627  (backed up)
Iteration 100: log likelihood = -1339.1627  (backed up)
convergence not achieved

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(14)       =    3491.83
                                                Prob > chi2       =     0.0000
Log likelihood = -1339.1627                     Pseudo R2         =     0.5659

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v5 |    .4964612    .0662678      7.49    0.000      .3665786     .6263438
          v6 |    .6855995    .1707563      4.02    0.000      .3509233     1.020276
          v7 |    3.704866    .3543443     10.46    0.000      3.010364     4.399368
          v9 |    .9253495    .2263174      4.09    0.000      .4817756     1.368923
         v16 |      .76768    .0927178      8.28    0.000      .5859564     .9494035
         v17 |    1.338431    .1903765      7.03    0.000      .9652997     1.711562
         v19 |    .0869667    .0268194      3.24    0.001      .0344016     .1395319
         v21 |    .2667653    .0375431      7.11    0.000      .1931822     .3403484
         v23 |    3.488473    .5040752      6.92    0.000      2.500504     4.476442
         v24 |    .9186041    .2129006      4.31    0.000      .5013267     1.335882
         v25 |   -2.525053    .2702294     -9.34    0.000     -3.054693    -1.995413
         v52 |    .6999923    .0971799      7.20    0.000      .5095232     .8904614
         v53 |     6.35459    .6513838      9.76    0.000      5.077901     7.631279
         v57 |    .0011362    .0001317      8.63    0.000      .0008781     .0013943
       _cons |   -2.387479    .0916472    -26.05    0.000     -2.567105    -2.207854
-------------+----------------------------------------------------------------


Note: 74 failures and 19 successes completely determined.


Warning: convergence not achieved
1.688e-14

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.1727807      0.4550969
               v6 |       0.2152931      0.9614203
               v7 |       1.1426365      3.2847248
               v8 |       0.1368686      0.6228345
               v9 |       0.1194438      1.2686870
              v16 |       0.2610206      1.1365279
              v17 |       0.1633636      1.1000374
              v18 |       0.0186096      0.3792675
              v19 |       0.0354681      0.0478566
              v20 |       0.0623173      1.6419546
              v21 |       0.2850692      0.2785537
              v23 |       0.9087893      3.0333616
              v24 |       0.1364868      0.7890926
              v25 |      -0.1194090     -1.8286444
              v26 |      -0.0365264     -1.1537435
              v27 |      -0.0021456     -8.0061923
              v52 |       0.1837436      0.4989944
              v53 |       1.5733685      5.1962139
              v57 |       0.0002816      0.0009413
            _cons |      -1.3345409     -2.1960013
------------------+--------------------------------
lambda=.05; selected=v5 v6 v7 v8 v9 v16 v17 v18 v19 v20 v21 v23 v24 v25 v26 v27 v52 v53 v57

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1469.0752
Iteration 2:   log likelihood = -1283.6935
Iteration 3:   log likelihood = -1197.5571
Iteration 4:   log likelihood = -1176.8582
Iteration 5:   log likelihood =  -1171.683
Iteration 6:   log likelihood = -1170.4581
Iteration 7:   log likelihood = -1170.4163
Iteration 8:   log likelihood = -1170.4162

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(19)       =    3829.32
                                                Prob > chi2       =     0.0000
Log likelihood = -1170.4162                     Pseudo R2         =     0.6206

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v5 |    .4550969    .0707022      6.44    0.000      .3165231     .5936707
          v6 |    .9614203    .2095233      4.59    0.000      .5507623     1.372078
          v7 |    3.284725    .3554478      9.24    0.000       2.58806      3.98139
          v8 |    .6228345    .1469756      4.24    0.000      .3347677     .9109014
          v9 |    1.268687    .2753861      4.61    0.000      .7289401     1.808434
         v16 |    1.136528    .1236747      9.19    0.000      .8941299     1.378926
         v17 |    1.100037     .213033      5.16    0.000      .6825004     1.517574
         v18 |    .3792675     .111105      3.41    0.001      .1615056     .5970294
         v19 |    .0478566    .0294369      1.63    0.104     -.0098386     .1055518
         v20 |    1.641955    .4716646      3.48    0.000       .717509       2.5664
         v21 |    .2785537    .0413681      6.73    0.000      .1974738     .3596336
         v23 |    3.033362    .4879427      6.22    0.000      2.077011     3.989712
         v24 |    .7890926    .2063253      3.82    0.000      .3847024     1.193483
         v25 |   -1.828644    .2862979     -6.39    0.000     -2.389778    -1.267511
         v26 |   -1.153743    .4202757     -2.75    0.006     -1.977469    -.3300183
         v27 |   -8.006192    1.986354     -4.03    0.000     -11.89937     -4.11301
         v52 |    .4989944    .0862705      5.78    0.000      .3299073     .6680815
         v53 |    5.196214    .6349955      8.18    0.000      3.951646     6.440782
         v57 |    .0009413    .0001316      7.15    0.000      .0006834     .0011992
       _cons |   -2.196001    .0999864    -21.96    0.000     -2.391971    -2.000032
-------------+----------------------------------------------------------------


Note: 410 failures and 17 successes completely determined.


9.842e-14

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0029758     -0.1374068
               v3 |       0.0997006      0.0991317
               v4 |       0.0177195      2.3332627
               v5 |       0.4300180      0.5875146
               v6 |       0.4414639      0.8492650
               v7 |       2.0729214      2.4348325
               v8 |       0.4834239      0.5999610
               v9 |       0.3608079      0.7307504
              v10 |       0.0346937      0.1092016
              v16 |       0.4770478      0.9743012
              v17 |       0.5327560      0.9980701
              v18 |       0.2248792      0.1631271
              v19 |       0.0674714      0.0716554
              v20 |       0.3028956      1.2950750
              v21 |       0.2293296      0.1668222
              v22 |       0.1532995      0.3442095
              v23 |       1.6217945      2.2132158
              v24 |       0.5013475      0.4608378
              v25 |      -0.6533537     -1.9673969
              v26 |      -0.3152566     -0.8402018
              v27 |      -0.1489442    -11.8213888
              v33 |      -0.2637423     -0.7969994
              v37 |      -0.1231707      0.0122131
              v39 |      -0.1129272     -0.8643057
              v42 |      -0.4502577     -2.7183354
              v43 |      -0.1147941     -1.3022334
              v44 |      -0.1292291     -1.7243178
              v45 |      -0.2962770     -0.7519671
              v46 |      -0.4141769     -1.5712385
              v47 |      -0.1448874     -2.3148858
              v48 |      -0.1707776     -4.5901990
              v49 |      -0.3176464     -1.2411361
              v52 |       0.4532346      0.3692874
              v53 |       3.7624097      5.7071085
              v56 |       0.0013703      0.0113318
              v57 |       0.0004691      0.0005470
            _cons |      -1.6849886     -1.6183501
------------------+--------------------------------
lambda=.01; selected=v2 v3 v4 v5 v6 v7 v8 v9 v10 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v33 v37 v39 v42 v43 v44 v45 v46 v47 v48 v49 v52 v53 v56 v57

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1291.4638
Iteration 2:   log likelihood = -1095.7645
Iteration 3:   log likelihood = -988.96597
Iteration 4:   log likelihood = -967.42267
Iteration 5:   log likelihood = -955.69701
Iteration 6:   log likelihood = -954.03981
Iteration 7:   log likelihood = -954.03087
Iteration 8:   log likelihood = -954.03087

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(36)       =    4262.09
                                                Prob > chi2       =     0.0000
Log likelihood = -954.03087                     Pseudo R2         =     0.6908

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v2 |   -.1374068    .0672639     -2.04    0.041     -.2692415     -.005572
          v3 |    .0991317    .1069644      0.93    0.354     -.1105148     .3087781
          v4 |    2.333263     1.48968      1.57    0.117     -.5864558     5.252981
          v5 |    .5875146    .1010412      5.81    0.000      .3894774     .7855518
          v6 |     .849265    .2413254      3.52    0.000       .376276     1.322254
          v7 |    2.434833    .3310068      7.36    0.000      1.786071     3.083594
          v8 |     .599961    .1588476      3.78    0.000      .2886254     .9112965
          v9 |    .7307504    .2738482      2.67    0.008      .1940177     1.267483
         v10 |    .1092016    .0675371      1.62    0.106     -.0231686     .2415719
         v16 |    .9743012    .1345076      7.24    0.000       .710671     1.237931
         v17 |    .9980701    .2196837      4.54    0.000      .5674979     1.428642
         v18 |    .1631271    .1122602      1.45    0.146     -.0568989     .3831531
         v19 |    .0716554    .0339202      2.11    0.035      .0051731     .1381378
         v20 |    1.295075    .5578864      2.32    0.020      .2016377     2.388512
         v21 |    .1668222    .0446003      3.74    0.000      .0794071     .2542372
         v22 |    .3442095    .1344195      2.56    0.010       .080752     .6076669
         v23 |    2.213216    .4661841      4.75    0.000      1.299512      3.12692
         v24 |    .4608378    .1687377      2.73    0.006      .1301179     .7915577
         v25 |   -1.967397    .2945318     -6.68    0.000     -2.544669    -1.390125
         v26 |   -.8402018    .4027778     -2.09    0.037     -1.629632    -.0507718
         v27 |   -11.82139    1.785514     -6.62    0.000     -15.32093    -8.321845
         v33 |   -.7969994    .2982932     -2.67    0.008     -1.381643    -.2123554
         v37 |    .0122131    .1741632      0.07    0.944     -.3291405     .3535667
         v39 |   -.8643057    .3729285     -2.32    0.020     -1.595232    -.1333793
         v42 |   -2.718335    .8314565     -3.27    0.001      -4.34796    -1.088711
         v43 |   -1.302233     .806224     -1.62    0.106     -2.882404     .2779367
         v44 |   -1.724318    .5309969     -3.25    0.001     -2.765053    -.6835831
         v45 |   -.7519671    .1504803     -5.00    0.000     -1.046903    -.4570311
         v46 |   -1.571238    .2724616     -5.77    0.000     -2.105253    -1.037224
         v47 |   -2.314886    1.645815     -1.41    0.160     -5.540623     .9108515
         v48 |   -4.590199    1.745301     -2.63    0.009     -8.010926    -1.169472
         v49 |   -1.241136    .4124564     -3.01    0.003     -2.049536    -.4327364
         v52 |    .3692874    .0893144      4.13    0.000      .1942343     .5443405
         v53 |    5.707108    .7229834      7.89    0.000      4.290087      7.12413
         v56 |    .0113318    .0017521      6.47    0.000      .0078978     .0147657
         v57 |     .000547      .00017      3.22    0.001      .0002138     .0008801
       _cons |    -1.61835    .1227107    -13.19    0.000     -1.858859    -1.377841
-------------+----------------------------------------------------------------


Note: 546 failures and 29 successes completely determined.


2.925e-13

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.0679826     -0.4973776
               v2 |      -0.0494522     -0.1491788
               v3 |       0.1148702      0.0946947
               v4 |       0.0538835      2.3127800
               v5 |       0.4859434      0.5565020
               v6 |       0.4965129      0.8275124
               v7 |       2.2422015      2.3353038
               v8 |       0.5381027      0.5824697
               v9 |       0.4307811      0.6613213
              v10 |       0.0617053      0.1105336
              v14 |       0.0136675      0.1739512
              v15 |       0.1997293      1.2701147
              v16 |       0.5874811      0.9593566
              v17 |       0.6509255      0.9836859
              v18 |       0.2359093      0.1219514
              v19 |       0.0716010      0.0683777
              v20 |       0.4013775      1.0729787
              v21 |       0.2134715      0.2133897
              v22 |       0.2149886      0.3521578
              v23 |       1.8816205      2.1630728
              v24 |       0.5523528      0.4311916
              v25 |      -0.9582616     -1.8797072
              v26 |      -0.4887831     -0.9039480
              v27 |      -0.4648677    -11.4597847
              v29 |      -0.1193588     -2.5138585
              v33 |      -0.4615122     -0.7369924
              v35 |      -0.0612672     -2.1647810
              v37 |      -0.0830439      0.0165618
              v39 |      -0.2532902     -0.7917925
              v41 |      -0.3023864    -45.3373480
              v42 |      -0.7192420     -2.6240140
              v43 |      -0.2684652     -1.3472954
              v44 |      -0.3735859     -1.5771656
              v45 |      -0.4176531     -0.7515336
              v46 |      -0.6942240     -1.3888339
              v47 |      -0.6969481     -2.0860236
              v48 |      -0.6140350     -3.9163491
              v49 |      -0.6146071     -1.3204901
              v51 |      -0.1083647     -0.6231862
              v52 |       0.4628134      0.3578162
              v53 |       4.4025143      5.5347481
              v56 |       0.0022381      0.0105774
              v57 |       0.0005137      0.0007932
            _cons |      -1.6389957     -1.5486373
------------------+--------------------------------
lambda=.005; selected=v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v29 v33 v35 v37 v39 v41 v42 v43 v44 v45 v46 v47 v48 v49 v51 v52 v53 v56 v57

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1281.8182
Iteration 2:   log likelihood = -1083.2277
Iteration 3:   log likelihood = -969.49359
Iteration 4:   log likelihood = -941.50247
Iteration 5:   log likelihood =  -927.8829
Iteration 6:   log likelihood = -925.73837
Iteration 7:   log likelihood = -925.38142
Iteration 8:   log likelihood = -925.35816
Iteration 9:   log likelihood = -925.35815

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(43)       =    4319.44
                                                Prob > chi2       =     0.0000
Log likelihood = -925.35815                     Pseudo R2         =     0.7001

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v1 |   -.4973776    .2123789     -2.34    0.019     -.9136326    -.0811226
          v2 |   -.1491788    .0702388     -2.12    0.034     -.2868443    -.0115133
          v3 |    .0946947    .1090294      0.87    0.385     -.1189989     .3083883
          v4 |     2.31278    1.483252      1.56    0.119     -.5943403       5.2199
          v5 |     .556502    .0999492      5.57    0.000      .3606051     .7523988
          v6 |    .8275124    .2416472      3.42    0.001      .3538927     1.301132
          v7 |    2.335304      .32711      7.14    0.000       1.69418     2.976428
          v8 |    .5824697    .1676119      3.48    0.001      .2539565     .9109829
          v9 |    .6613213    .2745632      2.41    0.016      .1231873     1.199455
         v10 |    .1105336    .0686961      1.61    0.108     -.0241082     .2451755
         v14 |    .1739512    .1330977      1.31    0.191     -.0869155     .4348179
         v15 |    1.270115    .7128356      1.78    0.075     -.1270173     2.667247
         v16 |    .9593566    .1364787      7.03    0.000      .6918633      1.22685
         v17 |    .9836859    .2215727      4.44    0.000      .5494113      1.41796
         v18 |    .1219514     .116775      1.04    0.296     -.1069235     .3508262
         v19 |    .0683777    .0340237      2.01    0.044      .0016925     .1350628
         v20 |    1.072979    .5312193      2.02    0.043       .031808     2.114149
         v21 |    .2133897    .0489292      4.36    0.000      .1174903     .3092891
         v22 |    .3521578    .1403479      2.51    0.012      .0770811     .6272346
         v23 |    2.163073     .466628      4.64    0.000      1.248499     3.077647
         v24 |    .4311916    .1621862      2.66    0.008      .1133125     .7490708
         v25 |   -1.879707    .2938923     -6.40    0.000     -2.455726    -1.303689
         v26 |    -.903948    .4131894     -2.19    0.029     -1.713784    -.0941116
         v27 |   -11.45978    1.811141     -6.33    0.000     -15.00956    -7.910014
         v29 |   -2.513859    1.466454     -1.71    0.086     -5.388056     .3603393
         v33 |   -.7369924    .3066182     -2.40    0.016     -1.337953    -.1360318
         v35 |   -2.164781    .7987813     -2.71    0.007     -3.730364    -.5991983
         v37 |    .0165618    .1739329      0.10    0.924     -.3243404     .3574641
         v39 |   -.7917925    .3617937     -2.19    0.029     -1.500895    -.0826899
         v41 |   -45.33735    27.20523     -1.67    0.096     -98.65863     7.983929
         v42 |   -2.624014    .8268212     -3.17    0.002     -4.244554    -1.003474
         v43 |   -1.347295    .8135381     -1.66    0.098     -2.941801     .2472099
         v44 |   -1.577166    .5292144     -2.98    0.003     -2.614407    -.5399245
         v45 |   -.7515336    .1503511     -5.00    0.000     -1.046216    -.4568507
         v46 |   -1.388834    .2646748     -5.25    0.000     -1.907587    -.8700809
         v47 |   -2.086024    1.585192     -1.32    0.188     -5.192943     1.020896
         v48 |   -3.916349    1.591033     -2.46    0.014     -7.034716    -.7979826
         v49 |    -1.32049    .4306051     -3.07    0.002     -2.164461    -.4765197
         v51 |   -.6231862     .807006     -0.77    0.440     -2.204889     .9585164
         v52 |    .3578162    .0896875      3.99    0.000      .1820319     .5336006
         v53 |    5.534748    .7067049      7.83    0.000      4.149632     6.919864
         v56 |    .0105774    .0018016      5.87    0.000      .0070463     .0141085
         v57 |    .0007932    .0002104      3.77    0.000      .0003807     .0012056
       _cons |   -1.548637    .1266906    -12.22    0.000     -1.796946    -1.300328
-------------+----------------------------------------------------------------


Note: 671 failures and 29 successes completely determined.


3.467e-13

. //
.
.
. ********************************************************************************
. *** compare results: single vs multiple lambdas                                                          ***
. ********************************************************************************
.
.
. clear all

.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. *******
.
. lassologit v58 v1-v57, l(0.187 0.1 0.07 0.05 0.01 ) lambdan quadp noseqr tolopt(1e-14)
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.18700    1     0.43201   6171.98872   0.0003  | Added v21
      |                                                         | _cons.
     2 |   2    0.10000    7     2.81070   5083.09675   0.1804  | Added v7 v16
      |                                                         | v23 v25 v53
      |                                                         | v57.
     3 |   3    0.07000   14     4.73158   4418.72233   0.2924  | Added v5 v6
      |                                                         | v9 v17 v19
      |                                                         | v24 v52.
     4 |   4    0.05000   19     6.90816   3913.66596   0.3772  | Added v8 v18
      |                                                         | v20 v26 v27.
     5 |   5    0.01000   37    17.62002   2616.28666   0.5984  | Added v2 v3
      |                                                         | v4 v10 v12
      |                                                         | v22 v33 v37
      |                                                         | v39 v42 v43
      |                                                         | v44 v45 v46
      |                                                         | v47 v48 v49
      |                                                         | v56.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat B = e(betas)

.
.
. local j = 1

. foreach lam of numlist 0.187 0.1 0.07 0.05 0.01 {
  2.
.         lassologit v58 v1-v57, l(`lam')   lambdan quadp noseqr tolopt(1e-14)
  3.         mat bj = e(beta)
  4.
.         mat Bj = B[`j',1..58]
  5.
.         di "lambda=`lam'"
  6.
.         di mreldif(bj,Bj)
  7.
.         assert mreldif(bj,Bj)<0.001
  8.
.         local j = `j' + 1
  9.
. }

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v21 |       0.0009245      0.8584517
            _cons |      -0.4310903     -1.1097109
------------------+--------------------------------
lambda=.187
0

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5412443      4.2194397
              v16 |       0.0569502      0.8984170
              v21 |       0.2448168      0.3940148
              v23 |       0.5126733      3.8072262
              v25 |      -0.0071134     -2.7490367
              v53 |       0.6310249      7.5984195
              v57 |       0.0000267      0.0011889
            _cons |      -0.8168529     -1.7667647
------------------+--------------------------------
lambda=.1
1.313e-16
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.0887044      0.4964612
               v6 |       0.0811233      0.6855995
               v7 |       0.8573037      3.7048664
               v9 |       0.0064682      0.9253495
              v16 |       0.1696674      0.7676800
              v17 |       0.0894092      1.3384307
              v19 |       0.0204993      0.0869667
              v21 |       0.2812394      0.2667653
              v23 |       0.7421539      3.4884730
              v24 |       0.0176598      0.9186041
              v25 |      -0.0664838     -2.5250532
              v52 |       0.0938832      0.6999923
              v53 |       1.1233156      6.3545899
              v57 |       0.0001765      0.0011362
            _cons |      -1.0934877     -2.3874793
------------------+--------------------------------
lambda=.07
1.951e-15

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.1727808      0.4550969
               v6 |       0.2152931      0.9614203
               v7 |       1.1426366      3.2847248
               v8 |       0.1368687      0.6228345
               v9 |       0.1194436      1.2686870
              v16 |       0.2610205      1.1365279
              v17 |       0.1633634      1.1000374
              v18 |       0.0186095      0.3792675
              v19 |       0.0354680      0.0478566
              v20 |       0.0623172      1.6419546
              v21 |       0.2850691      0.2785537
              v23 |       0.9087891      3.0333616
              v24 |       0.1364868      0.7890926
              v25 |      -0.1194090     -1.8286444
              v26 |      -0.0365264     -1.1537435
              v27 |      -0.0021456     -8.0061923
              v52 |       0.1837436      0.4989944
              v53 |       1.5733687      5.1962139
              v57 |       0.0002816      0.0009413
            _cons |      -1.3345407     -2.1960013
------------------+--------------------------------
lambda=.05
1.587e-15

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0037409     -0.1389110
               v3 |       0.1011375      0.1052528
               v4 |       0.0173759      2.3399989
               v5 |       0.4296060      0.5853019
               v6 |       0.4399529      0.8359847
               v7 |       2.0688244      2.4042943
               v8 |       0.4808568      0.5882269
               v9 |       0.3601745      0.7213125
              v10 |       0.0363978      0.1183907
              v12 |      -0.0308144     -0.1612150
              v16 |       0.4744442      0.9566529
              v17 |       0.5376233      1.0240614
              v18 |       0.2235756      0.1589568
              v19 |       0.0684679      0.0765814
              v20 |       0.3023890      1.3204219
              v21 |       0.2312331      0.1788195
              v22 |       0.1524290      0.3431311
              v23 |       1.6218802      2.2021820
              v24 |       0.5023647      0.4542068
              v25 |      -0.6504901     -1.9495298
              v26 |      -0.3118043     -0.8067431
              v27 |      -0.1501575    -11.7835281
              v33 |      -0.2648091     -0.8002706
              v37 |      -0.1250244      0.0036378
              v39 |      -0.1063192     -0.7635106
              v42 |      -0.4459357     -2.6936770
              v43 |      -0.1163318     -1.3224400
              v44 |      -0.1287169     -1.7394127
              v45 |      -0.3007246     -0.7909711
              v46 |      -0.4174005     -1.5924053
              v47 |      -0.1506038     -2.2954658
              v48 |      -0.1642560     -4.4529880
              v49 |      -0.3189394     -1.2608654
              v52 |       0.4521115      0.3611414
              v53 |       3.7605492      5.7431487
              v56 |       0.0013784      0.0113141
              v57 |       0.0004669      0.0005325
            _cons |      -1.6707146     -1.5458167
------------------+--------------------------------
lambda=.01
4.776e-15

. //
.
. *******
.
. lassologit v58 v1-v57, l(0.187 0.1 0.07 0.05 0.01 ) postl lambdan quadp noseqr tolopt(1e-14)
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....
convergence not achieved
warning: post-logit did not converge after 100 iterations.

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.18700    1     1.96816   5411.02908   0.1236  | Added v21
      |                                                         | _cons.
     2 |   2    0.10000    7    21.43451   3039.24390   0.5117  | Added v7 v16
      |                                                         | v23 v25 v53
      |                                                         | v57.
     3 |   3    0.07000   14    24.64745   2736.65101   0.5650  | Added v5 v6
      |                                                         | v9 v17 v19
      |                                                         | v24 v52.
     4 |   4    0.05000   19    33.88015   2412.03109   0.6206  | Added v8 v18
      |                                                         | v20 v26 v27.
     5 |   5    0.01000   37    54.63130   2041.28998   0.6916  | Added v2 v3
      |                                                         | v4 v10 v12
      |                                                         | v22 v33 v37
      |                                                         | v39 v42 v43
      |                                                         | v44 v45 v46
      |                                                         | v47 v48 v49
      |                                                         | v56.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat B = e(betas)

.
.
. local j = 1

. foreach lam of numlist 0.187 0.1 0.07 0.05 0.01 {
  2.
.         lassologit v58 v1-v57, l(`lam') postl lambdan   quadp noseqr tolopt(1e-14)
  3.         mat bj = e(beta_post)
  4.
.         mat Bj = B[`j',1..58]
  5.
.         di "lambda=`lam'"
  6.
.         di mreldif(bj,Bj)
  7.
.         assert mreldif(bj,Bj)<1e-10
  8.
.         local j = `j' + 1
  9.
. }

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v21 |       0.0009245      0.8584517
            _cons |      -0.4310903     -1.1097109
------------------+--------------------------------
lambda=.187
0

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5412443      4.2194397
              v16 |       0.0569502      0.8984170
              v21 |       0.2448168      0.3940148
              v23 |       0.5126733      3.8072262
              v25 |      -0.0071134     -2.7490367
              v53 |       0.6310249      7.5984195
              v57 |       0.0000267      0.0011889
            _cons |      -0.8168529     -1.7667647
------------------+--------------------------------
lambda=.1
0
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.0887044      0.4964612
               v6 |       0.0811233      0.6855995
               v7 |       0.8573037      3.7048664
               v9 |       0.0064682      0.9253495
              v16 |       0.1696674      0.7676800
              v17 |       0.0894092      1.3384307
              v19 |       0.0204993      0.0869667
              v21 |       0.2812394      0.2667653
              v23 |       0.7421539      3.4884730
              v24 |       0.0176598      0.9186041
              v25 |      -0.0664838     -2.5250532
              v52 |       0.0938832      0.6999923
              v53 |       1.1233156      6.3545899
              v57 |       0.0001765      0.0011362
            _cons |      -1.0934877     -2.3874793
------------------+--------------------------------
lambda=.07
0

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.1727808      0.4550969
               v6 |       0.2152931      0.9614203
               v7 |       1.1426366      3.2847248
               v8 |       0.1368687      0.6228345
               v9 |       0.1194436      1.2686870
              v16 |       0.2610205      1.1365279
              v17 |       0.1633634      1.1000374
              v18 |       0.0186095      0.3792675
              v19 |       0.0354680      0.0478566
              v20 |       0.0623172      1.6419546
              v21 |       0.2850691      0.2785537
              v23 |       0.9087891      3.0333616
              v24 |       0.1364868      0.7890926
              v25 |      -0.1194090     -1.8286444
              v26 |      -0.0365264     -1.1537435
              v27 |      -0.0021456     -8.0061923
              v52 |       0.1837436      0.4989944
              v53 |       1.5733687      5.1962139
              v57 |       0.0002816      0.0009413
            _cons |      -1.3345407     -2.1960013
------------------+--------------------------------
lambda=.05
0

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0037409     -0.1389110
               v3 |       0.1011375      0.1052528
               v4 |       0.0173759      2.3399989
               v5 |       0.4296060      0.5853019
               v6 |       0.4399529      0.8359847
               v7 |       2.0688244      2.4042943
               v8 |       0.4808568      0.5882269
               v9 |       0.3601745      0.7213125
              v10 |       0.0363978      0.1183907
              v12 |      -0.0308144     -0.1612150
              v16 |       0.4744442      0.9566529
              v17 |       0.5376233      1.0240614
              v18 |       0.2235756      0.1589568
              v19 |       0.0684679      0.0765814
              v20 |       0.3023890      1.3204219
              v21 |       0.2312331      0.1788195
              v22 |       0.1524290      0.3431311
              v23 |       1.6218802      2.2021820
              v24 |       0.5023647      0.4542068
              v25 |      -0.6504901     -1.9495298
              v26 |      -0.3118043     -0.8067431
              v27 |      -0.1501575    -11.7835281
              v33 |      -0.2648091     -0.8002706
              v37 |      -0.1250244      0.0036378
              v39 |      -0.1063192     -0.7635106
              v42 |      -0.4459357     -2.6936770
              v43 |      -0.1163318     -1.3224400
              v44 |      -0.1287169     -1.7394127
              v45 |      -0.3007246     -0.7909711
              v46 |      -0.4174005     -1.5924053
              v47 |      -0.1506038     -2.2954658
              v48 |      -0.1642560     -4.4529880
              v49 |      -0.3189394     -1.2608654
              v52 |       0.4521115      0.3611414
              v53 |       3.7605492      5.7431487
              v56 |       0.0013784      0.0113141
              v57 |       0.0004669      0.0005325
            _cons |      -1.6707146     -1.5458167
------------------+--------------------------------
lambda=.01
0

. //
.
.
. *******
.
. lassologit v58 v1-v57, l(0.1 0.07 0.05 0.01 0.005 ) nocons lambdan  quadp noseqr tolopt(1e-14)
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.10000    8     1.01900   5756.45351   0.0718  | Added v7 v21
      |                                                         | v23 v25 v26
      |                                                         | v27 v37 v53.
     2 |   2    0.07000   13     2.65604   5053.70201   0.1887  | Added v16
      |                                                         | v42 v45 v46
      |                                                         | v50.
     3 |   3    0.05000   19     4.75354   4429.24802   0.2935  | Added v12
      |                                                         | v17 v20 v24
      |                                                         | v33 v52.
     4 |   4    0.01000   41    18.75168   2807.93614   0.5695  | Added v1 v2
      |                                                         | v5 v6 v8 v9
      |                                                         | v15 v18 v19
      |                                                         | v22 v29 v35
      |                                                         | v39 v41 v43
      |                                                         | v44 v47 v48
      |                                                         | v49 v51 v56
      |                                                         | v57.
     5 |   5    0.00500   47    26.67062   2521.58278   0.6195  | Added v4 v13
      |                                                         | v30 v31 v38
      |                                                         | v40.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat B = e(betas)

.
.
. local j = 1

. foreach lam of numlist 0.1 0.07 0.05 0.01 0.005 {
  2.
.         di "lambda=`lam'"
  3.         lassologit v58 v1-v57, l(`lam')  nocons   lambdan quadp noseqr tolopt(1e-14)
  4.         mat bj = e(beta)
  5.
.         mat Bj = B[`j',1..57]
  6.
.         di mreldif(bj,Bj)
  7.
.         assert mreldif(bj,Bj)<1e-5
  8.
.         local j = `j' + 1
  9.
. }
lambda=.1

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.2650131      3.4924194
              v21 |       0.0024332      0.1020325
              v23 |       0.2750091      3.3829459
              v25 |      -0.1326805     -2.3257051
              v26 |      -0.0608908     -1.8382049
              v27 |      -0.0103742     -7.6421148
              v37 |      -0.0630326     -1.3603202
              v53 |       0.2095697      5.9704748
------------------+--------------------------------
0
lambda=.07

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5502769      2.8098039
              v16 |       0.0359280      1.0087524
              v21 |       0.0412445      0.1584121
              v23 |       0.5169110      2.9032142
              v25 |      -0.2210698     -2.1101118
              v26 |      -0.1311193     -1.9259327
              v27 |      -0.0427956     -7.5412564
              v37 |      -0.2308411     -0.5046334
              v42 |      -0.0191658     -3.1272642
              v45 |      -0.0778126     -0.9861816
              v46 |      -0.0645772     -2.5562092
              v50 |      -0.0694340     -0.9862391
              v53 |       0.6548612      7.7706313
------------------+--------------------------------
1.091e-15
lambda=.05

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.7933684      2.6253635
              v12 |      -0.0629520     -0.4247379
              v16 |       0.1067483      0.9324610
              v17 |       0.0710059      1.1060487
              v20 |       0.0238898      1.5232256
              v21 |       0.0680058      0.1468137
              v23 |       0.7250323      2.6941404
              v24 |       0.0479179      0.4504684
              v25 |      -0.3135342     -2.1956773
              v26 |      -0.1775486     -1.3329447
              v27 |      -0.0701598     -7.2267825
              v33 |      -0.0828687     -1.0037807
              v37 |      -0.3075390     -0.3504000
              v42 |      -0.1037288     -3.1005426
              v45 |      -0.1684504     -1.1473849
              v46 |      -0.1598983     -2.3516123
              v50 |      -0.2564002     -0.9437476
              v52 |       0.0245341      0.2775914
              v53 |       1.1899611      6.9886589
------------------+--------------------------------
4.393e-15
lambda=.01

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.0200604     -0.5365942
               v2 |      -0.1154487     -0.2437637
               v5 |       0.1956693      0.3515775
               v6 |       0.1165670      0.4697127
               v7 |       1.7000859      2.1879866
               v8 |       0.2964567      0.4535168
               v9 |       0.1377150      0.4396796
              v12 |      -0.2915624     -0.3305314
              v15 |       0.1204020      1.2645380
              v16 |       0.3284637      0.8163235
              v17 |       0.4203698      0.8761621
              v18 |       0.0486121     -0.0057940
              v19 |      -0.0207725     -0.0906895
              v20 |       0.2927474      1.2550231
              v21 |       0.0894496      0.1403134
              v22 |       0.0775057      0.3317326
              v23 |       1.4427900      2.0218483
              v24 |       0.3946860      0.4193053
              v25 |      -0.9369266     -2.2361590
              v26 |      -0.4647040     -1.0145500
              v27 |      -0.2576645     -9.4452785
              v29 |      -0.0450505     -3.5975876
              v33 |      -0.5899869     -1.0400269
              v35 |      -0.0918822     -2.1362442
              v37 |      -0.3583838     -0.2102179
              v39 |      -0.2118789     -0.9262838
              v41 |      -0.1033153    -34.1557491
              v42 |      -0.6598578     -2.8553308
              v43 |      -0.3301687     -1.8439233
              v44 |      -0.4364266     -2.1931420
              v45 |      -0.6039432     -0.9957092
              v46 |      -0.8008154     -1.8714535
              v47 |      -0.5115771     -2.5744130
              v48 |      -0.4924094     -3.7971354
              v49 |      -0.5587218     -1.6343045
              v50 |      -1.0800523     -0.9360925
              v51 |      -0.6243036     -1.6360753
              v52 |       0.1969137      0.2376949
              v53 |       3.2862406      4.9338768
              v56 |       0.0009495      0.0077243
              v57 |       0.0001419      0.0004734
------------------+--------------------------------
4.269e-15
lambda=.005

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.1809080     -0.5378352
               v2 |      -0.1572957     -0.2437759
               v4 |       0.0248724      2.1049508
               v5 |       0.2595463      0.3597005
               v6 |       0.2000403      0.5341243
               v7 |       1.9126371      2.1816531
               v8 |       0.3578749      0.4345871
               v9 |       0.2228853      0.5035271
              v12 |      -0.3141866     -0.3285839
              v13 |      -0.0875279     -0.3838125
              v15 |       0.3541592      1.5264669
              v16 |       0.5013867      0.8534160
              v17 |       0.5691097      0.9140972
              v18 |       0.0575477     -0.0097427
              v19 |      -0.0435870     -0.0856511
              v20 |       0.3980743      1.1929666
              v21 |       0.1054349      0.1407157
              v22 |       0.1420705      0.3282761
              v23 |       1.7201106      2.0721137
              v24 |       0.4724270      0.3984504
              v25 |      -1.2345627     -2.1574582
              v26 |      -0.6313621     -1.0300730
              v27 |      -0.5178153     -9.3080993
              v29 |      -0.3591798     -3.5319597
              v30 |      -0.1618564     -0.4851814
              v31 |      -0.0460959     -0.3252689
              v33 |      -0.7916616     -1.0259040
              v35 |      -0.2196920     -2.2944999
              v37 |      -0.3149201     -0.2114374
              v38 |      -0.1918731     -0.6960359
              v39 |      -0.3522178     -0.9350352
              v40 |      -0.0483344     -0.3780015
              v41 |      -0.4067988    -35.1248659
              v42 |      -0.9641556     -2.7912247
              v43 |      -0.5740112     -1.8487342
              v44 |      -0.7629174     -2.1331338
              v45 |      -0.7378222     -1.0101051
              v46 |      -1.1105819     -1.8257851
              v47 |      -0.9020293     -2.4623539
              v48 |      -0.9272582     -3.7774305
              v49 |      -0.8519997     -1.6597352
              v50 |      -1.1075620     -0.9226955
              v51 |      -1.1961593     -1.6631168
              v52 |       0.2273952      0.2330733
              v53 |       3.9489600      5.0332783
              v56 |       0.0014999      0.0077103
              v57 |       0.0002136      0.0004576
------------------+--------------------------------
8.375e-15

. //
.
.
. *******
.
. lassologit v58 v1-v57, l(0.187 0.16 0.12 0.1   ) nostd lambdan quadp noseqr tolopt(1e-14)
Obtaining solution for 4 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.18700    3     1.33158   5134.22819   0.1697  | Added v19
      |                                                         | v56 v57
      |                                                         | _cons.
     2 |   2    0.16000    5     1.43737   5052.83772   0.1841  | Added v25
      |                                                         | v27.
     3 |   3    0.12000    6     1.71424   4772.80828   0.2301  | Added v21.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat B = e(betas)

.
.
. local j = 1

. foreach lam of numlist 0.187 0.16 0.12 0.1   {
  2.
.         lassologit v58 v1-v57, l(`lam')  nostd  lambdan  quadp noseqr tolopt(1e-14)
  3.         mat bj = e(beta)
  4.
.         mat Bj = B[`j',1..58]
  5.
.         di "lambda=`lam'"
  6.
.         di mreldif(bj,Bj)
  7.
.         assert mreldif(bj,Bj)<0.001
  8.
.         local j = `j' + 1
  9.
. }
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v19 |       0.0322627      0.3256872
              v56 |       0.0232286      0.0244083
              v57 |       0.0000956      0.0002090
            _cons |      -1.2759899     -1.8573580
------------------+--------------------------------
lambda=.187
0
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v19 |       0.0706403      0.2337384
              v25 |      -0.0066139     -3.2040010
              v27 |      -0.0112998    -22.0263104
              v56 |       0.0229998      0.0258484
              v57 |       0.0001044      0.0004109
            _cons |      -1.3257117     -1.0884138
------------------+--------------------------------
lambda=.16
9.547e-16
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v19 |       0.0975655      0.1267263
              v21 |       0.1010912      0.5220624
              v25 |      -0.0801956     -2.9933831
              v27 |      -0.0332827    -23.0492091
              v56 |       0.0217725      0.0233477
              v57 |       0.0001340      0.0004653
            _cons |      -1.3801941     -1.2967833
------------------+--------------------------------
lambda=.12
1.269e-14
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v19 |       0.1094069      0.1267263
              v21 |       0.1558447      0.5220624
              v25 |      -0.1376249     -2.9933831
              v27 |      -0.0487535    -23.0492091
              v56 |       0.0211568      0.0233477
              v57 |       0.0001530      0.0004653
            _cons |      -1.4039432     -1.2967833
------------------+--------------------------------
lambda=.1
1.708e-16

. //
.
.
end of do-file

.
. do "cs_cvlassologit.do"

.
. clear all

.
. insheet using prostate.data, clear
(11 vars, 97 obs)

.
. gen ybin = lpsa > 2

.
. gen myf = 1

. replace myf = 2 if _n > 25
(72 real changes made)

. replace myf = 3 if _n > 50
(47 real changes made)

. replace myf = 4 if _n > 75
(22 real changes made)

.
. local tol = 0.01

.
. ********************************************************************************
. *** deviance                                                                                                                             ***
. ********************************************************************************
.
. // ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(deviance)  lambdan
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N       Deviance       St. err.
----------+---------------------------------------------
         1|             .2      2.0825447      .97441364  ^
         5|           .001      1.8496369      .77513024  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm = ( 2.08254581596245 \ 2.01772455876113 \ 2.01521038363898 \ 1.85552483852628 \ 1.84971975634164 )

. mat Gcvsd = ( 0.983003948645934 \ 1.01362212332398 \ 1.01620614729319 \ 0.891321820785998 \ 0.769254466742782 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.001
. // > cv$lambda.1se
. // [1] 0.2
. // >
. assert e(lopt)==0.001

. assert e(lse)==0.2

.
. // ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(deviance) nocons lambdan storeest(d)
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N       Deviance       St. err.
----------+---------------------------------------------
         1|             .2      1.8870548      .80058934  ^
         4|            .05       1.712839      .82969722  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm = ( 1.88703159578689 \ 1.84295622517937 \ 1.84604832914781 \ 1.71315139941324 \ 2.06072320470385 )

. mat Gcvsd = ( 0.807683652389135 \ 0.890207093045443 \ 0.89735498493324 \ 0.831483091061569 \ 0.885306606625466 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.05
. // > cv$lambda.1se
. // [1] 0.2
. assert e(lopt)==0.05

. assert e(lse)==0.2

.
. //ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(deviance) nostd lambdan
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N       Deviance       St. err.
----------+---------------------------------------------
         1|             .2      2.1712806      .97214791  ^
         5|           .001      1.8633088      .77838717  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm = ( 2.17122209560962 \ 2.07796719364886 \ 2.06600265938377 \ 1.92873373066042 \ 1.86328278602207 )

. mat Gcvsd = ( 0.976586472178121 \ 0.994800183102049 \ 1.00164196360505 \ 0.919465328924813 \ 0.772522333205428 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.001
. // > cv$lambda.1se
. // [1] 0.2
. assert e(lopt)==0.001

. assert e(lse)==0.2

.
. // ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(deviance) nocons nostd lambdan
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N       Deviance       St. err.
----------+---------------------------------------------
         1|             .2      2.0462999       .8777467  ^
         4|            .05      1.7732799       .8121304  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm = ( 2.04631386499165 \ 1.96612060457599 \ 1.95374855866588 \ 1.77310874352822 \ 2.07059117964739 )

. mat Gcvsd = ( 0.881443394729349 \ 0.910706849371597 \ 0.915312643481268 \ 0.812051490921067 \ 0.890972059994161 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.05
. // > cv$lambda.1se
. // [1] 0.2
. assert e(lopt)==0.05

. assert e(lse)==0.2

.
. ********************************************************************************
. *** classification                                                                                                                       ***
. ********************************************************************************
.
. // ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(class) lambdan
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N     Missclass.       St. err.
----------+---------------------------------------------
         1|             .2      .32989691      .23273587  *^
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm = ( 0.329896907216495 \ 0.422680412371134 \ 0.422680412371134 \ 0.422680412371134 \ 0.371134020618557 )

. mat Gcvsd = ( 0.233921440752119 \ 0.21546802804412 \ 0.21546802804412 \ 0.219888311955527 \ 0.175517201389091 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.2
. // > cv$lambda.1se
. // [1] 0.2
. assert e(lopt)==0.2

. assert e(lse)==0.2

.
. // ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(class) nocons lambdan
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N     Missclass.       St. err.
----------+---------------------------------------------
         1|             .2      .32989691      .23273587  *^
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm =( 0.329896907216495 \ 0.391752577319588 \ 0.391752577319588 \ 0.422680412371134 \ 0.43298969072165 )

. mat Gcvsd = ( 0.233921440752119 \ 0.21676631645944 \ 0.21676631645944 \ 0.210302540152146 \ 0.201492992636001 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.2
. // > cv$lambda.1se
. // [1] 0.2
. assert e(lopt)==0.2

. assert e(lse)==0.2

.
. //ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(class) nostd lambdan
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N     Missclass.       St. err.
----------+---------------------------------------------
         1|             .2      .48453608      .19658288  ^
         5|           .001       .3814433      .17692482  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm = ( 0.484536082474227 \ 0.443298969072165 \ 0.43298969072165 \ 0.43298969072165 \ 0.381443298969072 )

. mat Gcvsd = ( 0.195557378626205 \ 0.212481204585373 \ 0.215980406627655 \ 0.215980406627655 \ 0.176370943087664 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.001
. // > cv$lambda.1se
. // [1] 0.2
. assert e(lopt)==0.001

. assert e(lse)==0.2

.
. // ok
. cvlassologit ybin lcavol-pgg45, foldv(myf) l(.2 0.11 .1 0.05 0.001) lossm(class) nocons nostd lambdan
Use user-specified fold variable.
K-fold cross-validation with 4 folds.
Fold 1 2 3 4
          |       Lambda/N     Missclass.       St. err.
----------+---------------------------------------------
         1|             .2      .45360825      .21117543  ^
         2|            .11      .41237113      .21614273  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

. mat Scvm = e(mloss)'

. mat Scvsd = e(cvsd)'

. mat Gcvm = ( 0.45360824742268 \ 0.412371134020619 \ 0.422680412371134 \ 0.422680412371134 \ 0.43298969072165 )

. mat Gcvsd = ( 0.209411194781137 \ 0.215428563830343 \ 0.21546802804412 \ 0.212254330138366 \ 0.201492992636001 )

. assert mreldif(Scvm,Gcvm)<`tol'

. assert mreldif(Scvsd,Gcvsd)<`tol'

. // > cv$lambda.min
. // [1] 0.11
. // > cv$lambda.1se
. // [1] 0.2
. assert e(lopt)==0.11

. assert e(lse)==0.2

.
.
. ********************************************************************************
. *** plotting                                                                 ***
. ********************************************************************************
.
. clear all

.
. insheet using prostate.data, clear
(11 vars, 97 obs)

.
. gen ybin = lpsa > 2

.
. cvlassologit ybin lcavol-pgg45 , plotcv nfol(3)
K-fold cross-validation with 3 folds.
Fold 1 2 3
          |         Lambda       Deviance       St. err.
----------+---------------------------------------------
         8|      8.9647385      1.0037461      .11398461  ^
        16|       2.902296      .91542437      .10709838  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

.
. cvlassologit ybin lcavol-pgg45 , plotcv plotopt(legend(off)) nfol(3)
K-fold cross-validation with 3 folds.
Fold 1 2 3
          |         Lambda       Deviance       St. err.
----------+---------------------------------------------
         9|      7.7859773      .96537163        .069122  ^
        14|      3.8476068      .92203815      .05976386  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

.
.
. ********************************************************************************
. *** stratified option                                                        ***
. ********************************************************************************
.
. clear all

.
. insheet using prostate.data, clear
(11 vars, 97 obs)

.
. gen ybin = lpsa > 3

.
. gen f = ceil(rpoisson(3))+1

.
. cvlassologit ybin lcavol-pgg45, tabfold strat

           |                          Fold
      ybin |         1          2          3          4          5 |     Total
-----------+-------------------------------------------------------+----------
         0 |        14         14         14         14         14 |        70
         1 |         5          5          6          5          6 |        27
-----------+-------------------------------------------------------+----------
     Total |        19         19         20         19         20 |        97
K-fold cross-validation with 5 folds.
Fold 1 2 3 4 5
          |         Lambda       Deviance       St. err.
----------+---------------------------------------------
         6|      13.384075      .88157103      .06818012  ^
        14|      4.3330375      .75847939      .13799189  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

.
. cvlassologit ybin lcavol-pgg45, tabfold

           |                          Fold
      ybin |         1          2          3          4          5 |     Total
-----------+-------------------------------------------------------+----------
         0 |        13         15         11         16         15 |        70
         1 |         6          4          9          3          5 |        27
-----------+-------------------------------------------------------+----------
     Total |        19         19         20         19         20 |        97
K-fold cross-validation with 5 folds.
Fold 1 2 3 4 5
          |         Lambda       Deviance       St. err.
----------+---------------------------------------------
         9|      8.7682899      .81518874      .06501475  ^
        15|      3.7632924      .75588392      .07081494  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

.
. cvlassologit ybin lcavol-pgg45 [fw=f], tabfold strat

           |                          Fold
      ybin |         1          2          3          4          5 |     Total
-----------+-------------------------------------------------------+----------
         0 |        54         61         62         60         61 |       298
         1 |        20         24         21         17         28 |       110
-----------+-------------------------------------------------------+----------
     Total |        74         85         83         77         89 |       408
K-fold cross-validation with 5 folds.
Fold 1 2 3 4 5
          |         Lambda       Deviance       St. err.
----------+---------------------------------------------
         8|      9.7209919      .82739762       .0592582  ^
        15|      3.6235908      .74765361      .08344357  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

.
. cvlassologit ybin lcavol-pgg45 [fw=f], tabfold

           |                          Fold
      ybin |         1          2          3          4          5 |     Total
-----------+-------------------------------------------------------+----------
         0 |        67         40         59         69         63 |       298
         1 |        12         43         21         13         21 |       110
-----------+-------------------------------------------------------+----------
     Total |        79         83         80         82         84 |       408
K-fold cross-validation with 5 folds.
Fold 1 2 3 4 5
          |         Lambda       Deviance       St. err.
----------+---------------------------------------------
         7|      11.192705       .8891221       .1221579  ^
        16|      3.1471299      .79046066       .1276049  *
* lopt = the lambda that minimizes loss measure.
  Run model: cvlassologit, lopt
^ lse = largest lambda for which MSPE is within one standard error of the minimum loss.
  Run model: cvlassologit, lse
  Use 'long' option for long output.

.
end of do-file

.
. do "cs_rlassologit.do"

. clear all

.
.
.
. ***************************************************************
. *** verifying against "hdm" package in R (Spindler et al.)      ***
. *** hdmlambda option ensures same lambda is used                        ***
. ***************************************************************
.
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. rlassologit v58 v1-v57  , hdmlambda

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v3 |       0.0818368      0.0911749
               v5 |       0.3792664      0.6003482
               v6 |       0.4090015      0.8485870
               v7 |       1.8997413      2.4474283
               v8 |       0.4309734      0.6402136
               v9 |       0.3156239      0.7260621
              v10 |       0.0048763      0.1082446
              v16 |       0.4478750      0.9990454
              v17 |       0.4436761      0.9908264
              v18 |       0.1927575      0.1262342
              v19 |       0.0624956      0.0760883
              v20 |       0.2483980      1.2342767
              v21 |       0.2451824      0.1639695
              v22 |       0.1095403      0.3409440
              v23 |       1.4367754      2.1978709
              v24 |       0.4404862      0.5174827
              v25 |      -0.4796520     -1.9504124
              v26 |      -0.2233588     -0.8650710
              v27 |      -0.0873983    -12.3111997
              v33 |      -0.1435278     -0.8031068
              v37 |      -0.1344359      0.0241819
              v39 |      -0.0322820     -0.8265198
              v42 |      -0.2993749     -2.7999670
              v43 |      -0.0176102     -1.2816720
              v44 |      -0.0403139     -1.7105127
              v45 |      -0.2157528     -0.7307022
              v46 |      -0.2559548     -1.5712564
              v48 |      -0.0046234     -4.5397346
              v49 |      -0.1124130     -1.2103938
              v52 |       0.4188453      0.3924539
              v53 |       3.2560117      5.7099315
              v56 |       0.0009226      0.0119033
              v57 |       0.0004327      0.0005627
            _cons |      -1.6692523     -1.6805612
------------------+--------------------------------

. mat S = e(beta)'

. mat G = ( 0 \ 0 \ 0.0818948712695488 \ 0 \ 0.379429361719609 \ 0.409109085956748 \ 1.9003258692222 \ 0.431150805857511 \ 0.315744217129519 \ 0.0049820928287534 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0.447978507142549 \ 0.443934277021981 \ 0.192865405720127 \ 0.0625091762029476 \ 0.248557045294218 \ 0.245131827365983 \ 0.109668219678555 \ 1.43731652314774 \ 0.440704475266581 \ -0.480122280718989 \ -0.223595359843765 \ -0.0875263945521702 \ 0 \ 0 \ 0 \ 0 \ 0 \ -0.14385510842836 \ 0 \ 0 \ 0 \ -0.134425982189653 \ 0 \ -0.0324979517942505 \ 0 \ 0 \ -0.299792597221532 \ -0.0178914234516845 \ -0.0405270661669486 \ -0.215984667465846 \ -0.256364202865828 \ 0 \ -0.00501707194224279 \ -0.113031184465464 \ 0 \ 0 \ 0.418975832790503 \ 3.25756538129954 \ 0 \ 0 \ 0.000923864682472632 \ 0.000432834090656421 \ -1.66933973402153 )

. di mreldif(S,G)
.00055544

. di e(lambda)
69.269209

. assert mreldif(S,G)<0.01

.
. rlassologit v58 v1-v57 ,nocons hdmlambda

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0864021     -0.2438703
               v5 |       0.1420729      0.3237584
               v6 |       0.0696147      0.3658951
               v7 |       1.5124094      2.1483182
               v8 |       0.2413068      0.5279629
               v9 |       0.0892406      0.4630417
              v12 |      -0.2626754     -0.4051575
              v15 |       0.0219290      1.2633487
              v16 |       0.2736968      0.7948602
              v17 |       0.3267519      0.8489358
              v18 |       0.0176134     -0.0498307
              v20 |       0.2297984      1.3342773
              v21 |       0.0820892      0.0455995
              v22 |       0.0349657      0.3273623
              v23 |       1.2756734      1.9759747
              v24 |       0.3183246      0.3824989
              v25 |      -0.7536021     -2.2393589
              v26 |      -0.3712635     -0.9748771
              v27 |      -0.1840658     -9.3264461
              v33 |      -0.4515223     -1.0869808
              v35 |      -0.0468163     -2.1547606
              v37 |      -0.3779250     -0.2253376
              v39 |      -0.1360625     -0.9567674
              v42 |      -0.4949375     -3.0244352
              v43 |      -0.1919772     -1.9012782
              v44 |      -0.2743111     -2.3028157
              v45 |      -0.5126451     -1.1017958
              v46 |      -0.6227560     -2.1768003
              v47 |      -0.2272200     -2.6396062
              v48 |      -0.2895492     -4.3496106
              v49 |      -0.3642791     -1.6163529
              v50 |      -0.9797083     -1.0482526
              v51 |      -0.3254104     -1.6765103
              v52 |       0.1608367      0.2229926
              v53 |       2.8008370      5.1863222
              v56 |       0.0007093      0.0078098
              v57 |       0.0000976      0.0003042
------------------+--------------------------------

. mat S = e(beta)'

. mat G = ( 0 \ -0.0864040297967744 \ 0 \ 0 \ 0.14203538121037 \ 0.0696029895895297 \ 1.5124020295351 \ 0.241304873304514 \ 0.089231885869934 \ 0 \ 0 \ -0.262648802099565 \ 0 \ 0 \ 0.0221381492679238 \ 0.273749502669813 \ 0.32684735941686 \ 0.0176157322393083 \ 0 \ 0.229847624122447 \ 0.0820838755349145 \ 0.0349736719705019 \ 1.27572289568391 \ 0.318345425501668 \ -0.75361780468791 \ -0.371276657650674 \ -0.184069780173229 \ 0 \ 0 \ 0 \ 0 \ 0 \ -0.451510644154917 \ 0 \ -0.0468459332646387 \ 0 \ -0.377889219838404 \ 0 \ -0.136072245922347 \ 0 \ 0 \ -0.494978796805398 \ -0.191973864938743 \ -0.274310171697392 \ -0.512607089354212 \ -0.622744742178529 \ -0.227169791356443 \ -0.289531930392509 \ -0.364271673492403 \ -0.979682797504907 \ -0.325414901150868 \ 0.160823428575976 \ 2.80067037980844 \ 0 \ 0 \ 0.00070917591496024 \ 9.75715276693764e-05 )

. di mreldif(S,G)
.00020463

. di e(lambda)
69.187102

. assert mreldif(S,G)<0.01

.
. rlassologit v58 v1-v57 , postl hdmlambda

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v3 |       0.0818368      0.0911749
               v5 |       0.3792664      0.6003482
               v6 |       0.4090015      0.8485870
               v7 |       1.8997413      2.4474283
               v8 |       0.4309734      0.6402136
               v9 |       0.3156239      0.7260621
              v10 |       0.0048763      0.1082446
              v16 |       0.4478750      0.9990454
              v17 |       0.4436761      0.9908264
              v18 |       0.1927575      0.1262342
              v19 |       0.0624956      0.0760883
              v20 |       0.2483980      1.2342767
              v21 |       0.2451824      0.1639695
              v22 |       0.1095403      0.3409440
              v23 |       1.4367754      2.1978709
              v24 |       0.4404862      0.5174827
              v25 |      -0.4796520     -1.9504124
              v26 |      -0.2233588     -0.8650710
              v27 |      -0.0873983    -12.3111997
              v33 |      -0.1435278     -0.8031068
              v37 |      -0.1344359      0.0241819
              v39 |      -0.0322820     -0.8265198
              v42 |      -0.2993749     -2.7999670
              v43 |      -0.0176102     -1.2816720
              v44 |      -0.0403139     -1.7105127
              v45 |      -0.2157528     -0.7307022
              v46 |      -0.2559548     -1.5712564
              v48 |      -0.0046234     -4.5397346
              v49 |      -0.1124130     -1.2103938
              v52 |       0.4188453      0.3924539
              v53 |       3.2560117      5.7099315
              v56 |       0.0009226      0.0119033
              v57 |       0.0004327      0.0005627
            _cons |      -1.6692523     -1.6805612
------------------+--------------------------------

. mat S = e(beta_post)'

. mat G = ( 0 \ 0 \ 0.0911749035363913 \ 0 \ 0.600348234636252 \ 0.848587006358465 \ 2.4474282743846 \ 0.640213550033936 \ 0.72606218429801 \ 0.108244564804095 \ 0 \ 0 \ 0 \ 0 \ 0 \ 0.999045440309051 \ 0.990826392555297 \ 0.126234229254353 \ 0.0760883260691006 \ 1.23427664731182 \ 0.163969519238026 \ 0.340943971216137 \ 2.19787084433997 \ 0.517482714211636 \ -1.95041244716883 \ -0.865071034109125 \ -12.3112008896115 \ 0 \ 0 \ 0 \ 0 \ 0 \ -0.803106762101585 \ 0 \ 0 \ 0 \ 0.0241819026296822 \ 0 \ -0.826519776504054 \ 0 \ 0 \ -2.79996722215776 \ -1.28167204241549 \ -1.71051269617404 \ -0.730702205605326 \ -1.57125641472336 \ 0 \ -4.53973467862469 \ -1.21039378912067 \ 0 \ 0 \ 0.392453914192812 \ 5.70993167564932 \ 0 \ 0 \ 0.0119032569623226 \ 0.000562741641538757 \ -1.6805612492106 )

. di mreldif(S,G)
9.266e-08

. di e(lambda)
69.269209

. assert mreldif(S,G)<0.01

.
. rlassologit v58 v1-v57 ,postl nocons hdmlambda

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0864021     -0.2438703
               v5 |       0.1420729      0.3237584
               v6 |       0.0696147      0.3658951
               v7 |       1.5124094      2.1483182
               v8 |       0.2413068      0.5279629
               v9 |       0.0892406      0.4630417
              v12 |      -0.2626754     -0.4051575
              v15 |       0.0219290      1.2633487
              v16 |       0.2736968      0.7948602
              v17 |       0.3267519      0.8489358
              v18 |       0.0176134     -0.0498307
              v20 |       0.2297984      1.3342773
              v21 |       0.0820892      0.0455995
              v22 |       0.0349657      0.3273623
              v23 |       1.2756734      1.9759747
              v24 |       0.3183246      0.3824989
              v25 |      -0.7536021     -2.2393589
              v26 |      -0.3712635     -0.9748771
              v27 |      -0.1840658     -9.3264461
              v33 |      -0.4515223     -1.0869808
              v35 |      -0.0468163     -2.1547606
              v37 |      -0.3779250     -0.2253376
              v39 |      -0.1360625     -0.9567674
              v42 |      -0.4949375     -3.0244352
              v43 |      -0.1919772     -1.9012782
              v44 |      -0.2743111     -2.3028157
              v45 |      -0.5126451     -1.1017958
              v46 |      -0.6227560     -2.1768003
              v47 |      -0.2272200     -2.6396062
              v48 |      -0.2895492     -4.3496106
              v49 |      -0.3642791     -1.6163529
              v50 |      -0.9797083     -1.0482526
              v51 |      -0.3254104     -1.6765103
              v52 |       0.1608367      0.2229926
              v53 |       2.8008370      5.1863222
              v56 |       0.0007093      0.0078098
              v57 |       0.0000976      0.0003042
------------------+--------------------------------

. mat S = e(beta_post)'

. mat G = ( 0 \ -0.243870343170744 \ 0 \ 0 \ 0.323758365384805 \ 0.365895137099397 \ 2.14831819350489 \ 0.52796289907392 \ 0.463041759179273 \ 0 \ 0 \ -0.40515745464642 \ 0 \ 0 \ 1.26334873669496 \ 0.794860192566074 \ 0.848935809630871 \ -0.0498307343945656 \ 0 \ 1.33427727401593 \ 0.0455995142062725 \ 0.327362342472093 \ 1.975974600918 \ 0.382498934793842 \ -2.23935890965794 \ -0.974877197129703 \ -9.3264468573156 \ 0 \ 0 \ 0 \ 0 \ 0 \ -1.08698081175868 \ 0 \ -2.15476075561477 \ 0 \ -0.225337578437582 \ 0 \ -0.956767386369015 \ 0 \ 0 \ -3.02443544634889 \ -1.90127824511308 \ -2.30281566974477 \ -1.10179581057555 \ -2.17680028017689 \ -2.63960623014879 \ -4.34961066961778 \ -1.61635289440844 \ -1.04825259598903 \ -1.67651030427761 \ 0.222992581890547 \ 5.18632237505927 \ 0 \ 0 \ 0.00780983251377047 \ 0.000304166775336087 )

. di mreldif(S,G)
7.670e-08

. di e(lambda)
69.187102

. assert mreldif(S,G)<0.01

.
end of do-file

.
. do "cs_predict.do"

.
. clear all

.
.
. ********************************************************************************
. *** Verify post-logit predictions                                                                                        ***
. ********************************************************************************
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

. gen myholdout = _n>4000

.
. foreach lam in 0.18 .1 .05 .01 0.005 0.001 {
  2.
.         cap drop yhat* phat*
  3.
.         lassologit v58 v1-v57, l(`lam') postlogit lambdan
  4.         predict double yhat_my, xb
  5.         predict double phat_my, pr
  6.
.         local sel = e(selected)
  7.         logit v58 `sel'
  8.         predict double yhat_logit, xb
  9.         predict double phat_logit, pr
 10.
.         assert reldif(yhat_my,yhat_logit)<10e4
 11.         assert reldif(phat_my,phat_logit)<10e4
 12. }

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v21 |       0.0251662      0.8584517
            _cons |      -0.4508119     -1.1097109
------------------+--------------------------------

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -2704.3835
Iteration 2:   log likelihood = -2703.6411
Iteration 3:   log likelihood = -2703.6409

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(1)        =     762.87
                                                Prob > chi2       =     0.0000
Log likelihood = -2703.6409                     Pseudo R2         =     0.1236

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
         v21 |    .8584517    .0368163     23.32    0.000       .786293     .9306104
       _cons |   -1.109711    .0423539    -26.20    0.000     -1.192723    -1.026699
-------------+----------------------------------------------------------------

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5412442      4.2194397
              v16 |       0.0569502      0.8984170
              v21 |       0.2448168      0.3940148
              v23 |       0.5126734      3.8072262
              v25 |      -0.0071134     -2.7490367
              v53 |       0.6310249      7.5984195
              v57 |       0.0000267      0.0011889
            _cons |      -0.8168528     -1.7667647
------------------+--------------------------------

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1756.6861
Iteration 2:   log likelihood = -1569.5018
Iteration 3:   log likelihood = -1512.4228
Iteration 4:   log likelihood = -1506.6144
Iteration 5:   log likelihood = -1506.5064
Iteration 6:   log likelihood = -1506.5064

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(7)        =    3157.14
                                                Prob > chi2       =     0.0000
Log likelihood = -1506.5064                     Pseudo R2         =     0.5117

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v7 |     4.21944    .3657308     11.54    0.000      3.502621     4.936259
         v16 |     .898417    .0914536      9.82    0.000      .7191713     1.077663
         v21 |    .3940148     .036492     10.80    0.000      .3224919     .4655378
         v23 |    3.807226    .4987968      7.63    0.000      2.829602      4.78485
         v25 |   -2.749037    .2717015    -10.12    0.000     -3.281562    -2.216512
         v53 |    7.598419    .6620765     11.48    0.000      6.300773     8.896066
         v57 |    .0011889    .0001322      8.99    0.000      .0009298     .0014481
       _cons |   -1.766765    .0655888    -26.94    0.000     -1.895316    -1.638213
-------------+----------------------------------------------------------------


Note: 79 failures and 21 successes completely determined.


------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.1727807      0.4550969
               v6 |       0.2152931      0.9614203
               v7 |       1.1426365      3.2847248
               v8 |       0.1368686      0.6228345
               v9 |       0.1194438      1.2686870
              v16 |       0.2610206      1.1365279
              v17 |       0.1633636      1.1000374
              v18 |       0.0186096      0.3792675
              v19 |       0.0354681      0.0478566
              v20 |       0.0623173      1.6419546
              v21 |       0.2850692      0.2785537
              v23 |       0.9087893      3.0333616
              v24 |       0.1364868      0.7890926
              v25 |      -0.1194090     -1.8286444
              v26 |      -0.0365264     -1.1537435
              v27 |      -0.0021456     -8.0061923
              v52 |       0.1837436      0.4989944
              v53 |       1.5733685      5.1962139
              v57 |       0.0002816      0.0009413
            _cons |      -1.3345409     -2.1960013
------------------+--------------------------------

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1469.0752
Iteration 2:   log likelihood = -1283.6935
Iteration 3:   log likelihood = -1197.5571
Iteration 4:   log likelihood = -1176.8582
Iteration 5:   log likelihood =  -1171.683
Iteration 6:   log likelihood = -1170.4581
Iteration 7:   log likelihood = -1170.4163
Iteration 8:   log likelihood = -1170.4162

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(19)       =    3829.32
                                                Prob > chi2       =     0.0000
Log likelihood = -1170.4162                     Pseudo R2         =     0.6206

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v5 |    .4550969    .0707022      6.44    0.000      .3165231     .5936707
          v6 |    .9614203    .2095233      4.59    0.000      .5507623     1.372078
          v7 |    3.284725    .3554478      9.24    0.000       2.58806      3.98139
          v8 |    .6228345    .1469756      4.24    0.000      .3347677     .9109014
          v9 |    1.268687    .2753861      4.61    0.000      .7289401     1.808434
         v16 |    1.136528    .1236747      9.19    0.000      .8941299     1.378926
         v17 |    1.100037     .213033      5.16    0.000      .6825004     1.517574
         v18 |    .3792675     .111105      3.41    0.001      .1615056     .5970294
         v19 |    .0478566    .0294369      1.63    0.104     -.0098386     .1055518
         v20 |    1.641955    .4716646      3.48    0.000       .717509       2.5664
         v21 |    .2785537    .0413681      6.73    0.000      .1974738     .3596336
         v23 |    3.033362    .4879427      6.22    0.000      2.077011     3.989712
         v24 |    .7890926    .2063253      3.82    0.000      .3847024     1.193483
         v25 |   -1.828644    .2862979     -6.39    0.000     -2.389778    -1.267511
         v26 |   -1.153743    .4202757     -2.75    0.006     -1.977469    -.3300183
         v27 |   -8.006192    1.986354     -4.03    0.000     -11.89937     -4.11301
         v52 |    .4989944    .0862705      5.78    0.000      .3299073     .6680815
         v53 |    5.196214    .6349955      8.18    0.000      3.951646     6.440782
         v57 |    .0009413    .0001316      7.15    0.000      .0006834     .0011992
       _cons |   -2.196001    .0999864    -21.96    0.000     -2.391971    -2.000032
-------------+----------------------------------------------------------------


Note: 410 failures and 17 successes completely determined.


------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0029758     -0.1374068
               v3 |       0.0997006      0.0991317
               v4 |       0.0177195      2.3332627
               v5 |       0.4300180      0.5875146
               v6 |       0.4414639      0.8492650
               v7 |       2.0729214      2.4348325
               v8 |       0.4834239      0.5999610
               v9 |       0.3608079      0.7307504
              v10 |       0.0346937      0.1092016
              v16 |       0.4770478      0.9743012
              v17 |       0.5327560      0.9980701
              v18 |       0.2248792      0.1631271
              v19 |       0.0674714      0.0716554
              v20 |       0.3028956      1.2950750
              v21 |       0.2293296      0.1668222
              v22 |       0.1532995      0.3442095
              v23 |       1.6217945      2.2132158
              v24 |       0.5013475      0.4608378
              v25 |      -0.6533537     -1.9673969
              v26 |      -0.3152566     -0.8402018
              v27 |      -0.1489442    -11.8213888
              v33 |      -0.2637423     -0.7969994
              v37 |      -0.1231707      0.0122131
              v39 |      -0.1129272     -0.8643057
              v42 |      -0.4502577     -2.7183354
              v43 |      -0.1147941     -1.3022334
              v44 |      -0.1292291     -1.7243178
              v45 |      -0.2962770     -0.7519671
              v46 |      -0.4141769     -1.5712385
              v47 |      -0.1448874     -2.3148858
              v48 |      -0.1707776     -4.5901990
              v49 |      -0.3176464     -1.2411361
              v52 |       0.4532346      0.3692874
              v53 |       3.7624097      5.7071085
              v56 |       0.0013703      0.0113318
              v57 |       0.0004691      0.0005470
            _cons |      -1.6849886     -1.6183501
------------------+--------------------------------

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1291.4638
Iteration 2:   log likelihood = -1095.7645
Iteration 3:   log likelihood = -988.96597
Iteration 4:   log likelihood = -967.42267
Iteration 5:   log likelihood = -955.69701
Iteration 6:   log likelihood = -954.03981
Iteration 7:   log likelihood = -954.03087
Iteration 8:   log likelihood = -954.03087

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(36)       =    4262.09
                                                Prob > chi2       =     0.0000
Log likelihood = -954.03087                     Pseudo R2         =     0.6908

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v2 |   -.1374068    .0672639     -2.04    0.041     -.2692415     -.005572
          v3 |    .0991317    .1069644      0.93    0.354     -.1105148     .3087781
          v4 |    2.333263     1.48968      1.57    0.117     -.5864558     5.252981
          v5 |    .5875146    .1010412      5.81    0.000      .3894774     .7855518
          v6 |     .849265    .2413254      3.52    0.000       .376276     1.322254
          v7 |    2.434833    .3310068      7.36    0.000      1.786071     3.083594
          v8 |     .599961    .1588476      3.78    0.000      .2886254     .9112965
          v9 |    .7307504    .2738482      2.67    0.008      .1940177     1.267483
         v10 |    .1092016    .0675371      1.62    0.106     -.0231686     .2415719
         v16 |    .9743012    .1345076      7.24    0.000       .710671     1.237931
         v17 |    .9980701    .2196837      4.54    0.000      .5674979     1.428642
         v18 |    .1631271    .1122602      1.45    0.146     -.0568989     .3831531
         v19 |    .0716554    .0339202      2.11    0.035      .0051731     .1381378
         v20 |    1.295075    .5578864      2.32    0.020      .2016377     2.388512
         v21 |    .1668222    .0446003      3.74    0.000      .0794071     .2542372
         v22 |    .3442095    .1344195      2.56    0.010       .080752     .6076669
         v23 |    2.213216    .4661841      4.75    0.000      1.299512      3.12692
         v24 |    .4608378    .1687377      2.73    0.006      .1301179     .7915577
         v25 |   -1.967397    .2945318     -6.68    0.000     -2.544669    -1.390125
         v26 |   -.8402018    .4027778     -2.09    0.037     -1.629632    -.0507718
         v27 |   -11.82139    1.785514     -6.62    0.000     -15.32093    -8.321845
         v33 |   -.7969994    .2982932     -2.67    0.008     -1.381643    -.2123554
         v37 |    .0122131    .1741632      0.07    0.944     -.3291405     .3535667
         v39 |   -.8643057    .3729285     -2.32    0.020     -1.595232    -.1333793
         v42 |   -2.718335    .8314565     -3.27    0.001      -4.34796    -1.088711
         v43 |   -1.302233     .806224     -1.62    0.106     -2.882404     .2779367
         v44 |   -1.724318    .5309969     -3.25    0.001     -2.765053    -.6835831
         v45 |   -.7519671    .1504803     -5.00    0.000     -1.046903    -.4570311
         v46 |   -1.571238    .2724616     -5.77    0.000     -2.105253    -1.037224
         v47 |   -2.314886    1.645815     -1.41    0.160     -5.540623     .9108515
         v48 |   -4.590199    1.745301     -2.63    0.009     -8.010926    -1.169472
         v49 |   -1.241136    .4124564     -3.01    0.003     -2.049536    -.4327364
         v52 |    .3692874    .0893144      4.13    0.000      .1942343     .5443405
         v53 |    5.707108    .7229834      7.89    0.000      4.290087      7.12413
         v56 |    .0113318    .0017521      6.47    0.000      .0078978     .0147657
         v57 |     .000547      .00017      3.22    0.001      .0002138     .0008801
       _cons |    -1.61835    .1227107    -13.19    0.000     -1.858859    -1.377841
-------------+----------------------------------------------------------------


Note: 546 failures and 29 successes completely determined.


------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.0679826     -0.4973776
               v2 |      -0.0494522     -0.1491788
               v3 |       0.1148702      0.0946947
               v4 |       0.0538835      2.3127800
               v5 |       0.4859434      0.5565020
               v6 |       0.4965129      0.8275124
               v7 |       2.2422015      2.3353038
               v8 |       0.5381027      0.5824697
               v9 |       0.4307811      0.6613213
              v10 |       0.0617053      0.1105336
              v14 |       0.0136675      0.1739512
              v15 |       0.1997293      1.2701147
              v16 |       0.5874811      0.9593566
              v17 |       0.6509255      0.9836859
              v18 |       0.2359093      0.1219514
              v19 |       0.0716010      0.0683777
              v20 |       0.4013775      1.0729787
              v21 |       0.2134715      0.2133897
              v22 |       0.2149886      0.3521578
              v23 |       1.8816205      2.1630728
              v24 |       0.5523528      0.4311916
              v25 |      -0.9582616     -1.8797072
              v26 |      -0.4887831     -0.9039480
              v27 |      -0.4648677    -11.4597847
              v29 |      -0.1193588     -2.5138585
              v33 |      -0.4615122     -0.7369924
              v35 |      -0.0612672     -2.1647810
              v37 |      -0.0830439      0.0165618
              v39 |      -0.2532902     -0.7917925
              v41 |      -0.3023864    -45.3373480
              v42 |      -0.7192420     -2.6240140
              v43 |      -0.2684652     -1.3472954
              v44 |      -0.3735859     -1.5771656
              v45 |      -0.4176531     -0.7515336
              v46 |      -0.6942240     -1.3888339
              v47 |      -0.6969481     -2.0860236
              v48 |      -0.6140350     -3.9163491
              v49 |      -0.6146071     -1.3204901
              v51 |      -0.1083647     -0.6231862
              v52 |       0.4628134      0.3578162
              v53 |       4.4025143      5.5347481
              v56 |       0.0022381      0.0105774
              v57 |       0.0005137      0.0007932
            _cons |      -1.6389957     -1.5486373
------------------+--------------------------------

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1281.8182
Iteration 2:   log likelihood = -1083.2277
Iteration 3:   log likelihood = -969.49359
Iteration 4:   log likelihood = -941.50247
Iteration 5:   log likelihood =  -927.8829
Iteration 6:   log likelihood = -925.73837
Iteration 7:   log likelihood = -925.38142
Iteration 8:   log likelihood = -925.35816
Iteration 9:   log likelihood = -925.35815

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(43)       =    4319.44
                                                Prob > chi2       =     0.0000
Log likelihood = -925.35815                     Pseudo R2         =     0.7001

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v1 |   -.4973776    .2123789     -2.34    0.019     -.9136326    -.0811226
          v2 |   -.1491788    .0702388     -2.12    0.034     -.2868443    -.0115133
          v3 |    .0946947    .1090294      0.87    0.385     -.1189989     .3083883
          v4 |     2.31278    1.483252      1.56    0.119     -.5943403       5.2199
          v5 |     .556502    .0999492      5.57    0.000      .3606051     .7523988
          v6 |    .8275124    .2416472      3.42    0.001      .3538927     1.301132
          v7 |    2.335304      .32711      7.14    0.000       1.69418     2.976428
          v8 |    .5824697    .1676119      3.48    0.001      .2539565     .9109829
          v9 |    .6613213    .2745632      2.41    0.016      .1231873     1.199455
         v10 |    .1105336    .0686961      1.61    0.108     -.0241082     .2451755
         v14 |    .1739512    .1330977      1.31    0.191     -.0869155     .4348179
         v15 |    1.270115    .7128356      1.78    0.075     -.1270173     2.667247
         v16 |    .9593566    .1364787      7.03    0.000      .6918633      1.22685
         v17 |    .9836859    .2215727      4.44    0.000      .5494113      1.41796
         v18 |    .1219514     .116775      1.04    0.296     -.1069235     .3508262
         v19 |    .0683777    .0340237      2.01    0.044      .0016925     .1350628
         v20 |    1.072979    .5312193      2.02    0.043       .031808     2.114149
         v21 |    .2133897    .0489292      4.36    0.000      .1174903     .3092891
         v22 |    .3521578    .1403479      2.51    0.012      .0770811     .6272346
         v23 |    2.163073     .466628      4.64    0.000      1.248499     3.077647
         v24 |    .4311916    .1621862      2.66    0.008      .1133125     .7490708
         v25 |   -1.879707    .2938923     -6.40    0.000     -2.455726    -1.303689
         v26 |    -.903948    .4131894     -2.19    0.029     -1.713784    -.0941116
         v27 |   -11.45978    1.811141     -6.33    0.000     -15.00956    -7.910014
         v29 |   -2.513859    1.466454     -1.71    0.086     -5.388056     .3603393
         v33 |   -.7369924    .3066182     -2.40    0.016     -1.337953    -.1360318
         v35 |   -2.164781    .7987813     -2.71    0.007     -3.730364    -.5991983
         v37 |    .0165618    .1739329      0.10    0.924     -.3243404     .3574641
         v39 |   -.7917925    .3617937     -2.19    0.029     -1.500895    -.0826899
         v41 |   -45.33735    27.20523     -1.67    0.096     -98.65863     7.983929
         v42 |   -2.624014    .8268212     -3.17    0.002     -4.244554    -1.003474
         v43 |   -1.347295    .8135381     -1.66    0.098     -2.941801     .2472099
         v44 |   -1.577166    .5292144     -2.98    0.003     -2.614407    -.5399245
         v45 |   -.7515336    .1503511     -5.00    0.000     -1.046216    -.4568507
         v46 |   -1.388834    .2646748     -5.25    0.000     -1.907587    -.8700809
         v47 |   -2.086024    1.585192     -1.32    0.188     -5.192943     1.020896
         v48 |   -3.916349    1.591033     -2.46    0.014     -7.034716    -.7979826
         v49 |    -1.32049    .4306051     -3.07    0.002     -2.164461    -.4765197
         v51 |   -.6231862     .807006     -0.77    0.440     -2.204889     .9585164
         v52 |    .3578162    .0896875      3.99    0.000      .1820319     .5336006
         v53 |    5.534748    .7067049      7.83    0.000      4.149632     6.919864
         v56 |    .0105774    .0018016      5.87    0.000      .0070463     .0141085
         v57 |    .0007932    .0002104      3.77    0.000      .0003807     .0012056
       _cons |   -1.548637    .1266906    -12.22    0.000     -1.796946    -1.300328
-------------+----------------------------------------------------------------


Note: 671 failures and 29 successes completely determined.


------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.2721427     -0.3791446
               v2 |      -0.1256800     -0.1447328
               v3 |       0.1390962      0.1116912
               v4 |       0.1959648      2.2303869
               v5 |       0.5268010      0.5582587
               v6 |       0.6398606      0.8601265
               v7 |       2.2994846      2.2783320
               v8 |       0.5586001      0.5710605
               v9 |       0.5722809      0.6990956
              v10 |       0.0989041      0.1296654
              v11 |      -0.0891131     -0.2668115
              v12 |      -0.1347646     -0.1400000
              v14 |       0.0962984      0.1383352
              v15 |       0.7678938      1.1864707
              v16 |       0.9920547      1.0388119
              v17 |       0.8492258      0.9487245
              v18 |       0.1525157      0.1163154
              v19 |       0.0809274      0.0795294
              v20 |       0.6817313      1.0912048
              v21 |       0.2268940      0.2445585
              v22 |       0.2481234      0.2030494
              v23 |       2.2554731      2.2312204
              v24 |       0.5401740      0.4300520
              v25 |      -1.5416988     -1.9352774
              v26 |      -0.8651848     -1.0338064
              v27 |      -1.4429282    -11.0879158
              v28 |       0.2993044      0.4472262
              v29 |      -0.9746506     -2.4821139
              v30 |      -0.2146547     -0.3202787
              v31 |      -0.1517780     -0.1846426
              v33 |      -0.7640629     -0.7389031
              v35 |      -0.9709911     -2.0911250
              v36 |       0.6658666      0.9324802
              v37 |      -0.0114706      0.0497937
              v38 |      -0.4369001     -0.5997047
              v39 |      -0.5880767     -0.8729110
              v40 |      -0.3570155     -0.3069746
              v41 |      -2.1216469    -44.7199772
              v42 |      -1.4707506     -2.7023265
              v43 |      -0.7101894     -1.2583446
              v44 |      -1.0508245     -1.5925970
              v45 |      -0.6734395     -0.7950828
              v46 |      -1.2119073     -1.4721241
              v47 |      -1.5974548     -2.3396021
              v48 |      -2.0645790     -3.9592386
              v49 |      -1.0606296     -1.2859350
              v50 |      -0.1278490     -0.1819038
              v51 |      -0.6705187     -0.6455945
              v52 |       0.4195137      0.3518535
              v53 |       5.0716911      5.3236593
              v54 |       1.0462340      2.4322398
              v56 |       0.0046267      0.0102458
              v57 |       0.0006104      0.0008063
            _cons |      -1.5323641     -1.5551758
------------------+--------------------------------

Iteration 0:   log likelihood = -3085.0764
Iteration 1:   log likelihood = -1281.0337
Iteration 2:   log likelihood = -1091.3584
Iteration 3:   log likelihood = -970.45968
Iteration 4:   log likelihood = -928.52995
Iteration 5:   log likelihood = -915.56549
Iteration 6:   log likelihood = -909.26467
Iteration 7:   log likelihood = -908.70395
Iteration 8:   log likelihood = -908.58998
Iteration 9:   log likelihood = -908.58879
Iteration 10:  log likelihood = -908.58879

Logistic regression                             Number of obs     =      4,601
                                                LR chi2(53)       =    4352.98
                                                Prob > chi2       =     0.0000
Log likelihood = -908.58879                     Pseudo R2         =     0.7055

-------------+----------------------------------------------------------------
          v58 |      Coef.    Std. Err.       z    P>|z|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
          v1 |   -.3791446    .2291153     -1.65    0.098     -.8282023     .0699132
          v2 |   -.1447328    .0687834     -2.10    0.035     -.2795457    -.0099198
          v3 |    .1116912    .1098767      1.02    0.309     -.1036632     .3270457
          v4 |    2.230387    1.497854      1.49    0.136     -.7053536     5.166127
          v5 |    .5582587    .1013496      5.51    0.000      .3596172     .7569002
          v6 |    .8601265    .2470516      3.48    0.000      .3759143     1.344339
          v7 |    2.278332    .3326932      6.85    0.000      1.626265     2.930399
          v8 |    .5710605    .1681879      3.40    0.001      .2414183     .9007026
          v9 |    .6990956     .278946      2.51    0.012      .1523714      1.24582
         v10 |    .1296654    .0716798      1.81    0.070     -.0108244     .2701552
         v11 |   -.2668115    .2977127     -0.90    0.370     -.8503178     .3166947
         v12 |        -.14    .0740752     -1.89    0.059     -.2851847     .0051846
         v14 |    .1383352    .1360127      1.02    0.309     -.1282447     .4049151
         v15 |    1.186471     .714746      1.66    0.097     -.2144057     2.587347
         v16 |    1.038812    .1452214      7.15    0.000      .7541831     1.323441
         v17 |    .9487245    .2243132      4.23    0.000      .5090786      1.38837
         v18 |    .1163154    .1167751      1.00    0.319     -.1125596     .3451904
         v19 |    .0795294    .0350178      2.27    0.023      .0108957      .148163
         v20 |    1.091205      .54262      2.01    0.044      .0276891      2.15472
         v21 |    .2445585    .0523241      4.67    0.000       .142005     .3471119
         v22 |    .2030494    .1625843      1.25    0.212       -.11561     .5217087
         v23 |     2.23122    .4696526      4.75    0.000      1.310718     3.151722
         v24 |     .430052    .1624451      2.65    0.008      .1116654     .7484385
         v25 |   -1.935277    .3138415     -6.17    0.000     -2.550395    -1.320159
         v26 |   -1.033806    .4397403     -2.35    0.019     -1.895682    -.1719312
         v27 |   -11.08792    1.812851     -6.12    0.000     -14.64104    -7.534794
         v28 |    .4472262     .200055      2.24    0.025      .0551257     .8393267
         v29 |   -2.482114    1.500956     -1.65    0.098     -5.423933      .459705
         v30 |   -.3202787     .312797     -1.02    0.306     -.9333496     .2927922
         v31 |   -.1846426    .5228059     -0.35    0.724     -1.209323     .8400381
         v33 |   -.7389031    .3106915     -2.38    0.017     -1.347847     -.129959
         v35 |   -2.091125    .7805987     -2.68    0.007      -3.62107    -.5611796
         v36 |    .9324802     .309005      3.02    0.003      .3268416     1.538119
         v37 |    .0497937    .1750451      0.28    0.776     -.2932884     .3928758
         v38 |   -.5997047    .4262241     -1.41    0.159     -1.435089     .2356793
         v39 |    -.872911    .3831098     -2.28    0.023     -1.623792    -.1220297
         v40 |   -.3069746    .3643892     -0.84    0.400     -1.021164     .4072151
         v41 |   -44.71998    26.66045     -1.68    0.093     -96.97351     7.533554
         v42 |   -2.702327    .8331605     -3.24    0.001     -4.335291    -1.069362
         v43 |   -1.258345    .8116953     -1.55    0.121     -2.849238     .3325488
         v44 |   -1.592597    .5317162     -3.00    0.003     -2.634742    -.5504523
         v45 |   -.7950828    .1560284     -5.10    0.000     -1.100893    -.4892727
         v46 |   -1.472124    .2694301     -5.46    0.000     -2.000197    -.9440508
         v47 |   -2.339602    1.673053     -1.40    0.162     -5.618725     .9395212
         v48 |   -3.959239    1.557008     -2.54    0.011     -7.010917    -.9075599
         v49 |   -1.285935    .4405162     -2.92    0.004     -2.149331    -.4225391
         v50 |   -.1819038    .2486862     -0.73    0.464     -.6693198     .3055123
         v51 |   -.6455945    .8299164     -0.78    0.437     -2.272201     .9810118
         v52 |    .3518535    .0894266      3.93    0.000      .1765806     .5271264
         v53 |    5.323659    .7044546      7.56    0.000      3.942954     6.704365
         v54 |     2.43224    1.112616      2.19    0.029      .2515532     4.612926
         v56 |    .0102458    .0017977      5.70    0.000      .0067223     .0137693
         v57 |    .0008063    .0002138      3.77    0.000      .0003873     .0012254
       _cons |   -1.555176    .1390541    -11.18    0.000     -1.827717    -1.282635
-------------+----------------------------------------------------------------


Note: 669 failures and 31 successes completely determined.


. //
.
. ********************************************************************************
. *** Verify "predict" using internal ("Mata") predictions                                         ***
. ********************************************************************************
.
. foreach lam in 0.18 .1 .05 .01 0.005 0.001 {
  2.
.         insheet using "spam.data", clear delim(" ")
  3.         gen myholdout = _n>4000
  4.
.         di "lambda = `lam'"
  5.
.         lassologit v58 v1-v57, l(`lam') savep lambdan
  6.         mat P = e(phat)
  7.         svmat P
  8.
.         predict double p0, pr
  9.
.         assert reldif(P1,p0)<10e-4
 10.
. }
(58 vars, 4,601 obs)
lambda = 0.18

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v21 |       0.0251662      0.8584517
            _cons |      -0.4508119     -1.1097109
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .1

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5412442      4.2194397
              v16 |       0.0569502      0.8984170
              v21 |       0.2448168      0.3940148
              v23 |       0.5126734      3.8072262
              v25 |      -0.0071134     -2.7490367
              v53 |       0.6310249      7.5984195
              v57 |       0.0000267      0.0011889
            _cons |      -0.8168528     -1.7667647
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .05

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.1727807      0.4550969
               v6 |       0.2152931      0.9614203
               v7 |       1.1426365      3.2847248
               v8 |       0.1368686      0.6228345
               v9 |       0.1194438      1.2686870
              v16 |       0.2610206      1.1365279
              v17 |       0.1633636      1.1000374
              v18 |       0.0186096      0.3792675
              v19 |       0.0354681      0.0478566
              v20 |       0.0623173      1.6419546
              v21 |       0.2850692      0.2785537
              v23 |       0.9087893      3.0333616
              v24 |       0.1364868      0.7890926
              v25 |      -0.1194090     -1.8286444
              v26 |      -0.0365264     -1.1537435
              v27 |      -0.0021456     -8.0061923
              v52 |       0.1837436      0.4989944
              v53 |       1.5733685      5.1962139
              v57 |       0.0002816      0.0009413
            _cons |      -1.3345409     -2.1960013
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .01

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0029758     -0.1374068
               v3 |       0.0997006      0.0991317
               v4 |       0.0177195      2.3332627
               v5 |       0.4300180      0.5875146
               v6 |       0.4414639      0.8492650
               v7 |       2.0729214      2.4348325
               v8 |       0.4834239      0.5999610
               v9 |       0.3608079      0.7307504
              v10 |       0.0346937      0.1092016
              v16 |       0.4770478      0.9743012
              v17 |       0.5327560      0.9980701
              v18 |       0.2248792      0.1631271
              v19 |       0.0674714      0.0716554
              v20 |       0.3028956      1.2950750
              v21 |       0.2293296      0.1668222
              v22 |       0.1532995      0.3442095
              v23 |       1.6217945      2.2132158
              v24 |       0.5013475      0.4608378
              v25 |      -0.6533537     -1.9673969
              v26 |      -0.3152566     -0.8402018
              v27 |      -0.1489442    -11.8213888
              v33 |      -0.2637423     -0.7969994
              v37 |      -0.1231707      0.0122131
              v39 |      -0.1129272     -0.8643057
              v42 |      -0.4502577     -2.7183354
              v43 |      -0.1147941     -1.3022334
              v44 |      -0.1292291     -1.7243178
              v45 |      -0.2962770     -0.7519671
              v46 |      -0.4141769     -1.5712385
              v47 |      -0.1448874     -2.3148858
              v48 |      -0.1707776     -4.5901990
              v49 |      -0.3176464     -1.2411361
              v52 |       0.4532346      0.3692874
              v53 |       3.7624097      5.7071085
              v56 |       0.0013703      0.0113318
              v57 |       0.0004691      0.0005470
            _cons |      -1.6849886     -1.6183501
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = 0.005

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.0679826     -0.4973776
               v2 |      -0.0494522     -0.1491788
               v3 |       0.1148702      0.0946947
               v4 |       0.0538835      2.3127800
               v5 |       0.4859434      0.5565020
               v6 |       0.4965129      0.8275124
               v7 |       2.2422015      2.3353038
               v8 |       0.5381027      0.5824697
               v9 |       0.4307811      0.6613213
              v10 |       0.0617053      0.1105336
              v14 |       0.0136675      0.1739512
              v15 |       0.1997293      1.2701147
              v16 |       0.5874811      0.9593566
              v17 |       0.6509255      0.9836859
              v18 |       0.2359093      0.1219514
              v19 |       0.0716010      0.0683777
              v20 |       0.4013775      1.0729787
              v21 |       0.2134715      0.2133897
              v22 |       0.2149886      0.3521578
              v23 |       1.8816205      2.1630728
              v24 |       0.5523528      0.4311916
              v25 |      -0.9582616     -1.8797072
              v26 |      -0.4887831     -0.9039480
              v27 |      -0.4648677    -11.4597847
              v29 |      -0.1193588     -2.5138585
              v33 |      -0.4615122     -0.7369924
              v35 |      -0.0612672     -2.1647810
              v37 |      -0.0830439      0.0165618
              v39 |      -0.2532902     -0.7917925
              v41 |      -0.3023864    -45.3373480
              v42 |      -0.7192420     -2.6240140
              v43 |      -0.2684652     -1.3472954
              v44 |      -0.3735859     -1.5771656
              v45 |      -0.4176531     -0.7515336
              v46 |      -0.6942240     -1.3888339
              v47 |      -0.6969481     -2.0860236
              v48 |      -0.6140350     -3.9163491
              v49 |      -0.6146071     -1.3204901
              v51 |      -0.1083647     -0.6231862
              v52 |       0.4628134      0.3578162
              v53 |       4.4025143      5.5347481
              v56 |       0.0022381      0.0105774
              v57 |       0.0005137      0.0007932
            _cons |      -1.6389957     -1.5486373
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = 0.001

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.2721427     -0.3791446
               v2 |      -0.1256800     -0.1447328
               v3 |       0.1390962      0.1116912
               v4 |       0.1959648      2.2303869
               v5 |       0.5268010      0.5582587
               v6 |       0.6398606      0.8601265
               v7 |       2.2994846      2.2783320
               v8 |       0.5586001      0.5710605
               v9 |       0.5722809      0.6990956
              v10 |       0.0989041      0.1296654
              v11 |      -0.0891131     -0.2668115
              v12 |      -0.1347646     -0.1400000
              v14 |       0.0962984      0.1383352
              v15 |       0.7678938      1.1864707
              v16 |       0.9920547      1.0388119
              v17 |       0.8492258      0.9487245
              v18 |       0.1525157      0.1163154
              v19 |       0.0809274      0.0795294
              v20 |       0.6817313      1.0912048
              v21 |       0.2268940      0.2445585
              v22 |       0.2481234      0.2030494
              v23 |       2.2554731      2.2312204
              v24 |       0.5401740      0.4300520
              v25 |      -1.5416988     -1.9352774
              v26 |      -0.8651848     -1.0338064
              v27 |      -1.4429282    -11.0879158
              v28 |       0.2993044      0.4472262
              v29 |      -0.9746506     -2.4821139
              v30 |      -0.2146547     -0.3202787
              v31 |      -0.1517780     -0.1846426
              v33 |      -0.7640629     -0.7389031
              v35 |      -0.9709911     -2.0911250
              v36 |       0.6658666      0.9324802
              v37 |      -0.0114706      0.0497937
              v38 |      -0.4369001     -0.5997047
              v39 |      -0.5880767     -0.8729110
              v40 |      -0.3570155     -0.3069746
              v41 |      -2.1216469    -44.7199772
              v42 |      -1.4707506     -2.7023265
              v43 |      -0.7101894     -1.2583446
              v44 |      -1.0508245     -1.5925970
              v45 |      -0.6734395     -0.7950828
              v46 |      -1.2119073     -1.4721241
              v47 |      -1.5974548     -2.3396021
              v48 |      -2.0645790     -3.9592386
              v49 |      -1.0606296     -1.2859350
              v50 |      -0.1278490     -0.1819038
              v51 |      -0.6705187     -0.6455945
              v52 |       0.4195137      0.3518535
              v53 |       5.0716911      5.3236593
              v54 |       1.0462340      2.4322398
              v56 |       0.0046267      0.0102458
              v57 |       0.0006104      0.0008063
            _cons |      -1.5323641     -1.5551758
------------------+--------------------------------

. //
.
. foreach lam in 0.18 .1 .05 .01 0.005 0.001 {
  2.
.         insheet using "spam.data", clear delim(" ")
  3.         gen myholdout = _n>4000
  4.
.         di "lambda = `lam'"
  5.
.         lassologit v58 v1-v57, l(`lam') savep postlogit lambdan
  6.         mat P = e(phat)
  7.         svmat P
  8.
.         predict double p0, pr
  9.
.         assert reldif(P1,p0)<10e-4
 10.
. }
(58 vars, 4,601 obs)
lambda = 0.18

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
              v21 |       0.0251662      0.8584517
            _cons |      -0.4508119     -1.1097109
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .1

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5412442      4.2194397
              v16 |       0.0569502      0.8984170
              v21 |       0.2448168      0.3940148
              v23 |       0.5126734      3.8072262
              v25 |      -0.0071134     -2.7490367
              v53 |       0.6310249      7.5984195
              v57 |       0.0000267      0.0011889
            _cons |      -0.8168528     -1.7667647
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .05

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v5 |       0.1727807      0.4550969
               v6 |       0.2152931      0.9614203
               v7 |       1.1426365      3.2847248
               v8 |       0.1368686      0.6228345
               v9 |       0.1194438      1.2686870
              v16 |       0.2610206      1.1365279
              v17 |       0.1633636      1.1000374
              v18 |       0.0186096      0.3792675
              v19 |       0.0354681      0.0478566
              v20 |       0.0623173      1.6419546
              v21 |       0.2850692      0.2785537
              v23 |       0.9087893      3.0333616
              v24 |       0.1364868      0.7890926
              v25 |      -0.1194090     -1.8286444
              v26 |      -0.0365264     -1.1537435
              v27 |      -0.0021456     -8.0061923
              v52 |       0.1837436      0.4989944
              v53 |       1.5733685      5.1962139
              v57 |       0.0002816      0.0009413
            _cons |      -1.3345409     -2.1960013
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .01

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v2 |      -0.0029758     -0.1374068
               v3 |       0.0997006      0.0991317
               v4 |       0.0177195      2.3332627
               v5 |       0.4300180      0.5875146
               v6 |       0.4414639      0.8492650
               v7 |       2.0729214      2.4348325
               v8 |       0.4834239      0.5999610
               v9 |       0.3608079      0.7307504
              v10 |       0.0346937      0.1092016
              v16 |       0.4770478      0.9743012
              v17 |       0.5327560      0.9980701
              v18 |       0.2248792      0.1631271
              v19 |       0.0674714      0.0716554
              v20 |       0.3028956      1.2950750
              v21 |       0.2293296      0.1668222
              v22 |       0.1532995      0.3442095
              v23 |       1.6217945      2.2132158
              v24 |       0.5013475      0.4608378
              v25 |      -0.6533537     -1.9673969
              v26 |      -0.3152566     -0.8402018
              v27 |      -0.1489442    -11.8213888
              v33 |      -0.2637423     -0.7969994
              v37 |      -0.1231707      0.0122131
              v39 |      -0.1129272     -0.8643057
              v42 |      -0.4502577     -2.7183354
              v43 |      -0.1147941     -1.3022334
              v44 |      -0.1292291     -1.7243178
              v45 |      -0.2962770     -0.7519671
              v46 |      -0.4141769     -1.5712385
              v47 |      -0.1448874     -2.3148858
              v48 |      -0.1707776     -4.5901990
              v49 |      -0.3176464     -1.2411361
              v52 |       0.4532346      0.3692874
              v53 |       3.7624097      5.7071085
              v56 |       0.0013703      0.0113318
              v57 |       0.0004691      0.0005470
            _cons |      -1.6849886     -1.6183501
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = 0.005

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.0679826     -0.4973776
               v2 |      -0.0494522     -0.1491788
               v3 |       0.1148702      0.0946947
               v4 |       0.0538835      2.3127800
               v5 |       0.4859434      0.5565020
               v6 |       0.4965129      0.8275124
               v7 |       2.2422015      2.3353038
               v8 |       0.5381027      0.5824697
               v9 |       0.4307811      0.6613213
              v10 |       0.0617053      0.1105336
              v14 |       0.0136675      0.1739512
              v15 |       0.1997293      1.2701147
              v16 |       0.5874811      0.9593566
              v17 |       0.6509255      0.9836859
              v18 |       0.2359093      0.1219514
              v19 |       0.0716010      0.0683777
              v20 |       0.4013775      1.0729787
              v21 |       0.2134715      0.2133897
              v22 |       0.2149886      0.3521578
              v23 |       1.8816205      2.1630728
              v24 |       0.5523528      0.4311916
              v25 |      -0.9582616     -1.8797072
              v26 |      -0.4887831     -0.9039480
              v27 |      -0.4648677    -11.4597847
              v29 |      -0.1193588     -2.5138585
              v33 |      -0.4615122     -0.7369924
              v35 |      -0.0612672     -2.1647810
              v37 |      -0.0830439      0.0165618
              v39 |      -0.2532902     -0.7917925
              v41 |      -0.3023864    -45.3373480
              v42 |      -0.7192420     -2.6240140
              v43 |      -0.2684652     -1.3472954
              v44 |      -0.3735859     -1.5771656
              v45 |      -0.4176531     -0.7515336
              v46 |      -0.6942240     -1.3888339
              v47 |      -0.6969481     -2.0860236
              v48 |      -0.6140350     -3.9163491
              v49 |      -0.6146071     -1.3204901
              v51 |      -0.1083647     -0.6231862
              v52 |       0.4628134      0.3578162
              v53 |       4.4025143      5.5347481
              v56 |       0.0022381      0.0105774
              v57 |       0.0005137      0.0007932
            _cons |      -1.6389957     -1.5486373
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = 0.001

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.2721427     -0.3791446
               v2 |      -0.1256800     -0.1447328
               v3 |       0.1390962      0.1116912
               v4 |       0.1959648      2.2303869
               v5 |       0.5268010      0.5582587
               v6 |       0.6398606      0.8601265
               v7 |       2.2994846      2.2783320
               v8 |       0.5586001      0.5710605
               v9 |       0.5722809      0.6990956
              v10 |       0.0989041      0.1296654
              v11 |      -0.0891131     -0.2668115
              v12 |      -0.1347646     -0.1400000
              v14 |       0.0962984      0.1383352
              v15 |       0.7678938      1.1864707
              v16 |       0.9920547      1.0388119
              v17 |       0.8492258      0.9487245
              v18 |       0.1525157      0.1163154
              v19 |       0.0809274      0.0795294
              v20 |       0.6817313      1.0912048
              v21 |       0.2268940      0.2445585
              v22 |       0.2481234      0.2030494
              v23 |       2.2554731      2.2312204
              v24 |       0.5401740      0.4300520
              v25 |      -1.5416988     -1.9352774
              v26 |      -0.8651848     -1.0338064
              v27 |      -1.4429282    -11.0879158
              v28 |       0.2993044      0.4472262
              v29 |      -0.9746506     -2.4821139
              v30 |      -0.2146547     -0.3202787
              v31 |      -0.1517780     -0.1846426
              v33 |      -0.7640629     -0.7389031
              v35 |      -0.9709911     -2.0911250
              v36 |       0.6658666      0.9324802
              v37 |      -0.0114706      0.0497937
              v38 |      -0.4369001     -0.5997047
              v39 |      -0.5880767     -0.8729110
              v40 |      -0.3570155     -0.3069746
              v41 |      -2.1216469    -44.7199772
              v42 |      -1.4707506     -2.7023265
              v43 |      -0.7101894     -1.2583446
              v44 |      -1.0508245     -1.5925970
              v45 |      -0.6734395     -0.7950828
              v46 |      -1.2119073     -1.4721241
              v47 |      -1.5974548     -2.3396021
              v48 |      -2.0645790     -3.9592386
              v49 |      -1.0606296     -1.2859350
              v50 |      -0.1278490     -0.1819038
              v51 |      -0.6705187     -0.6455945
              v52 |       0.4195137      0.3518535
              v53 |       5.0716911      5.3236593
              v54 |       1.0462340      2.4322398
              v56 |       0.0046267      0.0102458
              v57 |       0.0006104      0.0008063
            _cons |      -1.5323641     -1.5551758
------------------+--------------------------------

. //
.
. foreach lam in .1 .05 .01 0.005 0.001 {
  2.
.         insheet using "spam.data", clear delim(" ")
  3.         gen myholdout = _n>4000
  4.
.         di "lambda = `lam'"
  5.
.         lassologit v58 v1-v57, l(`lam') savep nocons lambdan
  6.         mat P = e(phat)
  7.         svmat P
  8.
.         predict double p0, pr
  9.
.         assert reldif(P1,p0)<10e-4
 10.
. }
(58 vars, 4,601 obs)
lambda = .1

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.2650131      3.4924194
              v21 |       0.0024332      0.1020325
              v23 |       0.2750091      3.3829459
              v25 |      -0.1326806     -2.3257051
              v26 |      -0.0608907     -1.8382049
              v27 |      -0.0103742     -7.6421148
              v37 |      -0.0630326     -1.3603202
              v53 |       0.2095697      5.9704748
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .05

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.7933681      2.6253635
              v12 |      -0.0629520     -0.4247379
              v16 |       0.1067483      0.9324610
              v17 |       0.0710060      1.1060487
              v20 |       0.0238899      1.5232256
              v21 |       0.0680059      0.1468137
              v23 |       0.7250324      2.6941404
              v24 |       0.0479179      0.4504684
              v25 |      -0.3135342     -2.1956773
              v26 |      -0.1775486     -1.3329447
              v27 |      -0.0701598     -7.2267825
              v33 |      -0.0828687     -1.0037807
              v37 |      -0.3075390     -0.3504000
              v42 |      -0.1037288     -3.1005426
              v45 |      -0.1684503     -1.1473849
              v46 |      -0.1598983     -2.3516123
              v50 |      -0.2564002     -0.9437476
              v52 |       0.0245341      0.2775914
              v53 |       1.1899608      6.9886589
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = .01

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.0200614     -0.5365942
               v2 |      -0.1154487     -0.2437637
               v5 |       0.1956686      0.3515775
               v6 |       0.1165661      0.4697127
               v7 |       1.7000845      2.1879866
               v8 |       0.2964563      0.4535168
               v9 |       0.1377147      0.4396796
              v12 |      -0.2915625     -0.3305314
              v15 |       0.1204023      1.2645380
              v16 |       0.3284637      0.8163235
              v17 |       0.4203702      0.8761621
              v18 |       0.0486122     -0.0057940
              v19 |      -0.0207723     -0.0906895
              v20 |       0.2927478      1.2550231
              v21 |       0.0894498      0.1403134
              v22 |       0.0775057      0.3317326
              v23 |       1.4427914      2.0218483
              v24 |       0.3946862      0.4193053
              v25 |      -0.9369264     -2.2361590
              v26 |      -0.4647039     -1.0145500
              v27 |      -0.2576645     -9.4452785
              v29 |      -0.0450506     -3.5975876
              v33 |      -0.5899866     -1.0400269
              v35 |      -0.0918822     -2.1362442
              v37 |      -0.3583833     -0.2102179
              v39 |      -0.2118789     -0.9262838
              v41 |      -0.1033151    -34.1557491
              v42 |      -0.6598575     -2.8553308
              v43 |      -0.3301687     -1.8439233
              v44 |      -0.4364265     -2.1931420
              v45 |      -0.6039432     -0.9957092
              v46 |      -0.8008156     -1.8714535
              v47 |      -0.5115775     -2.5744130
              v48 |      -0.4924093     -3.7971354
              v49 |      -0.5587218     -1.6343045
              v50 |      -1.0800518     -0.9360925
              v51 |      -0.6243036     -1.6360753
              v52 |       0.1969136      0.2376949
              v53 |       3.2862404      4.9338768
              v56 |       0.0009495      0.0077243
              v57 |       0.0001419      0.0004734
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = 0.005

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.1809098     -0.5378352
               v2 |      -0.1572958     -0.2437759
               v4 |       0.0248724      2.1049508
               v5 |       0.2595450      0.3597005
               v6 |       0.2000386      0.5341243
               v7 |       1.9126344      2.1816531
               v8 |       0.3578740      0.4345871
               v9 |       0.2228842      0.5035271
              v12 |      -0.3141872     -0.3285839
              v13 |      -0.0875285     -0.3838125
              v15 |       0.3541591      1.5264669
              v16 |       0.5013869      0.8534160
              v17 |       0.5691099      0.9140972
              v18 |       0.0575477     -0.0097427
              v19 |      -0.0435866     -0.0856511
              v20 |       0.3980751      1.1929666
              v21 |       0.1054354      0.1407157
              v22 |       0.1420706      0.3282761
              v23 |       1.7201134      2.0721137
              v24 |       0.4724277      0.3984504
              v25 |      -1.2345621     -2.1574582
              v26 |      -0.6313617     -1.0300730
              v27 |      -0.5178155     -9.3080993
              v29 |      -0.3591801     -3.5319597
              v30 |      -0.1618564     -0.4851814
              v31 |      -0.0460959     -0.3252689
              v33 |      -0.7916608     -1.0259040
              v35 |      -0.2196920     -2.2944999
              v37 |      -0.3149194     -0.2114374
              v38 |      -0.1918730     -0.6960359
              v39 |      -0.3522176     -0.9350352
              v40 |      -0.0483340     -0.3780015
              v41 |      -0.4067984    -35.1248659
              v42 |      -0.9641550     -2.7912247
              v43 |      -0.5740110     -1.8487342
              v44 |      -0.7629171     -2.1331338
              v45 |      -0.7378221     -1.0101051
              v46 |      -1.1105821     -1.8257851
              v47 |      -0.9020297     -2.4623539
              v48 |      -0.9272575     -3.7774305
              v49 |      -0.8519997     -1.6597352
              v50 |      -1.1075606     -0.9226955
              v51 |      -1.1961591     -1.6631168
              v52 |       0.2273952      0.2330733
              v53 |       3.9489608      5.0332783
              v56 |       0.0014999      0.0077103
              v57 |       0.0002136      0.0004576
------------------+--------------------------------
(58 vars, 4,601 obs)
lambda = 0.001

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |      -0.3982812     -0.5384526
               v2 |      -0.2199557     -0.2435814
               v3 |      -0.0115065     -0.0829364
               v4 |       0.1436504      2.0968461
               v5 |       0.3343040      0.3616199
               v6 |       0.3856815      0.5459681
               v7 |       2.0959496      2.1145837
               v8 |       0.4107710      0.4150610
               v9 |       0.3989685      0.5202900
              v10 |       0.0151967      0.0332519
              v12 |      -0.3254717     -0.3318908
              v13 |      -0.2610576     -0.3470012
              v14 |      -0.0227294     -0.0519676
              v15 |       0.9111647      1.4541153
              v16 |       0.8280732      0.8757171
              v17 |       0.8068889      0.8974761
              v18 |       0.0162698     -0.0052409
              v19 |      -0.0686586     -0.0843323
              v20 |       0.7500576      1.2233055
              v21 |       0.1325490      0.1481123
              v22 |       0.2060752      0.1916727
              v23 |       2.0838490      2.1058144
              v24 |       0.4834125      0.4045198
              v25 |      -1.8348083     -2.2448002
              v26 |      -1.0129285     -1.1435044
              v27 |      -1.7329179     -9.1731030
              v28 |       0.2991569      0.4537484
              v29 |      -1.4051036     -3.5172228
              v30 |      -0.4119775     -0.4989323
              v31 |      -0.2362189     -0.3216134
              v33 |      -1.0382361     -1.0221971
              v35 |      -1.2583401     -2.3237163
              v36 |       0.1167889      0.3925375
              v37 |      -0.2344416     -0.1769186
              v38 |      -0.5851065     -0.7396187
              v39 |      -0.7198894     -0.9942981
              v40 |      -0.4284422     -0.5274777
              v41 |      -2.3932401    -35.4819610
              v42 |      -1.7659388     -2.8886123
              v43 |      -1.1357858     -1.7651116
              v44 |      -1.5697365     -2.1709830
              v45 |      -0.9170788     -0.9935707
              v46 |      -1.6453864     -1.8919245
              v47 |      -1.6567380     -2.4726632
              v48 |      -2.2231618     -3.7887919
              v49 |      -1.3284236     -1.6211424
              v50 |      -1.1716434     -1.2302896
              v51 |      -1.8222807     -1.6166041
              v52 |       0.2422685      0.2336426
              v53 |       4.7488119      4.9620987
              v54 |       0.8396562      2.2167321
              v56 |       0.0029953      0.0074715
              v57 |       0.0003678      0.0004834
------------------+--------------------------------

. //
.
. ********************************************************************************
. *** Verify using glmnet (cs_predict.R)                                                                           ***
. ********************************************************************************
.
. insheet using prostate.data, clear
(11 vars, 97 obs)

.
. gen ybin = lpsa > 2

.
. lassologit ybin lcavol-pgg45, lam(.2 .11 .1 0.05 0.01) savep lambdan
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.20000    1     0.69846    113.99735   0.0787  | Added lcavol
      |                                                         | _cons.
     2 |   2    0.11000    3     3.59675     99.74080   0.2292  | Added
      |                                                         | lweight
      |                                                         | gleason.
     3 |   4    0.05000    5    10.56586     90.27006   0.3403  | Added lbph
      |                                                         | svi.
     4 |   5    0.01000    8    18.32126     86.17997   0.4238  | Added age
      |                                                         | lcp pgg45.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat P = e(phat)

. mat P = P[97,1..5]

. mat G = ( 0.761871934040682,0.883722877193935,0.895110432984738,0.955542318252603,0.999505561515738)

. assert mreldif(P,G)<0.01

.
. lassologit ybin lcavol-pgg45, lam(.2 .11 .1 0.05 0.01) savep nocons lambdan
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.20000    2     0.25986    113.68946   0.0921  | Added lcavol
      |                                                         | gleason.
     2 |   2    0.11000    2     0.57932    102.08041   0.1876  | Added
      |                                                         | lweight.
      |                                                         | Removed
      |                                                         | gleason.
     3 |   4    0.05000    5     1.57115     96.27282   0.2764  | Added age
      |                                                         | lbph svi
      |                                                         | pgg45.
      |                                                         | Removed
      |                                                         | lweight.
     4 |   5    0.01000    8     4.49403     90.64428   0.3638  | Added
      |                                                         | lweight lcp
      |                                                         | gleason.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat P = e(phat)

. mat P = P[97,1..5]

. mat G = ( 0.761411339295924,0.883320216213757,0.893762132556822,0.956213536648691,0.999298395412146)

. assert mreldif(P,G)<0.01

.
. lassologit ybin lcavol-pgg45, lam(.2 .11 .1 0.05 0.01) savep nostd lambdan
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.20000    3     0.58709    113.58767   0.1153  | Added lcavol
      |                                                         | age pgg45
      |                                                         | _cons.
     2 |   2    0.11000    4     1.21286    102.96716   0.2193  | Added lbph.
     3 |   4    0.05000    3     1.51415     93.41464   0.2813  | Removed age.
     4 |   5    0.01000    8    15.75757     87.63212   0.4118  | Added
      |                                                         | lweight age
      |                                                         | svi lcp
      |                                                         | gleason.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat P = e(phat)

. mat P = P[97,1..5]

. mat G = ( 0.708638828605104,0.858851204259658,0.872566014019627,0.931492511316991,0.998846180327787)

. assert mreldif(P,G)<0.01

.
. lassologit ybin lcavol-pgg45, lam(.2 .11 .1 0.05 0.01) savep nostd nocons lambdan
Obtaining solution for 5 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
.....

  Knot|  ID    Lambda/n    s     L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1    0.20000    3     0.06870    112.79223   0.1131  | Added lcavol
      |                                                         | age pgg45.
     2 |   2    0.11000    4     0.50886    101.72070   0.2179  | Added lbph.
     3 |   5    0.01000    8     3.41422     91.81371   0.3541  | Added
      |                                                         | lweight svi
      |                                                         | lcp gleason.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat P = e(phat)

. mat P = P[97,1..5]

. mat G = ( 0.703648308982215,0.853973607193486,0.868497657957821,0.929886289492582,0.998267904285371)

. assert mreldif(P,G)<0.01

.
.
.
. ********************************************************************************
. *** comparison with mata predicted values                                                                        ***
. ********************************************************************************
.
.
. *** in-sample
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

. gen myholdout = _n<50

.
. lassologit v58 v1-v57, lambda(0.1) savep lambdan

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5412442      4.2194397
              v16 |       0.0569502      0.8984170
              v21 |       0.2448168      0.3940148
              v23 |       0.5126734      3.8072262
              v25 |      -0.0071134     -2.7490367
              v53 |       0.6310249      7.5984195
              v57 |       0.0000267      0.0011889
            _cons |      -0.8168528     -1.7667647
------------------+--------------------------------

. mat Phat1 = e(phat)

.
. svmat Phat1

.
. predict double Phat2 if e(sample), pr

.
. assert abs(Phat1 - Phat2)<10e-8

.
.
. *** in-sample (not on full sample)
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

. gen myholdout = _n<50

.
. lassologit v58 v1-v57 if _n<4000, lambda(0.1) savep lambdan
convergence not achieved
warning: post-logit did not converge after 100 iterations.

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.3346469      3.8281662
              v19 |       0.1093364      0.1855088
              v21 |       0.2019775      0.3285388
              v23 |       0.3357161      4.2536733
              v25 |      -0.0414092     -2.4138668
              v52 |       0.5888534      2.8057184
              v53 |       0.2882914      9.1192984
            _cons |      -0.7614305     -1.8296059
------------------+--------------------------------

. mat Phat1 = e(phat)

.
. svmat Phat1

.
. predict double Phat2 if e(sample), pr

.
. assert abs(Phat1 - Phat2)<10e-6  if !missing(Phat1)

.
.
. *** in-sample
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

. gen myholdout = _n<50

.
. lassologit v58 v1-v57, lambda(0.1) savep  holdout(myh)  lambdan

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v7 |       0.5467516      4.1570567
              v16 |       0.0485652      0.8595936
              v21 |       0.2489515      0.4009632
              v23 |       0.5225101      3.8591993
              v25 |      -0.0027273     -2.7525769
              v53 |       0.6483558      7.5757553
              v57 |       0.0000294      0.0012028
            _cons |      -0.8520893     -1.8036440
------------------+--------------------------------

. mat Phat1 = e(phat0)

.
. svmat Phat1

.
. predict double Phat2, pr

.
. assert abs(Phat1 - Phat2)<10e-8 if _n<50

.
end of do-file

.
. do "cs_weights.do"

. clear all

.
. cap cd "C:\Users\Achim.Ahrens\Dropbox\StataLasso\lassoLogit"

. cap cd "C:\Users\achim\Dropbox\StataLasso\lassoLogit"

. cap cd "C:\LocalStore\ecomes\Dropbox\StataLasso\lassoLogit"

. adopath + "`c(pwd)'"
  [1]  (BASE)      "/Applications/Stata 16/ado/base/"
  [2]  (SITE)      "/Applications/Stata 16/ado/site/"
  [3]              "."
  [4]  (PERSONAL)  "/Users/kahrens/Documents/Stata/ado/personal/"
  [5]  (PLUS)      "/Users/kahrens/Library/Application Support/Stata/ado/plus/"
  [6]  (OLDPLACE)  "~/ado/"
  [7]              "/Users/kahrens/Dropbox (PP)/StataLasso/Current"
  [8]              "/Users/kahrens/Dropbox (PP)/StataLasso/lassoLogit"

.
. which lassologit
./lassologit.ado
*! lassologit (v0.3)
*! part of lassopack v1.3.1
*! last edited: 15oct2019
*! authors: aa/ms/cbh

.
.
. ********************************************************************************
. ***  verify fweights                                                                                                             ***
. ********************************************************************************
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. // frequencies
. set seed 123

. gen freq = max(rpoisson(3),1)

.
. // estimate with fweights
. lassologit v58 v1-v57 [fw=freq]
Obtaining solution for 50 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50


  Knot|  ID     Lambda    s      L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1 2652.14886    0     0.43345  18856.83345   0.0000  | Added v21
      |                                                         | _cons.
     2 |   3 2197.68398    2     0.68101  18156.94054   0.0374  | Added v23.
     3 |   4 2000.54773    3     1.04108  17572.06374   0.0686  | Added v7.
     4 |   5 1821.09495    4     1.47848  17000.82094   0.0990  | Added v53.
     5 |   6 1657.73941    5     1.92357  16456.86737   0.1280  | Added v52.
     6 |   7 1509.03717    6     2.37585  15918.47486   0.1567  | Added v57.
     7 |   8 1373.67379    8     2.81688  15313.96430   0.1890  | Added v16
      |                                                         | v25.
     8 |   9 1250.45274   11     3.26479  14725.03387   0.2206  | Added v5 v19
      |                                                         | v56.
     9 |  10 1138.28485   13     3.74757  14148.00406   0.2515  | Added v8
      |                                                         | v17.
    10 |  11 1036.17863   14     4.27697  13593.87671   0.2811  | Added v24.
    11 |  12  943.23152   15     4.84130  13080.63162   0.3084  | Added v9.
    12 |  13  858.62193   19     5.42156  12616.34231   0.3336  | Added v6 v18
      |                                                         | v20 v26.
    13 |  15  711.49086   20     6.64149  11762.95437   0.3790  | Added v27.
    14 |  16  647.66883   22     7.22988  11385.42743   0.3993  | Added v22
      |                                                         | v37.
    15 |  17  589.57176   23     7.83815  11006.32589   0.4195  | Added v45.
    16 |  18  536.68610   25     8.43471  10654.66134   0.4385  | Added v42
      |                                                         | v46.
    17 |  21  404.82877   26    10.22168   9721.81359   0.4881  | Added v3.
    18 |  22  368.51489   27    10.82301   9458.26909   0.5022  | Added v33.
    19 |  26  253.04032   28    13.24214   8578.63303   0.5490  | Added v49.
    20 |  27  230.34214   33    13.91267   8402.35731   0.5590  | Added v4 v39
      |                                                         | v43 v44 v48.
    21 |  30  173.74985   34    15.99443   7907.31436   0.5854  | Added v47.
    22 |  31  158.16417   35    16.76628   7765.85178   0.5930  | Added v10.
    23 |  32  143.97655   38    17.55431   7635.81406   0.6004  | Added v2 v12
      |                                                         | v41.
    24 |  34  119.30513   39    19.14212   7383.84921   0.6139  | Added v35.
    25 |  35  108.60324   40    19.94348   7270.46716   0.6200  | Added v15.
    26 |  36   98.86133   42    20.80458   7165.44680   0.6259  | Added v29
      |                                                         | v51.
    27 |  38   81.92073   45    22.66782   6966.65317   0.6368  | Added v1 v36
      |                                                         | v54.
    28 |  39   74.57229   46    23.71637   6870.53825   0.6421  | Added v40.
    29 |  40   67.88302   47    24.79449   6781.41660   0.6469  | Added v31.
    30 |  43   51.20498   48    28.06065   6553.46675   0.6592  | Added v28.
    31 |  44   46.61180   49    29.20843   6490.01160   0.6627  | Added v38.
    32 |  45   42.43063   50    30.35391   6432.85656   0.6658  | Added v50.
    33 |  46   38.62453   51    31.50073   6381.29222   0.6687  | Added v30.
    34 |  48   32.00594   52    33.76718   6290.37496   0.6737  | Added v14.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat A = e(betas)

. mat LA = e(lambdas)

.
. // estimate with expanded data
. expand freq
(9,467 observations created)

. lassologit v58 v1-v57
Obtaining solution for 50 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50


  Knot|  ID     Lambda    s      L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   1 2652.14886    0     0.43345  18856.83345   0.0000  | Added v21
      |                                                         | _cons.
     2 |   3 2197.68398    2     0.68101  18156.94054   0.0374  | Added v23.
     3 |   4 2000.54773    3     1.04108  17572.06374   0.0686  | Added v7.
     4 |   5 1821.09495    4     1.47848  17000.82094   0.0990  | Added v53.
     5 |   6 1657.73941    5     1.92357  16456.86737   0.1280  | Added v52.
     6 |   7 1509.03717    6     2.37585  15918.47486   0.1567  | Added v57.
     7 |   8 1373.67379    8     2.81688  15313.96430   0.1890  | Added v16
      |                                                         | v25.
     8 |   9 1250.45274   11     3.26479  14725.03387   0.2206  | Added v5 v19
      |                                                         | v56.
     9 |  10 1138.28485   13     3.74757  14148.00406   0.2515  | Added v8
      |                                                         | v17.
    10 |  11 1036.17863   14     4.27697  13593.87671   0.2811  | Added v24.
    11 |  12  943.23152   15     4.84130  13080.63162   0.3084  | Added v9.
    12 |  13  858.62193   19     5.42156  12616.34231   0.3336  | Added v6 v18
      |                                                         | v20 v26.
    13 |  15  711.49086   20     6.64149  11762.95437   0.3790  | Added v27.
    14 |  16  647.66883   22     7.22988  11385.42743   0.3993  | Added v22
      |                                                         | v37.
    15 |  17  589.57176   23     7.83815  11006.32589   0.4195  | Added v45.
    16 |  18  536.68610   25     8.43471  10654.66134   0.4385  | Added v42
      |                                                         | v46.
    17 |  21  404.82877   26    10.22168   9721.81359   0.4881  | Added v3.
    18 |  22  368.51489   27    10.82301   9458.26909   0.5022  | Added v33.
    19 |  26  253.04032   28    13.24214   8578.63303   0.5490  | Added v49.
    20 |  27  230.34214   33    13.91267   8402.35731   0.5590  | Added v4 v39
      |                                                         | v43 v44 v48.
    21 |  30  173.74985   34    15.99443   7907.31436   0.5854  | Added v47.
    22 |  31  158.16417   35    16.76628   7765.85178   0.5930  | Added v10.
    23 |  32  143.97655   38    17.55431   7635.81406   0.6004  | Added v2 v12
      |                                                         | v41.
    24 |  34  119.30513   39    19.14212   7383.84921   0.6139  | Added v35.
    25 |  35  108.60324   40    19.94348   7270.46716   0.6200  | Added v15.
    26 |  36   98.86133   42    20.80458   7165.44680   0.6259  | Added v29
      |                                                         | v51.
    27 |  38   81.92073   45    22.66782   6966.65317   0.6368  | Added v1 v36
      |                                                         | v54.
    28 |  39   74.57229   46    23.71637   6870.53825   0.6421  | Added v40.
    29 |  40   67.88302   47    24.79449   6781.41660   0.6469  | Added v31.
    30 |  43   51.20498   48    28.06065   6553.46675   0.6592  | Added v28.
    31 |  44   46.61180   49    29.20843   6490.01160   0.6627  | Added v38.
    32 |  45   42.43063   50    30.35391   6432.85656   0.6658  | Added v50.
    33 |  46   38.62453   51    31.50073   6381.29222   0.6687  | Added v30.
    34 |  48   32.00594   52    33.76718   6290.37496   0.6737  | Added v14.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat B = e(betas)

. mat LB = e(lambdas)

.
. assert mreldif(LA,LB)<1e-10

. assert mreldif(A,B)<1e-10

.
. ********************************************************************************
. ***  verify fweights (without constant)                                                                          ***
. ********************************************************************************
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. // frequencies
. set seed 123

. gen freq = max(rpoisson(3),1)

.
. // estimate with fweights
. lassologit v58 v1-v57 [fw=freq], nocons
Obtaining solution for 50 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50


  Knot|  ID     Lambda    s      L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   2 2049.62463    1     0.03225  19279.50542  -0.0223  | Added v25.
     2 |   3 1865.76957    2     0.07211  19071.40676  -0.0111  | Added v23.
     3 |   4 1698.40664    4     0.29051  18652.22506   0.0114  | Added v7
      |                                                         | v26.
     4 |   5 1546.05647    7     0.57671  18180.99515   0.0368  | Added v27
      |                                                         | v37 v53.
     5 |   6 1407.37239    8     0.95088  17573.51667   0.0691  | Added v21.
     6 |   7 1281.12852   10     1.41016  16986.00749   0.1006  | Added v45
      |                                                         | v50.
     7 |   8 1166.20896   11     1.89052  16389.79594   0.1323  | Added v46.
     8 |   9 1061.59789   12     2.38226  15801.84364   0.1636  | Added v52.
     9 |  10  966.37062   15     2.89222  15230.45986   0.1944  | Added v16
      |                                                         | v42 v56.
    10 |  11  879.68542   17     3.41388  14657.05059   0.2250  | Added v24
      |                                                         | v33.
    11 |  12  800.77603   20     4.00469  14083.26229   0.2559  | Added v12
      |                                                         | v17 v20.
    12 |  13  728.94496   21     4.61784  13535.79374   0.2851  | Added v8.
    13 |  15  604.03498   22     5.86677  12568.67828   0.3365  | Added v44.
    14 |  16  549.85194   23     6.50409  12137.78363   0.3595  | Added v57.
    15 |  17  500.52922   25     7.17326  11722.46514   0.3818  | Added v2
      |                                                         | v48.
    16 |  18  455.63084   30     7.87033  11343.40366   0.4025  | Added v5 v9
      |                                                         | v11 v39 v49.
    17 |  19  414.75992   31     8.62771  10973.62057   0.4223  | Added v43.
    18 |  20  377.55520   32     9.39145  10632.80497   0.4405  | Added v18.
    19 |  21  343.68781   33    10.21684  10316.54898   0.4574  | Added v51.
    20 |  22  312.85839   36    11.09671  10028.06392   0.4731  | Added v22
      |                                                         | v35 v47.
    21 |  25  235.99284   38    13.95656   9254.93660   0.5144  | Added v19
      |                                                         | v41.
    22 |  28  178.01223   40    16.87948   8633.72067   0.5476  | Added v6
      |                                                         | v15.
    23 |  29  162.04421   43    17.88557   8461.46998   0.5572  | Added v4 v29
      |                                                         | v31.
    24 |  30  147.50855   44    18.91227   8294.55116   0.5661  | Added v1.
    25 |  33  111.26747   45    22.08643   7853.19073   0.5897  | Added v40.
    26 |  34  101.28657   47    23.20359   7727.30505   0.5966  | Added v13
      |                                                         | v30.
    27 |  37   76.40168   48    26.60429   7391.98031   0.6146  | Added v38.
    28 |  39   63.30970   50    28.90082   7213.81854   0.6243  | Added v14
      |                                                         | v54.
    29 |  42   47.75527   51    32.35117   6993.93711   0.6361  | Added v28.
    30 |  44   39.57206   52    34.70622   6872.62826   0.6426  | Added v3.
    31 |  45   36.02237   53    35.85737   6820.09430   0.6456  | Added v36.
    32 |  49   24.73472   54    40.48523   6632.29067   0.6557  | Added v34.
    33 |  50   22.51597   55    41.68802   6594.27081   0.6578  | Added v55.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat A = e(betas)

. mat LA = e(lambdas)

.
. // estimate with expanded data
. expand freq
(9,467 observations created)

. lassologit v58 v1-v57, nocons
Obtaining solution for 50 lambdas
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50


  Knot|  ID     Lambda    s      L1-Norm     EBIC     Pseudo-R2 | Entered/removed
------+---------------------------------------------------------+----------------
     1 |   2 2049.62463    1     0.03225  19279.50542  -0.0223  | Added v25.
     2 |   3 1865.76957    2     0.07211  19071.40676  -0.0111  | Added v23.
     3 |   4 1698.40664    4     0.29051  18652.22506   0.0114  | Added v7
      |                                                         | v26.
     4 |   5 1546.05647    7     0.57671  18180.99515   0.0368  | Added v27
      |                                                         | v37 v53.
     5 |   6 1407.37239    8     0.95088  17573.51667   0.0691  | Added v21.
     6 |   7 1281.12852   10     1.41016  16986.00749   0.1006  | Added v45
      |                                                         | v50.
     7 |   8 1166.20896   11     1.89052  16389.79594   0.1323  | Added v46.
     8 |   9 1061.59789   12     2.38226  15801.84364   0.1636  | Added v52.
     9 |  10  966.37062   15     2.89222  15230.45986   0.1944  | Added v16
      |                                                         | v42 v56.
    10 |  11  879.68542   17     3.41388  14657.05059   0.2250  | Added v24
      |                                                         | v33.
    11 |  12  800.77603   20     4.00469  14083.26229   0.2559  | Added v12
      |                                                         | v17 v20.
    12 |  13  728.94496   21     4.61784  13535.79374   0.2851  | Added v8.
    13 |  15  604.03498   22     5.86677  12568.67828   0.3365  | Added v44.
    14 |  16  549.85194   23     6.50409  12137.78363   0.3595  | Added v57.
    15 |  17  500.52922   25     7.17326  11722.46514   0.3818  | Added v2
      |                                                         | v48.
    16 |  18  455.63084   30     7.87033  11343.40366   0.4025  | Added v5 v9
      |                                                         | v11 v39 v49.
    17 |  19  414.75992   31     8.62771  10973.62057   0.4223  | Added v43.
    18 |  20  377.55520   32     9.39145  10632.80497   0.4405  | Added v18.
    19 |  21  343.68781   33    10.21684  10316.54898   0.4574  | Added v51.
    20 |  22  312.85839   36    11.09671  10028.06392   0.4731  | Added v22
      |                                                         | v35 v47.
    21 |  25  235.99284   38    13.95656   9254.93660   0.5144  | Added v19
      |                                                         | v41.
    22 |  28  178.01223   40    16.87948   8633.72067   0.5476  | Added v6
      |                                                         | v15.
    23 |  29  162.04421   43    17.88557   8461.46998   0.5572  | Added v4 v29
      |                                                         | v31.
    24 |  30  147.50855   44    18.91227   8294.55116   0.5661  | Added v1.
    25 |  33  111.26747   45    22.08643   7853.19073   0.5897  | Added v40.
    26 |  34  101.28657   47    23.20359   7727.30505   0.5966  | Added v13
      |                                                         | v30.
    27 |  37   76.40168   48    26.60429   7391.98031   0.6146  | Added v38.
    28 |  39   63.30970   50    28.90082   7213.81854   0.6243  | Added v14
      |                                                         | v54.
    29 |  42   47.75527   51    32.35117   6993.93711   0.6361  | Added v28.
    30 |  44   39.57206   52    34.70622   6872.62826   0.6426  | Added v3.
    31 |  45   36.02237   53    35.85737   6820.09430   0.6456  | Added v36.
    32 |  49   24.73472   54    40.48523   6632.29067   0.6557  | Added v34.
    33 |  50   22.51597   55    41.68802   6594.27081   0.6578  | Added v55.
Use 'long' option for full output.
Type e.g. 'lassologit, lic(ebic)' to run the model selected by EBIC.

. mat B = e(betas)

. mat LB = e(lambdas)

.
. assert mreldif(LA,LB)<1e-10

. assert mreldif(A,B)<1e-10

.
. ********************************************************************************
. ***  verify aweights                                                                                                             ***
. ********************************************************************************
.
. insheet using "spam.data", clear delim(" ")
(58 vars, 4,601 obs)

.
. // aweights / pweights
. // check by setting lambda very small
. // => lasso logit and post-logit should be similar
. set seed 123

. gen double wtvar=runiform()

. lassologit v58 v1-v10 [aw=wtvar], l(0.000001) tolopt(1e-15) tolzero(1e-15)
(sum of wgt is     2.3211e+03)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |       0.7744671      0.7744671
               v2 |      -0.0626458     -0.0626458
               v3 |       0.6246121      0.6246121
               v4 |       3.1963970      3.1963963
               v5 |       0.6076114      0.6076114
               v6 |       1.2341420      1.2341420
               v7 |       5.5779583      5.5779583
               v8 |       1.8396889      1.8396889
               v9 |       1.8146473      1.8146473
              v10 |       0.2954549      0.2954549
            _cons |      -1.7590782     -1.7590782
------------------+--------------------------------

. mat bL=e(beta_dense)

. mat bPL=e(beta_post_dense)

. assert mreldif(bL,bPL)<0.002

.
. // confirm pw and aw are equivalent
. lassologit v58 v1-v5 [aw=wtvar], l(0.05)
(sum of wgt is     2.3211e+03)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |       0.9796408      0.9799240
               v2 |      -0.0345078     -0.0345423
               v3 |       0.7029451      0.7030173
               v4 |       2.9951618      3.0512232
               v5 |       0.8908860      0.8910039
            _cons |      -1.0201645     -1.0203550
------------------+--------------------------------

. mat bL=e(beta_dense)

. mat bPL=e(beta_post_dense)

. lassologit v58 v1-v5 [pw=wtvar], l(0.05)
(sum of wgt is     2.3211e+03)

------------------+--------------------------------
         Selected |       Logistic       Post
                  |       Lasso          logit
------------------+--------------------------------
               v1 |       0.9796408      0.9799240
               v2 |      -0.0345078     -0.0345423
               v3 |       0.7029451      0.7030173
               v4 |       2.9951618      3.0512232
               v5 |       0.8908860      0.8910039
            _cons |      -1.0201645     -1.0203550
------------------+--------------------------------

. assert mreldif(bL,e(beta_dense))<1e-10

. assert mreldif(bPL,e(beta_post_dense))<1e-10

.
.
end of do-file

.
. cap log close