-------------
      name:  <unnamed>
       log:  C:\Users\ecomes\Documents\GitHub\lassopack\lassopack_v141incomplete\cs_cvlasso.smcl
  log type:  smcl
 opened on:  27 Sep 2020, 20:21:45
r; t=0.02 20:21:45

. about

Stata/SE 16.1 for Windows (64-bit x86-64)
Revision 30 Jun 2020
Copyright 1985-2019 StataCorp LLC

Total physical memory:       16.00 GB
Available physical memory:    5.19 GB

Stata license: 5-user network perpetual
Serial number: 401606228165
  Licensed to: Mark Schaffer
               Heriot-Watt University
r; t=0.01 20:21:45

. which cvlasso
.\cvlasso.ado
*! cvlasso 1.0.11 27sept2020
*! lassopack package 1.4.1
*! authors aa/ms
r; t=0.00 20:21:45

. which lasso2
.\lasso2.ado
*! lasso2 1.0.12 27sept2020
*! lassopack package 1.4.1
*! authors aa/ms
r; t=0.00 20:21:45

. which lasso2_p
.\lasso2_p.ado
*! lasso2_p 1.0.06 14oct2019
*! lassopack package 1.4
*! authors aa/ms
r; t=0.00 20:21:45

. which lassoutils
.\lassoutils.ado
*! lassoutils 1.2.03 27sept2020
*! lassopack package 1.4.1
*! authors aa/cbh/ms
r; t=0.01 20:21:45

.
. * data source
. * global prostate prostate.data
. global prostate https://web.stanford.edu/~hastie/ElemStatLearn/datasets/prostate.data
r; t=0.00 20:21:45

.
. * program to compare two matrices in terms of avg abs deviation
. cap program drop comparemat
r; t=0.00 20:21:45

. program define comparemat , rclass
  1.         syntax anything [, tol(real 10e-3)]
  2.         local A         : word 1 of `0'
  3.         local B         : word 2 of `0'
  4.         tempname Amat Bmat
  5.         mat `Amat' = `A'
  6.         mat `Bmat' = `B'
  7.         local diff=mreldif(`Amat',`Bmat')
  8.         di as text "mreldif=`diff'. tolerance = `tol'"
  9.         mat list `Amat'
 10.         mat list `Bmat'
 11.         return scalar mreldif = `diff'
 12.         assert `diff'<`tol'
 13. end
r; t=0.00 20:21:45

.
.
. set seed 123456
r; t=0.00 20:21:45

.
. ********************************************************************************
. *** compare with glmnet                                                                  ***
. ********************************************************************************
.
. * load example data
. insheet using "$prostate", tab clear
(11 vars, 97 obs)
r; t=1.50 20:21:47

. drop if _n==97 // to ensure same size for each fold
(1 observation deleted)
r; t=0.00 20:21:47

.
. global model lpsa lcavol lweight age lbph svi lcp gleason pgg45
r; t=0.00 20:21:47

.
. * generate fold variable
. gen myfid = 1 if _n<=32
(64 missing values generated)
r; t=0.00 20:21:47

. replace myfid = 2 if _n>32 & _n<=64
(32 real changes made)
r; t=0.00 20:21:47

. replace myfid = 3 if _n>64
(32 real changes made)
r; t=0.00 20:21:47

.
. cvlasso $model, foldvar(myfid) lambda(150 15 1.5)
Use user-specified fold variable.

K-fold cross-validation with 3 folds. Elastic net with alpha=1.
Fold 1 2 3
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|            150      2.3865184      1.1559279
         2|             15      1.4635023      .42894674  *^
         3|            1.5       1.485229      .36948736
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=0.77 20:21:48

. mat L = e(mmspe)
r; t=0.00 20:21:48

. /*
> c<-cv.glmnet(X,y,foldid=fid,lambda=c(150, 15, 1.5)/(2*n),keep=TRUE, intercept=TRUE,standardize=TRUE)
> > c$cvm # mean-squared prediction error
> [1] 2.386518 1.463497 1.484953
> > var(predict(c,newx=X,s="lambda.min"))
>          1
> 1 0.608541
> */
. mat G = ( 2.38651835211576 \ 1.46349718052732 \ 1.48495268875459 )
r; t=0.00 20:21:48

. comparemat L G // compare coeffs
mreldif=.0001112103968545. tolerance = .01

__000000[3,1]
           r1
c1  2.3865184
c2  1.4635023
c3   1.485229

__000001[3,1]
           c1
r1  2.3865184
r2  1.4634972
r3  1.4849527
r; t=0.04 20:21:48

. cap drop xb
r; t=0.00 20:21:48

. predict double xb, lopt
Estimate lasso with lambda=15 (lopt).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.4705447      0.4939937
          lweight |       0.4738822      0.5463838
             lbph |       0.0222266      0.0675109
              svi |       0.4597209      0.5816563
            pgg45 |       0.0021287      0.0033429
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |      -0.0467006     -0.4001276
------------------+--------------------------------
No xb or residuals options specified. Assume xb (fitted values).
Use e(b) from previous lasso2 estimation (lambda=15).
r; t=0.10 20:21:48

. sum xb

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          xb |         96    2.446048    .7801003   .9116189   4.111986
r; t=0.00 20:21:48

. assert reldif(0.608541,r(Var))<0.001 // compare predicted values
r; t=0.00 20:21:48

.
.
. cvlasso $model, foldvar(myfid) lambda(150 15 1.5) prestd
Use user-specified fold variable.

K-fold cross-validation with 3 folds. Elastic net with alpha=1.
Fold 1 2 3
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|            150      2.3865184      1.1559279
         2|             15      1.4635023      .42894674  *^
         3|            1.5       1.485229      .36948736
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=0.03 20:21:48

. mat L = e(mmspe)
r; t=0.00 20:21:48

. /*
> c<-cv.glmnet(X,y,foldid=fid,lambda=c(150, 15, 1.5)/(2*n),keep=TRUE, intercept=TRUE,standardize=TRUE)
> > c$cvm # mean-squared prediction error
> [1] 2.386518 1.463497 1.484953
> > var(predict(c,newx=X,s="lambda.min"))
>          1
> 1 0.608541
> */
. mat G = ( 2.38651835211576 \ 1.46349718052732 \ 1.48495268875459 )
r; t=0.00 20:21:48

. comparemat L G // compare coeffs
mreldif=.0001112103968545. tolerance = .01

__000000[3,1]
           r1
c1  2.3865184
c2  1.4635023
c3   1.485229

__000001[3,1]
           c1
r1  2.3865184
r2  1.4634972
r3  1.4849527
r; t=0.00 20:21:48

. cap drop xb
r; t=0.00 20:21:48

. predict double xb, lopt
Estimate lasso with lambda=15 (lopt).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.4705447      0.4939937
          lweight |       0.4738822      0.5463838
             lbph |       0.0222266      0.0675109
              svi |       0.4597209      0.5816563
            pgg45 |       0.0021287      0.0033429
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |      -0.0467006     -0.4001276
------------------+--------------------------------
No xb or residuals options specified. Assume xb (fitted values).
Use e(b) from previous lasso2 estimation (lambda=15).
r; t=1.44 20:21:49

. sum xb

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          xb |         96    2.446048    .7801003   .9116189   4.111986
r; t=0.00 20:21:49

. assert reldif(0.608541,r(Var))<0.001 // compare predicted values
r; t=0.00 20:21:49

.
.
. cvlasso $model, foldvar(myfid) lambda(150 15 1.5) unitload
Use user-specified fold variable.

K-fold cross-validation with 3 folds. Elastic net with alpha=1.
Fold 1 2 3
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|            150      2.1036977      .86238904
         2|             15      1.4298598      .47710985  ^
         3|            1.5      1.4275375      .35365915  *
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lopt is at the limit of the lambda range.
r; t=0.03 20:21:49

. mat L = e(mmspe)
r; t=0.00 20:21:49

. /*
> > # cross-validation with intercept & standardisation
> > c<-cv.glmnet(X,y,foldid=fid,lambda=c(150, 15, 1.5)/(2*n),keep=TRUE, intercept=TRUE,standardize=FALSE)
> > c$cvm # mean-squared prediction error
> [1] 2.103697 1.429934 1.427561
> > var(predict(c,newx=X,s="lambda.min"))
>           1
> 1 0.7840688
> */
. mat G = ( 2.10369705382686 \ 1.42993421234064 \ 1.42756055333919 )
r; t=0.00 20:21:49

. comparemat L G // compare coeffs
mreldif=.0000306155184697. tolerance = .01

__000000[3,1]
           r1
c1  2.1036977
c2  1.4298598
c3  1.4275375

__000001[3,1]
           c1
r1  2.1036971
r2  1.4299342
r3  1.4275606
r; t=0.00 20:21:49

. cap drop xb
r; t=0.00 20:21:49

. predict double xb, lopt
Estimate lasso with lambda=1.5 (lopt).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.5568426      0.5653571
          lweight |       0.5707438      0.6139211
              age |      -0.0208973     -0.0224946
             lbph |       0.0911393      0.0935981
              svi |       0.6204808      0.7149700
              lcp |      -0.1126800     -0.1447125
            pgg45 |       0.0068648      0.0071245
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |       0.6415930      0.5426554
------------------+--------------------------------
No xb or residuals options specified. Assume xb (fitted values).
Use e(b) from previous lasso2 estimation (lambda=1.5).
r; t=0.02 20:21:49

. sum xb

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          xb |         96    2.446048    .8854875    .513909   4.598263
r; t=0.00 20:21:49

. assert reldif(0.7840688,r(Var))<0.001 // compare predicted values
r; t=0.00 20:21:49

.
.
. cvlasso $model, foldvar(myfid) lambda(150 15 1.5) nocons unitload
Use user-specified fold variable.

K-fold cross-validation with 3 folds. Elastic net with alpha=1.
Fold 1 2 3
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|            150      1.9998833      .72964224
         2|             15        1.26607      .39073554  ^
         3|            1.5       1.246129      .28903645  *
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lopt is at the limit of the lambda range.
r; t=0.14 20:21:49

. mat L = e(mmspe)
r; t=0.00 20:21:49

. /*
> > c<-cv.glmnet(X,y,foldid=fid,lambda=c(150, 15, 1.5)/(2*n),keep=TRUE, intercept=FALSE,standardize=FALSE)
> > c$cvm # mean-squared prediction error
> [1] 1.999806 1.266384 1.246805
> > var(predict(c,newx=X,s="lambda.min"))
>           1
> 1 0.7919695
> */
. mat G = ( 1.99980614859113 \ 1.26638436668758 \ 1.24680539174676 )
r; t=0.00 20:21:49

. comparemat L G // compare coeffs
mreldif=.0003010647418424. tolerance = .01

__000000[3,1]
           r1
c1  1.9998833
c2    1.26607
c3   1.246129

__000001[3,1]
           c1
r1  1.9998061
r2  1.2663844
r3  1.2468054
r; t=0.00 20:21:49

. cap drop xb
r; t=0.00 20:21:49

. predict double xb, lopt
Estimate lasso with lambda=1.5 (lopt).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.5473610      0.5569029
          lweight |       0.6258035      0.6453516
              age |      -0.0188110     -0.0217852
             lbph |       0.0801178      0.0880196
              svi |       0.6260775      0.7250462
              lcp |      -0.1142476     -0.1460891
          gleason |       0.0505847      0.0620963
            pgg45 |       0.0059407      0.0060062
------------------+--------------------------------
No xb or residuals options specified. Assume xb (fitted values).
Use e(b) from previous lasso2 estimation (lambda=1.5).
r; t=0.03 20:21:49

. sum xb

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          xb |         96    2.443933    .8905195   .5327895   4.561406
r; t=0.00 20:21:49

. assert reldif(0.7919695,r(Var))<0.001 // compare predicted values
r; t=0.00 20:21:49

.
. cvlasso $model, foldvar(myfid) lambda(150 15 1.5) nocons
Use user-specified fold variable.

K-fold cross-validation with 3 folds. Elastic net with alpha=1.
Fold 1 2 3
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|            150      1.9069161      .92525083
         2|             15      1.2339936      .35347077  *^
         3|            1.5       1.309495       .3270498
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=0.15 20:21:49

. mat L = e(mmspe)
r; t=0.00 20:21:49

. /*
> c<-cv.glmnet(X,y,foldid=fid,lambda=c(150, 15, 1.5)/(2*n),keep=TRUE, intercept=FALSE,standardize=TRUE)
> > c$cvm # mean-squared prediction error
> [1] 1.906526 1.232220 1.310531
> > var(predict(c,newx=X,s="lambda.min"))
>           1
> 1 0.6062457
> */
. mat G = ( 1.90652583524832 \ 1.23222044017428 \ 1.31053116174191 )
r; t=0.00 20:21:49

. comparemat L G // compare coeffs
mreldif=.0007943382600103. tolerance = .01

__000000[3,1]
           r1
c1  1.9069161
c2  1.2339936
c3   1.309495

__000001[3,1]
           c1
r1  1.9065258
r2  1.2322204
r3  1.3105312
r; t=0.00 20:21:49

. cap drop xb
r; t=0.00 20:21:49

. predict double xb, lopt
Estimate lasso with lambda=15 (lopt).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.4712765      0.5002634
          lweight |       0.4608978      0.4351342
             lbph |       0.0239597      0.0823598
              svi |       0.4613426      0.5955516
            pgg45 |       0.0021037      0.0031282
------------------+--------------------------------
No xb or residuals options specified. Assume xb (fitted values).
Use e(b) from previous lasso2 estimation (lambda=15).
r; t=0.02 20:21:49

. sum xb

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          xb |         96    2.446541    .7785216   .9124108     4.1091
r; t=0.00 20:21:49

. assert reldif(0.6062457,r(Var))<0.001 // compare predicted values
r; t=0.00 20:21:49

.
. cvlasso $model, foldvar(myfid) lambda(150 15 1.5) nocons prestd
Use user-specified fold variable.

K-fold cross-validation with 3 folds. Elastic net with alpha=1.
Fold 1 2 3
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|            150      1.9069161      .92525083
         2|             15      1.2339936      .35347077  *^
         3|            1.5       1.309495       .3270498
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=0.15 20:21:50

. mat L = e(mmspe)
r; t=0.00 20:21:50

. /*
> c<-cv.glmnet(X,y,foldid=fid,lambda=c(150, 15, 1.5)/(2*n),keep=TRUE, intercept=FALSE,standardize=TRUE)
> > c$cvm # mean-squared prediction error
> [1] 1.906526 1.232220 1.310531
> > var(predict(c,newx=X,s="lambda.min"))
>           1
> 1 0.6062457
> */
. mat G = ( 1.90652583524832 \ 1.23222044017428 \ 1.31053116174191 )
r; t=0.00 20:21:50

. comparemat L G // compare coeffs
mreldif=.0007943382600105. tolerance = .01

__000000[3,1]
           r1
c1  1.9069161
c2  1.2339936
c3   1.309495

__000001[3,1]
           c1
r1  1.9065258
r2  1.2322204
r3  1.3105312
r; t=0.00 20:21:50

. cap drop xb
r; t=0.00 20:21:50

. predict double xb, lopt
Estimate lasso with lambda=15 (lopt).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.4712765      0.5002634
          lweight |       0.4608978      0.4351342
             lbph |       0.0239597      0.0823598
              svi |       0.4613426      0.5955516
            pgg45 |       0.0021037      0.0031282
------------------+--------------------------------
No xb or residuals options specified. Assume xb (fitted values).
Use e(b) from previous lasso2 estimation (lambda=15).
r; t=0.02 20:21:50

. sum xb

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
          xb |         96    2.446541    .7785216   .9124108     4.1091
r; t=0.00 20:21:50

. assert reldif(0.6062457,r(Var))<0.001 // compare predicted values
r; t=0.00 20:21:50

.
.
. ********************************************************************************
. *** validate                                                        ***
. ********************************************************************************
.
. * load example data
. insheet using "$prostate", tab clear
(11 vars, 97 obs)
r; t=0.18 20:21:50

.
. global model lpsa lcavol lweight age lbph svi lcp gleason pgg45
r; t=0.00 20:21:50

. gen sample = _n<70
r; t=0.00 20:21:50

.
. foreach type of newlist lopt lse {
  2.
. local type lse
  3.
. // check that right beta is used for predict
. // also validates that "if" works
. cvlasso $model if sample
  4. local mylopt = e(`type')
  5. cap drop myxb
  6. predict double myxb if !sample, xb `type' postres
  7. mat A = e(b)
  8.
. lasso2 $model if sample, lambda(`mylopt')
  9. cap drop myxb2
 10. predict double myxb2 if !sample, xb
 11. mat B = e(b)
 12.
. comparemat A B
 13. assert myxb2==myxb
 14.
. // and now with alpha list
. // use lglmnet option
. cvlasso $model if sample, alpha(0 0.3 0.7 1) lglmnet
 15. local mylopt = e(`type')
 16. local myalpha = e(alphamin)
 17. cap drop myr
 18. predict double myr if !sample, r `type' postres
 19. mat A = e(b)
 20.
. lasso2 $model if sample, lambda(`mylopt') alpha(`myalpha') lglmnet
 21. cap drop myr2
 22. predict double myr2 if !sample, r
 23. mat B = e(b)
 24.
. comparemat A B
 25. assert myr2==myr
 26.
. }

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|       64.86388      .70214335      .13668767
         2|      59.101552      .68166758      .13770442
         3|      53.851133      .65032545      .13589084
         4|      49.067147      .61368184      .12902249
         5|      44.708157      .57648569      .11951189
         6|      40.736407       .5455564      .11125054
         7|      37.117497      .52022373      .10413738
         8|      33.820081      .49994965      .09808444
         9|      30.815598      .48394209      .09299888
        10|      28.078025       .4715922      .08866583  ^
        11|      25.583651      .46159647      .08503773
        12|       23.31087      .45319845       .0819249
        13|      21.239997      .44655158      .07921285
        14|      19.353094      .43989318      .07690231
        15|      17.633818      .43416143      .07503205
        16|      16.067278      .42831327      .07332298
        17|      14.639906      .42328622      .07186312
        18|      13.339337      .41909404      .07059609
        19|      12.154307      .41541784      .06940436
        20|      11.074552      .41239688      .06842274
        21|      10.090719      .41115051      .06762829  *
        22|      9.1942875      .41125524      .06734084
        23|      8.3774923      .41189673      .06726297
        24|       7.633259      .41299996      .06716497
        25|      6.9551413      .41535333      .06772844
        26|      6.3372657      .41747426      .06851425
        27|      5.7742805      .41770086      .06978754
        28|      5.2613093      .41811876      .07107378
        29|      4.7939091      .41867378      .07229779
        30|      4.3680314      .41856902      .07315811
        31|      3.9799876      .41856329      .07409234
        32|      3.6264164        .418418      .07512313
        33|      3.3042556      .41815181       .0761924
        34|      3.0107146      .41800644      .07722359
        35|       2.743251      .41780862      .07813846
        36|      2.4995482      .41776606      .07897215
        37|      2.2774952      .41784915      .07973505
        38|      2.0751688       .4178434       .0803494
        39|      1.8908165      .41783315      .08086973
        40|      1.7228416       .4177931      .08133498
        41|      1.5697891      .41780825      .08175923
        42|      1.4303334       .4178703      .08214655
        43|      1.3032665      .41796691      .08250007
        44|      1.1874879      .41808819       .0828227
        45|      1.0819947      .41822631      .08311707
        46|      .98587331      .41837509      .08338564
        47|      .89829104      .41872946      .08363953
        48|      .81848934      .41907617      .08387238
        49|        .745777      .41940754      .08408564
        50|      .67952423      .41972231      .08428089
        51|      .61915717      .42001978      .08445959
        52|      .56415295      .42029967      .08462309
        53|      .51403516      .42056204      .08477263
        54|      .46836969       .4208072      .08490936
        55|      .42676102      .42103565      .08503435
        56|      .38884875      .42124801      .08514857
        57|       .3543045      .42144499      .08525293
        58|      .32282906      .42162738      .08534826
        59|      .29414982      .42179596      .08543531
        60|      .26801836      .42195157      .08551481
        61|      .24420835      .42209501      .08558737
        62|      .22251355      .42222708      .08565361
        63|      .20274606      .42234856      .08571407
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Estimate lasso with lambda=28.078 (lse).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.2177045      0.3782994
          lweight |       0.4397825      0.8391637
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |       0.1812277     -1.3919237
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=28.07802540248).
(69 missing values generated)

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.2177045      0.3782994
          lweight |       0.4397825      0.8391637
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |       0.1812277     -1.3919237
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=28.07802540248).
(69 missing values generated)
mreldif=0. tolerance = .01

__000000[1,3]
       lcavol    lweight      _cons
y1  .21770447  .43978251  .18122774

__000001[1,3]
       lcavol    lweight      _cons
y1  .21770447  .43978251  .18122774

K-fold cross-validation with 10 folds. Elastic net with alpha=0.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812      .41012597      .06401609  ^
         2|      .42827212      .40728618      .06307755
         3|       .3902256      .40470048      .06225597
         4|      .35555903      .40236398      .06155117
         5|      .32397215      .40027036      .06096131
         6|      .29519136      .39841194      .06048296
         7|      .26896737      .39677969      .06011112
         8|      .24507305      .39536326      .05983949
         9|      .22330144      .39415121      .05966063
        10|      .20346395      .39313106      .05956626
        11|      .18538878      .39228957      .05954754
        12|      .16891935       .3916129      .05959536
        13|      .15391302      .39108687      .05970059
        14|      .14023981      .39069715      .05985432
        15|      .12778129      .39042948      .06004803
        16|      .11642955       .3902699      .06027379
        17|      .10608627      .39020487      .06052428  *
        18|      .09666186       .3902215      .06079293
        19|      .08807469       .3903076       .0610739
        20|      .08025038      .39045184      .06136209
        21|      .07312115      .39064375      .06165314
        22|      .06662527      .39087384      .06194337
        23|      .06070647      .39113356      .06222972
        24|      .05531347      .39141529      .06250972
        25|      .05039957      .39171237       .0627814
        26|      .04592222      .39201899      .06304327
        27|      .04184261       .3923302      .06329421
        28|      .03812543      .39264181      .06353346
        29|      .03473847      .39295034      .06376053
        30|       .0316524      .39325295      .06397518
        31|      .02884049      .39354738      .06417738
        32|      .02627838      .39383186      .06436723
        33|      .02394388      .39410506      .06454499
        34|      .02181677      .39436605        .064711
        35|      .01987863      .39461421      .06486568
        36|      .01811267      .39484918      .06500951
        37|      .01650359      .39507085      .06514299
        38|      .01503746      .39527928      .06526666
        39|      .01370157      .39547467      .06538108
        40|      .01248436      .39565737      .06548677
        41|      .01137528      .39582777       .0655843
        42|      .01036473      .39598637      .06567418
        43|      .00944396       .3961337      .06575692
        44|      .00860498      .39627031      .06583304
        45|      .00784054      .39639678      .06590299
        46|      .00714401      .39651369      .06596722
        47|      .00650936      .39662164      .06602617
        48|      .00593108      .39672117      .06608023
        49|      .00540418      .39681286      .06612978
        50|      .00492409      .39689723      .06617517
        51|      .00448665      .39697481      .06621673
        52|      .00408806      .39704608      .06625476
        53|      .00372489       .3971115      .06628956
        54|      .00339398      .39717151      .06632139
        55|      .00309247      .39722654      .06635048
        56|      .00281774      .39727696      .06637707
        57|      .00256742      .39732314      .06640137
        58|      .00233934      .39736541      .06642356
        59|      .00213152      .39740409      .06644383
        60|      .00194216      .39743947      .06646234
        61|      .00176963      .39747182      .06647924
        62|      .00161242       .3975014      .06649466
        63|      .00146917      .39752842      .06650873
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lse is at the limit of the lambda range.


K-fold cross-validation with 10 folds. Elastic net with alpha=.3.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812      .44529989      .07882048  ^
         2|      .42827212      .43541694      .07554672
         3|       .3902256      .42687637      .07255057
         4|      .35555903      .41952353      .06981929
         5|      .32397215      .41321631      .06733883
         6|      .29519136      .40782529      .06509417
         7|      .26896737      .40323347      .06306964
         8|      .24507305      .40001487      .06128728
         9|      .22330144      .39808447      .05978981
        10|      .20346395      .39735749      .05857717
        11|      .18538878      .39719435      .05757831  *
        12|      .16891935      .39732921      .05677394
        13|      .15391302      .39811974      .05635231
        14|      .14023981      .39919567      .05630205
        15|      .12778129      .40019299      .05646601
        16|      .11642955      .40073679      .05669463
        17|      .10608627      .40091483      .05685402
        18|      .09666186      .40114622      .05717764
        19|      .08807469      .40098742      .05776215
        20|      .08025038      .40099934      .05836479
        21|      .07312115      .40114941      .05897052
        22|      .06662527      .40114799      .05948742
        23|      .06070647      .40109615      .05994603
        24|      .05531347      .40028904       .0601798
        25|      .05039957       .3996653      .06044304
        26|      .04592222      .39919495      .06072542
        27|      .04184261      .39885197      .06101861
        28|      .03812543      .39861389      .06131593
        29|      .03473847      .39846146      .06161219
        30|       .0316524      .39836032      .06190805
        31|      .02884049      .39808305      .06224123
        32|      .02627838      .39784061      .06255301
        33|      .02394388      .39765313      .06285056
        34|      .02181677      .39751086       .0631329
        35|      .01987863      .39740558      .06339951
        36|      .01811267      .39733036      .06365023
        37|      .01650359       .3972794      .06388516
        38|      .01503746      .39724785      .06410461
        39|      .01370157       .3972317      .06430905
        40|      .01248436      .39722762      .06449906
        41|      .01137528      .39723286      .06467529
        42|      .01036473      .39724519      .06483845
        43|      .00944396      .39726277      .06498925
        44|      .00860498      .39728411      .06512844
        45|      .00784054      .39730804      .06525674
        46|      .00714401       .3973336      .06537487
        47|      .00650936      .39736002      .06548353
        48|      .00593108      .39738673      .06558339
        49|      .00540418      .39741327      .06567507
        50|      .00492409      .39743928       .0657592
        51|      .00448665      .39746453      .06583634
        52|      .00408806      .39748881      .06590703
        53|      .00372489      .39751201      .06597178
        54|      .00339398      .39753404      .06603105
        55|      .00309247      .39755485      .06608529
        56|      .00281774      .39757444       .0661349
        57|      .00256742      .39759281      .06618027
        58|      .00233934      .39760997      .06622173
        59|      .00213152      .39762597      .06625963
        60|      .00194216      .39764084      .06629424
        61|      .00176963      .39765464      .06632586
        62|      .00161242      .39766743      .06635473
        63|      .00146917      .39767925      .06638109
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lse is at the limit of the lambda range.


K-fold cross-validation with 10 folds. Elastic net with alpha=.7.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812      .56478477      .11268272
         2|      .42827212      .53834409      .10494957
         3|       .3902256      .51647335      .09837217
         4|      .35555903      .49844777      .09247087
         5|      .32397215      .48344329      .08707347
         6|      .29519136      .46920859      .08244563
         7|      .26896737      .45606914        .078432
         8|      .24507305      .44348282      .07473117  ^
         9|      .22330144      .43289941      .07144851
        10|      .20346395      .42377807      .06852391
        11|      .18538878        .416121       .0659115
        12|      .16891935      .40982415      .06357773
        13|      .15391302      .40459551      .06151615
        14|      .14023981      .40024536      .05969764
        15|      .12778129      .39663093      .05809528
        16|      .11642955      .39475363      .05678376
        17|      .10608627      .39420819      .05582604  *
        18|      .09666186      .39475825      .05516119
        19|      .08807469      .39566183      .05469839
        20|      .08025038      .39662863      .05440645
        21|      .07312115      .39855638      .05466686
        22|      .06662527      .40034315      .05515023
        23|      .06070647      .40171035      .05578078
        24|      .05531347       .4027468       .0563652
        25|      .05039957      .40351716       .0568747
        26|      .04592222      .40373416      .05759446
        27|      .04184261      .40383878      .05838472
        28|      .03812543      .40410598      .05913399
        29|      .03473847      .40426995      .05972735
        30|       .0316524      .40421342      .06016101
        31|      .02884049      .40343107      .06040336
        32|      .02627838       .4026502       .0607131
        33|      .02394388      .40203757       .0610298
        34|      .02181677      .40155988      .06134707
        35|      .01987863      .40115794      .06166821
        36|      .01811267       .4008511      .06197901
        37|      .01650359      .40062127      .06227702
        38|      .01503746      .40028311       .0626034
        39|      .01370157      .39994508      .06292698
        40|      .01248436      .39966671      .06322981
        41|      .01137528      .39943782      .06351225
        42|      .01036473      .39924995      .06377493
        43|      .00944396      .39908768      .06401694
        44|      .00860498      .39890069      .06423062
        45|      .00784054      .39874262      .06442897
        46|      .00714401      .39860883      .06461269
        47|      .00650936      .39849548      .06478256
        48|      .00593108      .39839932      .06493935
        49|      .00540418      .39831763      .06508388
        50|      .00492409      .39824813      .06521693
        51|      .00448665      .39818892      .06533929
        52|      .00408806      .39813838       .0654517
        53|      .00372489      .39809518       .0655549
        54|      .00339398      .39805819      .06564956
        55|      .00309247      .39802645      .06573633
        56|      .00281774      .39799916      .06581582
        57|      .00256742      .39797566       .0658886
        58|      .00233934      .39795539      .06595521
        59|      .00213152      .39793785      .06601615
        60|      .00194216      .39792265      .06607188
        61|      .00176963      .39790945      .06612282
        62|      .00161242      .39789797      .06616937
        63|      .00146917      .39788795       .0662119
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse


K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812      .68765443       .1373409
         2|      .42827212      .65513813      .13755403
         3|       .3902256      .61330573      .12760865
         4|      .35555903      .57588694      .11700443
         5|      .32397215      .54476261      .10768145
         6|      .29519136      .51886926      .09948626
         7|      .26896737      .49790373      .09268422
         8|      .24507305      .48106487      .08704268
         9|      .22330144      .46757902      .08192997
        10|      .20346395       .4562232      .07754346
        11|      .18538878      .44550619      .07376981  ^
        12|      .16891935      .43595363      .07036464
        13|      .15391302      .42657658      .06740889
        14|      .14023981      .41860881      .06487241
        15|      .12778129      .41202072      .06265271
        16|      .11642955      .40628874      .06067793
        17|      .10608627      .40150317      .05894068
        18|      .09666186      .39759331       .0573977
        19|      .08807469      .39500474      .05608341
        20|      .08025038       .3939009      .05507944  *
        21|      .07312115      .39424725      .05446178
        22|      .06662527      .39521599      .05405737
        23|      .06070647      .39634974      .05384646
        24|      .05531347      .39813019      .05396025
        25|      .05039957      .40007771      .05454916
        26|      .04592222      .40183114      .05526845
        27|      .04184261      .40326722      .05607408
        28|      .03812543      .40401502      .05664212
        29|      .03473847      .40467183      .05734232
        30|       .0316524      .40477347      .05819792
        31|      .02884049      .40500933      .05900882
        32|      .02627838      .40521778      .05969353
        33|      .02394388      .40534316      .06023307
        34|      .02181677       .4046186       .0604313
        35|      .01987863      .40384936      .06073578
        36|      .01811267      .40312431      .06106187
        37|      .01650359      .40254831      .06138569
        38|      .01503746      .40209645      .06170245
        39|      .01370157      .40173272       .0620117
        40|      .01248436      .40142526      .06231409
        41|      .01137528      .40110867      .06262028
        42|      .01036473      .40069569      .06294802
        43|      .00944396      .40034997      .06325382
        44|      .00860498      .40006034      .06353825
        45|      .00784054       .3998175      .06380212
        46|      .00714401      .39961373      .06404637
        47|      .00650936      .39944258      .06427203
        48|      .00593108      .39925579      .06447205
        49|      .00540418      .39907614      .06465322
        50|      .00492409      .39892114      .06482056
        51|      .00448665      .39878714       .0649749
        52|      .00408806      .39867103      .06511705
        53|      .00372489      .39857021      .06524781
        54|      .00339398      .39848247      .06536799
        55|      .00309247      .39840596      .06547832
        56|      .00281774       .3983391      .06557955
        57|      .00256742      .39828054      .06567235
        58|      .00233934      .39822914      .06575737
        59|      .00213152      .39818394      .06583523
        60|      .00194216      .39814411      .06590648
        61|      .00176963      .39810893      .06597167
        62|      .00161242      .39807782      .06603128
        63|      .00146917      .39805024      .06608578
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse

Cross-validation over alpha (0 .3 .7 1).
         alpha | lopt*        Minimum MSPE
   ------------+----------------------------
         0.000 |  .10608627   .39020487  #
         0.300 |  .18538878   .39719435
         0.700 |  .10608627   .39420819
         1.000 |  .08025038    .3939009
* lambda value that minimizes MSPE for a given alpha
# alpha value that minimizes MSPE
Estimate lasso with lambda=.47 (lse) and alpha=0.

------------------+--------------------------------
         Selected |           Ridge   Post-est OLS
------------------+--------------------------------
           lcavol |       0.2170410      0.3897536
          lweight |       0.4973051      0.7911376
              age |      -0.0039816     -0.0203522
             lbph |       0.0775598      0.1026400
              svi |      -0.0935545     -0.2764415
              lcp |       0.0076792     -0.0959183
          gleason |       0.1359352      0.2326491
            pgg45 |       0.0020570      0.0026209
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |      -0.7078928     -1.5876684
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=.4700281188547001).
(69 missing values generated)

------------------+--------------------------------
         Selected |           Ridge   Post-est OLS
------------------+--------------------------------
           lcavol |       0.2170410      0.3897536
          lweight |       0.4973051      0.7911376
              age |      -0.0039816     -0.0203522
             lbph |       0.0775598      0.1026400
              svi |      -0.0935545     -0.2764415
              lcp |       0.0076792     -0.0959183
          gleason |       0.1359352      0.2326491
            pgg45 |       0.0020570      0.0026209
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |      -0.7078928     -1.5876684
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=.4700281188547001).
(69 missing values generated)
mreldif=0. tolerance = .01

__000000[1,9]
        lcavol     lweight         age        lbph         svi         lcp
y1   .21704097    .4973051  -.00398162   .07755978  -.09355452   .00767922

       gleason       pgg45       _cons
y1    .1359352   .00205695  -.70789276

__000001[1,9]
        lcavol     lweight         age        lbph         svi         lcp
y1   .21704097    .4973051  -.00398162   .07755978  -.09355452   .00767922

       gleason       pgg45       _cons
y1    .1359352   .00205695  -.70789276

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|       64.86388         .73815      .13934819
         2|      59.101552      .72696279      .13684858
         3|      53.851133       .6911905      .13033704
         4|      49.067147      .65516965      .12292271
         5|      44.708157      .61856766      .11453878
         6|      40.736407         .58831       .1077572
         7|      37.117497      .56330798      .10240623
         8|      33.820081      .54289378      .09839534  ^
         9|      30.815598      .52636626       .0955039
        10|      28.078025      .51313142      .09344308
        11|      25.583651      .50234616      .09222386
        12|       23.31087      .49347152       .0916299
        13|      21.239997      .48604068       .0914002
        14|      19.353094      .47998464      .09145944
        15|      17.633818      .47423991       .0914453
        16|      16.067278      .46906988      .09158127
        17|      14.639906      .46489735      .09190217
        18|      13.339337       .4614885      .09233757
        19|      12.154307      .45850261      .09279684
        20|      11.074552       .4561127      .09333192
        21|      10.090719      .45430203      .09393271
        22|      9.1942875      .45408009      .09444503  *
        23|      8.3774923      .45520803       .0947816
        24|       7.633259      .45659624      .09510214
        25|      6.9551413      .45813535      .09541936
        26|      6.3372657      .45929872      .09575475
        27|      5.7742805      .45997826       .0960196
        28|      5.2613093      .46072422      .09626595
        29|      4.7939091      .46123203      .09614638
        30|      4.3680314      .46142682      .09580863
        31|      3.9799876       .4610857      .09543152
        32|      3.6264164      .46083084      .09510119
        33|      3.3042556      .46054012      .09465183
        34|      3.0107146      .45998373      .09434707
        35|       2.743251      .45951242      .09412049
        36|      2.4995482      .45892324      .09398604
        37|      2.2774952      .45831124      .09388383
        38|      2.0751688      .45780864      .09380486
        39|      1.8908165      .45735658      .09376111
        40|      1.7228416      .45700626      .09372764
        41|      1.5697891      .45673819       .0937025
        42|      1.4303334      .45646934      .09362726
        43|      1.3032665      .45609866      .09342596
        44|      1.1874879      .45579166      .09324682
        45|      1.0819947      .45553748      .09308717
        46|      .98587331      .45532708      .09294468
        47|      .89829104      .45515297      .09281735
        48|      .81848934      .45500894      .09270341
        49|        .745777      .45488984      .09260133
        50|      .67952423      .45479139      .09250976
        51|      .61915717      .45471005      .09242754
        52|      .56415295      .45464287      .09235363
        53|      .51403516      .45458743      .09228712
        54|      .46836969       .4545417      .09222722
        55|      .42676102        .454504      .09217322
        56|      .38884875      .45447295      .09212451
        57|       .3543045       .4544474      .09208052
        58|      .32282906      .45442639      .09204078
        59|      .29414982      .45440914      .09200485
        60|      .26801836      .45439498      .09197234
        61|      .24420835      .45438338      .09194291
        62|      .22251355       .4543739      .09191626
        63|      .20274606      .45436615      .09189211
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Estimate lasso with lambda=33.82 (lse).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.1848622      0.3782994
          lweight |       0.3581076      0.8391637
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |       0.5029428     -1.3919237
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=33.82008100076).
(69 missing values generated)

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
           lcavol |       0.1848622      0.3782994
          lweight |       0.3581076      0.8391637
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |       0.5029428     -1.3919237
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=33.82008100076).
(69 missing values generated)
mreldif=0. tolerance = .01

__000000[1,3]
       lcavol    lweight      _cons
y1  .18486224  .35810765  .50294277

__000001[1,3]
       lcavol    lweight      _cons
y1  .18486224  .35810765  .50294277

K-fold cross-validation with 10 folds. Elastic net with alpha=0.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812      .44726584      .07065653  ^
         2|      .42827212      .44571884      .07036734
         3|       .3902256      .44442816      .07021443
         4|      .35555903      .44338599      .07018872
         5|      .32397215      .44258269      .07028015
         6|      .29519136      .44200686      .07047791
         7|      .26896737      .44164545      .07077066
         8|      .24507305      .44148392      .07114681  *
         9|      .22330144       .4415065      .07159477
        10|      .20346395      .44169647      .07210312
        11|      .18538878      .44203645      .07266082
        12|      .16891935      .44250872      .07325742
        13|      .15391302      .44309556      .07388311
        14|      .14023981      .44377954      .07452885
        15|      .12778129      .44454376      .07518646
        16|      .11642955      .44537212      .07584861
        17|      .10608627      .44624952      .07650884
        18|      .09666186      .44716196      .07716156
        19|      .08807469       .4480967      .07780203
        20|      .08025038      .44904233      .07842629
        21|      .07312115      .44998873      .07903111
        22|      .06662527      .45092712      .07961396
        23|      .06070647      .45185003       .0801729
        24|      .05531347      .45275119      .08070656
        25|      .05039957      .45362549      .08121404
        26|      .04592222      .45446888      .08169486
        27|      .04184261      .45527827      .08214892
        28|      .03812543      .45605143      .08257639
        29|      .03473847      .45678687      .08297771
        30|       .0316524      .45748378      .08335353
        31|      .02884049       .4581419      .08370464
        32|      .02627838      .45876142      .08403197
        33|      .02394388      .45934295      .08433652
        34|      .02181677      .45988739      .08461939
        35|      .01987863      .46039589      .08488168
        36|      .01811267      .46086981      .08512452
        37|      .01650359      .46131061      .08534904
        38|      .01503746      .46171988      .08555637
        39|      .01370157      .46209924       .0857476
        40|      .01248436      .46245034      .08592379
        41|      .01137528      .46277486      .08608598
        42|      .01036473      .46307442      .08623513
        43|      .00944396      .46335063      .08637219
        44|      .00860498      .46360504      .08649805
        45|      .00784054      .46383915      .08661354
        46|      .00714401       .4640544      .08671945
        47|      .00650936      .46425214      .08681652
        48|      .00593108      .46443367      .08690544
        49|      .00540418       .4646002      .08698686
        50|      .00492409      .46475289      .08706138
        51|      .00448665      .46489281      .08712956
        52|      .00408806      .46502096      .08719191
        53|      .00372489      .46513828      .08724892
        54|      .00339398      .46524564      .08730102
        55|      .00309247      .46534384      .08734863
        56|      .00281774      .46543364      .08739212
        57|      .00256742      .46551573      .08743184
        58|      .00233934      .46559075      .08746811
        59|      .00213152      .46565929      .08750122
        60|      .00194216      .46572189      .08753144
        61|      .00176963      .46577906      .08755902
        62|      .00161242      .46583126      .08758419
        63|      .00146917      .46587891      .08760715
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lse is at the limit of the lambda range.


K-fold cross-validation with 10 folds. Elastic net with alpha=.3.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812       .4807686      .08462549  ^
         2|      .42827212      .47256051      .08070791
         3|       .3902256      .46563366      .07728267
         4|      .35555903      .45983105       .0743409
         5|      .32397215      .45500889      .07186538
         6|      .29519136      .45103664      .06983106
         7|      .26896737      .44779678      .06820608
         8|      .24507305      .44568547      .06710056
         9|      .22330144      .44446595      .06642088
        10|      .20346395      .44367255      .06600318
        11|      .18538878      .44354984      .06580573  *
        12|      .16891935      .44409278      .06585495
        13|      .15391302      .44466433      .06626105
        14|      .14023981      .44536206       .0668258
        15|      .12778129      .44628011      .06748795
        16|      .11642955      .44675365      .06818043
        17|      .10608627      .44710255      .06876427
        18|      .09666186      .44828134      .06965561
        19|      .08807469      .44959762      .07062134
        20|      .08025038      .45068917        .071747
        21|      .07312115      .45114911      .07260245
        22|      .06662527      .45154277      .07344089
        23|      .06070647      .45201081      .07430661
        24|      .05531347      .45244205      .07521906
        25|      .05039957      .45297301      .07610437
        26|      .04592222      .45357727      .07695654
        27|      .04184261      .45423254      .07777138
        28|      .03812543      .45492028      .07854614
        29|      .03473847      .45562517      .07927923
        30|       .0316524      .45633475         .07997
        31|      .02884049      .45703904      .08061856
        32|      .02627838      .45773015      .08122555
        33|      .02394388        .458402      .08179206
        34|      .02181677      .45905006      .08231951
        35|      .01987863      .45967102      .08280952
        36|      .01811267      .46024884      .08325919
        37|      .01650359      .46068402      .08363694
        38|      .01503746      .46109797      .08398602
        39|      .01370157      .46148987      .08430819
        40|      .01248436      .46185936      .08460516
        41|      .01137528      .46220647       .0848786
        42|      .01036473      .46253153      .08513014
        43|      .00944396      .46283508      .08536133
        44|      .00860498      .46311785      .08557364
        45|      .00784054      .46338069      .08576847
        46|      .00714401      .46362452      .08594716
        47|      .00650936      .46385033      .08611093
        48|      .00593108      .46405911      .08626095
        49|      .00540418      .46425189      .08639831
        50|      .00492409      .46442967      .08652403
        51|      .00448665      .46459342      .08663904
        52|      .00408806      .46474411      .08674422
        53|      .00372489      .46488264      .08684037
        54|      .00339398       .4650099      .08692825
        55|      .00309247       .4651267      .08700855
        56|      .00281774      .46523385       .0870819
        57|      .00256742      .46533207      .08714888
        58|      .00233934      .46542205      .08721004
        59|      .00213152      .46550446      .08726587
        60|      .00194216      .46557989      .08731683
        61|      .00176963       .4656489      .08736334
        62|      .00161242      .46571203      .08740578
        63|      .00146917      .46576974       .0874445
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lse is at the limit of the lambda range.


K-fold cross-validation with 10 folds. Elastic net with alpha=.7.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812      .58619016      .12810454
         2|      .42827212      .56107624      .11832598
         3|       .3902256      .54039885      .10991634
         4|      .35555903      .52456909      .10265959
         5|      .32397215      .51165111       .0961521  ^
         6|      .29519136      .50061598      .09049654
         7|      .26896737      .49111134      .08554142
         8|      .24507305      .48239203       .0814258
         9|      .22330144      .47510973       .0779965
        10|      .20346395      .46904459      .07499795
        11|      .18538878      .46405149      .07247272
        12|      .16891935      .46009631      .07050059
        13|      .15391302      .45699556      .06901584
        14|      .14023981      .45397225      .06777763
        15|      .12778129      .45120778      .06680757
        16|      .11642955      .44953485      .06628193
        17|      .10608627      .44871007      .06610389
        18|      .09666186      .44833137      .06613475  *
        19|      .08807469      .44869745       .0663539
        20|      .08025038      .44970847      .06688917
        21|      .07312115      .45065363      .06765046
        22|      .06662527      .45153455      .06848568
        23|      .06070647      .45271177      .06942702
        24|      .05531347      .45257275      .07000925
        25|      .05039957      .45243613       .0705241
        26|      .04592222      .45338008      .07147215
        27|      .04184261      .45455376      .07269662
        28|      .03812543      .45540524      .07378965
        29|      .03473847       .4559352      .07465225
        30|       .0316524      .45658653      .07549777
        31|      .02884049      .45704894      .07638579
        32|      .02627838      .45744487      .07725548
        33|      .02394388      .45779308      .07809994
        34|      .02181677      .45818688      .07890063
        35|      .01987863      .45862789      .07965063
        36|      .01811267      .45909868       .0803506
        37|      .01650359      .45958543      .08100187
        38|      .01503746      .46007733      .08160628
        39|      .01370157      .46056602      .08216596
        40|      .01248436      .46104515      .08268324
        41|      .01137528      .46151001      .08316058
        42|      .01036473       .4619572      .08360042
        43|      .00944396      .46238438      .08400522
        44|      .00860498      .46271952      .08435291
        45|      .00784054      .46297764      .08465122
        46|      .00714401      .46322396      .08492508
        47|      .00650936      .46345767      .08517631
        48|      .00593108      .46367834      .08540661
        49|      .00540418      .46388585      .08561762
        50|      .00492409      .46408028      .08581084
        51|      .00448665      .46426189      .08598768
        52|      .00408806      .46443109      .08614946
        53|      .00372489      .46458834      .08629742
        54|      .00339398      .46473419      .08643268
        55|      .00309247      .46486922      .08655629
        56|      .00281774      .46499403      .08666923
        57|      .00256742      .46510923      .08677239
        58|      .00233934      .46521543       .0868666
        59|      .00213152      .46531321      .08695262
        60|      .00194216      .46540316      .08703113
        61|      .00176963      .46548581       .0871028
        62|      .00161242      .46556172      .08716819
        63|      .00146917      .46563136      .08722786
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse


K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      .47002812      .69815481      .15163127
         2|      .42827212      .66932957      .15135765
         3|       .3902256       .6375022      .14767754
         4|      .35555903      .60003182      .13432424
         5|      .32397215      .56894123      .12262063
         6|      .29519136      .54436246      .11216636
         7|      .26896737       .5244468      .10333925
         8|      .24507305      .50941128      .09638042  ^
         9|      .22330144      .49830776      .09020357
        10|      .20346395      .48935447      .08495596
        11|      .18538878      .48204675      .08053992
        12|      .16891935      .47586911      .07683111
        13|      .15391302      .47030912      .07399968
        14|      .14023981      .46538509      .07179493
        15|      .12778129      .46149035      .07007257
        16|      .11642955      .45819543      .06862152
        17|      .10608627      .45565501      .06760599
        18|      .09666186      .45372367      .06695403
        19|      .08807469      .45232684       .0666063
        20|      .08025038      .45154331       .0664764
        21|      .07312115      .45103659      .06652145
        22|      .06662527       .4509109      .06667515  *
        23|      .06070647      .45178675      .06707184
        24|      .05531347      .45258315       .0678345
        25|      .05039957      .45348951      .06867401
        26|      .04592222      .45460175      .06962724
        27|      .04184261      .45508972      .07045032
        28|      .03812543      .45458988      .07093927
        29|      .03473847      .45447797      .07149219
        30|       .0316524      .45566263      .07270131
        31|      .02884049      .45675066      .07396821
        32|      .02627838       .4571526      .07483705
        33|      .02394388      .45770467      .07568529
        34|      .02181677      .45820848      .07656181
        35|      .01987863      .45865808       .0774122
        36|      .01811267      .45907697      .07825024
        37|      .01650359       .4594059      .07903985
        38|      .01503746      .45973484      .07979336
        39|      .01370157      .46010643      .08049433
        40|      .01248436      .46050468      .08114456
        41|      .01137528      .46091709      .08174629
        42|      .01036473        .461334      .08230202
        43|      .00944396      .46174801      .08281441
        44|      .00860498       .4621536      .08328616
        45|      .00784054      .46254669      .08371996
        46|      .00714401       .4629244      .08411845
        47|      .00650936      .46327511      .08448079
        48|      .00593108      .46348523      .08477022
        49|      .00540418      .46368773      .08503559
        50|      .00492409      .46388141      .08527874
        51|      .00448665       .4640655      .08550141
        52|      .00408806      .46423955      .08570521
        53|      .00372489      .46440338      .08589167
        54|      .00339398      .46455702      .08606219
        55|      .00309247      .46470063      .08621806
        56|      .00281774      .46483448      .08636052
        57|      .00256742      .46495893      .08649067
        58|      .00233934      .46507439      .08660955
        59|      .00213152      .46518132       .0867181
        60|      .00194216      .46528017      .08681721
        61|      .00176963      .46537143      .08690767
        62|      .00161242      .46545556      .08699024
        63|      .00146917      .46553304      .08706558
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse

Cross-validation over alpha (0 .3 .7 1).
         alpha | lopt*        Minimum MSPE
   ------------+----------------------------
         0.000 |  .24507305   .44148392  #
         0.300 |  .18538878   .44354984
         0.700 |  .09666186   .44833137
         1.000 |  .06662527    .4509109
* lambda value that minimizes MSPE for a given alpha
# alpha value that minimizes MSPE
Estimate lasso with lambda=.47 (lse) and alpha=0.

------------------+--------------------------------
         Selected |           Ridge   Post-est OLS
------------------+--------------------------------
           lcavol |       0.2170410      0.3897536
          lweight |       0.4973051      0.7911376
              age |      -0.0039816     -0.0203522
             lbph |       0.0775598      0.1026400
              svi |      -0.0935545     -0.2764415
              lcp |       0.0076792     -0.0959183
          gleason |       0.1359352      0.2326491
            pgg45 |       0.0020570      0.0026209
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |      -0.7078928     -1.5876684
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=.4700281188547001).
(69 missing values generated)

------------------+--------------------------------
         Selected |           Ridge   Post-est OLS
------------------+--------------------------------
           lcavol |       0.2170410      0.3897536
          lweight |       0.4973051      0.7911376
              age |      -0.0039816     -0.0203522
             lbph |       0.0775598      0.1026400
              svi |      -0.0935545     -0.2764415
              lcp |       0.0076792     -0.0959183
          gleason |       0.1359352      0.2326491
            pgg45 |       0.0020570      0.0026209
------------------+--------------------------------
   Partialled-out*|
------------------+--------------------------------
            _cons |      -0.7078928     -1.5876684
------------------+--------------------------------
Use e(b) from previous lasso2 estimation (lambda=.4700281188547001).
(69 missing values generated)
mreldif=0. tolerance = .01

__000000[1,9]
        lcavol     lweight         age        lbph         svi         lcp
y1   .21704097    .4973051  -.00398162   .07755978  -.09355452   .00767922

       gleason       pgg45       _cons
y1    .1359352   .00205695  -.70789276

__000001[1,9]
        lcavol     lweight         age        lbph         svi         lcp
y1   .21704097    .4973051  -.00398162   .07755978  -.09355452   .00767922

       gleason       pgg45       _cons
y1    .1359352   .00205695  -.70789276
r; t=5.86 20:21:56

. *
.
. ********************************************************************************
. *** partial                                                                                      ***
. ********************************************************************************
.
.
. * load example data
. insheet using "$prostate", tab clear
(11 vars, 97 obs)
r; t=0.61 20:21:56

.
. cvlasso $model, partial(svi) saveest(m)

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      113.54767      .92810044      .14125823
         2|      103.46041      .89743208      .13984793
         3|      94.269272      .84698786      .12962102
         4|      85.894649       .8034353      .12009755
         5|      78.264005      .76717895      .11193551
         6|      71.311247      .73687106      .10496926
         7|      64.976152      .70977163      .09887212
         8|       59.20385      .68491422      .09353112
         9|      53.944343      .66029017      .08846888
        10|      49.152076      .63675856      .08373702
        11|      44.785541       .6171784      .07978601
        12|      40.806917      .60088269      .07648243  ^
        13|      37.181743       .5875348      .07382533
        14|       33.87862      .57693934      .07171871
        15|      30.868936       .5682703      .07000492
        16|      28.126625      .56120868      .06876519
        17|      25.627933      .55518126      .06848201
        18|      23.351218      .55046904      .06858147
        19|       21.27676      .54676171      .06879055
        20|      19.386592      .54398718      .06907625
        21|       17.66434      .54191837      .06939279
        22|      16.095089      .54003365       .0696544
        23|      14.665246      .53852262      .06989421
        24|      13.362426      .53812578      .07012989
        25|      12.175345      .53832579      .07035321
        26|      11.093721      .53826037      .07056447
        27|      10.108185      .53786967      .07093189
        28|      9.2102017      .53713298      .07087962
        29|      8.3919928      .53665065      .07106639
        30|      7.6464713      .53605999      .07151172
        31|      6.9671798      .53526344      .07217222
        32|      6.3482348      .53469694      .07280828
        33|      5.7842751      .53403281      .07343641
        34|       5.270416      .53351888      .07403369
        35|      4.8022068      .53316651      .07459398
        36|       4.375592      .53194544      .07533791
        37|      3.9868765      .53071925      .07607058
        38|      3.6326933      .52969279      .07673514
        39|      3.3099749      .52884208      .07733835
        40|      3.0159258       .5281428      .07788621
        41|      2.7479993      .52728948      .07835937
        42|      2.5038746      .52648626      .07878276
        43|      2.2814373      .52579993      .07916793
        44|      2.0787607      .52521238      .07951832
        45|      1.8940893      .52468293      .07983516
        46|      1.7258236      .52420837      .08012221
        47|      1.5725062      .52379813      .08038341
        48|      1.4328091      .52342923      .08061638
        49|      1.3055223      .52310885      .08082854
        50|      1.1895433      .52282994      .08102172
        51|      1.0838675      .52258662      .08119763
        52|      .98757974      .52237389       .0813578
        53|      .89984588       .5221875      .08150366
        54|      .81990605      .52202385      .08163648
        55|      .74706786      .52187987      .08175743
        56|      .68070041      .52175295      .08186759
        57|      .62022886      .52164084       .0819679
        58|      .56512944      .52154162      .08205927
        59|      .51492489      .52145366      .08214248
        60|      .46918039      .52137554      .08221827
        61|      .42749969      .52130604      .08228731
        62|       .3895218      .52124411      .08235019
        63|      .35491776      .52118884      .08240746
        64|      .32338784      .52114055      .08245931  *
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lopt is at the limit of the lambda range.
r; t=1.08 20:21:57

.
. // make sure that partial works
. estimates restore m1
(results m1 are active now)
r; t=0.01 20:21:57

. assert "`e(partial)'"=="svi"
r; t=0.00 20:21:57

.
.
. ********************************************************************************
. *** misc options/syntax checks                                                   ***
. ********************************************************************************
.
. // Support for inrange(.) and similar [if] expressions:
. cvlasso $model if inrange(age,50,70)

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      132.46591      1.3468706      .28051017
         2|        120.698      1.2663279      .28277885
         3|      109.97553      1.1638371        .264536
         4|       100.2056      1.0770413      .24756594
         5|      91.303614      1.0050165      .23294401
         6|      83.192453      .94628701      .22011741
         7|      75.801865      .89729298      .20917878
         8|      69.067836      .85344967      .19961019
         9|       62.93204      .81748443      .19107086
        10|      57.341331      .78605508      .18244682
        11|      52.247285      .75803541      .17315602
        12|       47.60578      .73426303      .16502049
        13|      43.376614      .71347782      .15833262  ^
        14|      39.523155      .69707931      .15282169
        15|      36.012027      .68237011      .14860429
        16|      32.812818      .66879212      .14538535
        17|      29.897817      .65590514      .14211631
        18|      27.241778      .64503617      .13902259
        19|      24.821693      .63562948      .13625794
        20|      22.616602      .62762356      .13380436
        21|      20.607406      .62128712      .13161579
        22|      18.776701      .61607581      .12968819
        23|       17.10863      .61188759      .12804577
        24|      15.588747      .60874875      .12669098
        25|      14.203885      .60648266      .12563051
        26|      12.942051      .60418992       .1247094
        27|      11.792315      .60248719      .12397669
        28|      10.744718      .60136927      .12343029  *
        29|      9.7901873      .60170297      .12349762
        30|       8.920454      .60234317      .12368115
        31|      8.1279855      .60310956      .12391603
        32|      7.4059177      .60395984      .12418638
        33|      6.7479964      .60485137       .1244796
        34|       6.148523      .60592188       .1248269
        35|      5.6023051      .60767394      .12536162
        36|      5.1046118      .60948033      .12584599
        37|      4.6511321      .61207075      .12637019
        38|      4.2379384      .61464505      .12688897
        39|      3.8614516      .61752709      .12755684
        40|      3.5184109      .62052791      .12828173
        41|       3.205845      .62334868      .12897082
        42|      2.9210465       .6260554      .12963867
        43|      2.6615488      .62856219      .13031667
        44|      2.4251041      .63088099      .13095931
        45|      2.2096646      .63277656      .13152733
        46|      2.0133641      .63433622      .13205671
        47|      1.8345024      .63558327       .1326299
        48|      1.6715302      .63671747      .13317138
        49|      1.5230361      .63775095      .13366803
        50|      1.3877338      .63873225      .13412088
        51|      1.2644513      .63965926      .13453374
        52|      1.1521209      .64053124      .13491011
        53|      1.0497697      .64134842      .13525318
        54|      .95651105      .64211183      .13556589
        55|      .87153724      .64280169      .13585909
        56|      .79411228      .64342633      .13613282
        57|      .72356553       .6440069      .13638206
        58|      .65928596      .64454537      .13660901
        59|      .60071681      .64504388      .13681568
        60|      .54735079      .64534099      .13692261
        61|      .49872565      .64560982      .13701649
        62|      .45442024      .64584187      .13710724
        63|       .4140508      .64605003      .13719209
        64|      .37726767        .646243      .13726943
        65|      .34375225      .64642158      .13733993
        66|      .31321425      .64658657      .13740419
        67|      .28538915      .64673881      .13746276
        68|      .26003597      .64687909      .13751615
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=0.51 20:21:58

.
. ********************************************************************************
. *** plotting                                                                                             ***
. ********************************************************************************
.
. * load example data
. insheet using "$prostate", tab clear
(11 vars, 97 obs)
r; t=0.19 20:21:58

.
. cvlasso $model, plotcv

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      163.62492       1.333319      .20089729
         2|      149.08894      1.2420647      .19385317
         3|      135.84429      1.1387822        .177899
         4|      123.77625      1.0531517      .16424841
         5|      112.78031      .98216599      .15250138
         6|      102.76122      .92332908      .14233858
         7|      93.632197      .87456976      .13350476
         8|      85.314171      .83420647      .12570416
         9|      77.735095      .79993609      .11875212
        10|      70.829323      .76609365      .11248448
        11|      64.537041      .73282703      .10780767
        12|      58.803749      .69912922      .10256908
        13|      53.579786        .669818       .0976207
        14|      48.819905      .64551004      .09356449
        15|      44.482879      .62537656      .09026863  ^
        16|      40.531143      .60920075      .08743039
        17|      36.930468      .59590953      .08515487
        18|      33.649667      .58544829      .08345446
        19|      30.660323      .57789692      .08243322
        20|      27.936545       .5724866       .0815623
        21|      25.454739      .56847109      .08089575
        22|       23.19341      .56514785      .08043522
        23|      21.132972      .56189348       .0802513
        24|      19.255577      .55864494      .08044089
        25|      17.544964      .55573796      .08074748
        26|      15.986318      .55325411      .08111917
        27|      14.566138      .55150312      .08129531
        28|      13.272122      .55118766      .08146513
        29|      12.093063      .55099552      .08177064
        30|      11.018749      .55088363      .08210567
        31|      10.039874      .55110601      .08242346
        32|      9.1479589      .55111023       .0827693
        33|      8.3352794      .54997427      .08318548
        34|      7.5947962      .54846465      .08332853
        35|      6.9200954      .54729517      .08348564
        36|      6.3053332      .54684846      .08385284
        37|      5.7451848      .54691285      .08427171
        38|      5.2347984      .54744963      .08462423
        39|      4.7697533      .54808502      .08495417
        40|      4.3460216      .54879163      .08526634
        41|       3.959933      .54933821      .08562963
        42|      3.6081435      .54941743       .0860535
        43|       3.287606      .54908836      .08649829
        44|      2.9955441      .54875064      .08685923
        45|      2.7294282       .5481921      .08695813
        46|      2.4869533      .54742296      .08702243
        47|      2.2660193      .54677854      .08709007
        48|      2.0647124      .54623847      .08716004
        49|       1.881289       .5457992      .08722744
        50|      1.7141605      .54544279      .08729181
        51|      1.5618792      .54515446      .08735287
        52|      1.4231261      .54492196      .08741047
        53|      1.2966995      .54474678      .08746371  *
        54|      1.1815043      .54477019      .08750238
        55|      1.0765427      .54481303      .08753934
        56|      .98090565      .54486992      .08757449
        57|      .89376469      .54493659      .08760776
        58|       .8143651      .54500964      .08763914
        59|      .74201915      .54508642      .08766863
        60|      .67610021      .54516486      .08769625
        61|      .61603733      .54524338      .08772206
        62|      .56131027      .54533234      .08774575
        63|      .51144502      .54544399      .08776693
        64|      .46600965      .54554976      .08778657
        65|      .42461064      .54564951      .08780475
        66|       .3868894      .54574318      .08782155
        67|      .35251921      .54583086      .08783705
        68|      .32120238      .54591267      .08785134
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=3.02 20:22:01

.
. ********************************************************************************
. *** time-series example with rolling cv                                      ***
. ********************************************************************************
.
. webuse air2, clear
(TIMESLAB: Airline passengers)
r; t=1.27 20:22:02

.
. cvlasso air L(1/12).air, rolling origin(130)
Rolling forecasting cross-validation with 1-step ahead forecasts. Elastic net with alpha=1.
Training from-to (validation point): 13-130 (131), 13-131 (132), 13-132 (133), 13-133 (134), 13-134 (135), 13-135 (136), 13-136 (137), 13-137 (138), 13-138 (139), 13-139 (140), 13-140 (141), 13-141 (142), 13-142 (143), 13-143 (144).
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      30083.535      33237.193      8731.4325
         2|      27410.996      27799.242      7290.3087
         3|      24975.879      23267.301      6092.3376
         4|      22757.091      19493.102       5095.861
         5|      20735.414      16349.032      4266.8189
         6|      18893.337      13729.055      3576.9191
         7|      17214.905      11545.052      3002.6587
         8|       15685.58      9723.7885      2524.5123
         9|      14292.116      8204.3942      2126.2578
        10|      13022.444      6936.2699      1794.4166
        11|      11865.566      5877.3493      1517.7888
        12|      10811.462      4992.6553      1287.0672
        13|      9851.0014      4253.1013      1094.5174
        14|      8975.8656       3635.824      936.22874
        15|      8178.4744      3111.7137      812.75242
        16|      7451.9213      2669.6887      708.75189
        17|      6789.9131      2300.5206      621.98344
        18|       6186.716      1992.0343      549.37699
        19|      5637.1052      1734.1043      488.40062
        20|      5136.3203      1518.3087      436.97343
        21|      4680.0237      1337.6412      393.39186
        22|      4264.2633      1186.2716      356.26673
        23|      3885.4379      1059.3481      324.46942
        24|      3540.2663       952.8315      297.08581
        25|      3225.7588      863.35854       273.3769
        26|      2939.1913        788.491      252.67635
        27|      2678.0817      725.70704      234.57369
        28|      2440.1683      670.22718      218.23327
        29|      2223.3904      622.52635      203.38451
        30|      2025.8706      581.16825      190.03867
        31|      1845.8978      546.16451      178.31137
        32|      1681.9133      516.49556      168.00213
        33|      1532.4968      491.30969      158.93797
        34|       1396.354      469.89498      150.96867
        35|      1272.3058      451.65601       143.9631  ^
        36|      1159.2776      436.09447      137.80621
        37|      1056.2906      422.79303      132.39667
        38|      962.45264      411.40189      127.64501
        39|        876.951      401.62764      123.47207
        40|      799.04509      393.22392      119.80779
        41|      728.06013      385.98373      116.59019
        42|      663.38127       379.7329      113.76442
        43|      604.44831      374.32476      111.28209
        44|      550.75079      369.63567      109.10052
        45|      501.82361      365.56123      107.18216
        46|      457.24298       362.0132      105.49406
        47|      416.62277      358.91691      104.00732
        48|      379.61115      356.20904      102.69665
        49|      345.88755      353.83583      101.53998
        50|      315.15985       352.3553      100.65556  *
        51|      287.16192      356.42305      101.19582
        52|      261.65124      363.33054      102.75269
        53|      238.40687      370.44865      105.00085
        54|      217.22746      372.21202      106.53333
        55|      197.92957      373.58108      108.17032
        56|      180.34605      375.89938      109.80358
        57|      164.32461      378.99098      111.37688
        58|      149.72646      380.49347      112.55753
        59|      136.42518      381.08165      113.73224
        60|      124.30554      381.60207      114.93783
        61|      113.26258      380.71469       115.6034
        62|      103.20064      379.53228      116.00241
        63|      94.032582      380.74666      117.01678
        64|      85.678986      382.39512      117.92244
        65|      78.067501      382.00813      118.30133
        66|        71.1322      379.53614      118.33073
        67|      64.813011      377.47621      118.59801
        68|      59.055202      376.71111      119.05724
        69|        53.8089      376.19828      119.49392
        70|      49.028666      375.22278      119.97715
        71|      44.673094      373.26668      120.18322
        72|       40.70446      372.49456      120.43289
        73|      37.088388      372.59088      120.82114
        74|      33.793558      374.04884      121.19229
        75|      30.791431       377.5105      121.17767
        76|      28.056005      381.87875      121.00114
        77|      25.563587      385.86197      120.80072
        78|      23.292588      389.16575      120.36636
        79|      21.223339      392.38507      120.08113
        80|      19.337916      396.88113       120.4689
        81|      17.619989      402.63138      121.19743
        82|      16.054678      412.30702      121.83665
        83|      14.628424      421.09094      121.51485
        84|      13.328875      426.86241       120.2055
        85|      12.144775      431.12421      119.04316
        86|      11.065867      433.74587      118.05604
        87|      10.082806      436.53986      117.36929
        88|      9.1870769      439.42206      116.91838
        89|      8.3709223      442.32753      116.65087
        90|      7.6272726      445.20676       116.5244
        91|      6.9496867      448.02273      116.50501
        92|      6.3322957      450.74836      116.56561
        93|       5.769752      453.36455      116.68474
        94|      5.2571831      455.85849      116.84547
        95|      4.7901495      458.22233      117.03456
        96|      4.3646058      460.45211      117.24169
        97|      3.9768663      462.54684      117.45892
        98|      3.6235724      464.50782      117.68017
        99|      3.3016642      466.33804      117.90088
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=21.59 20:22:24

. // we should have 144-130=14 folds
. assert 14==`e(nfolds)'
r; t=0.00 20:22:24

.
. cvlasso air L(1/12).air, rolling origin(130) h(2)
Rolling forecasting cross-validation with 2-step ahead forecasts. Elastic net with alpha=1.
Training from-to (validation point): 13-130 (132), 13-131 (133), 13-132 (134), 13-133 (135), 13-134 (136), 13-135 (137), 13-136 (138), 13-137 (139), 13-138 (140), 13-139 (141), 13-140 (142), 13-141 (143), 13-142 (144).
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      30083.535      34952.233      8972.5481
         2|      27410.996      29219.469      7495.1704
         3|      24975.879      24447.167      6266.3552
         4|      22757.091      20473.399      5244.0824
         5|      20735.414      17163.629      4393.4479
         6|      18893.337       14406.07       3685.457
         7|      17214.905      12107.831      3096.0221
         8|       15685.58      10191.716      2605.1314
         9|      14292.116      8593.5634      2196.1576
        10|      13022.444       7260.043      1855.2848
        11|      11865.566      6146.8207      1571.0323
        12|      10811.462      5217.0365      1333.8591
        13|      9851.0014      4440.0404       1135.836
        14|      8975.8656      3792.7368      974.00243
        15|      8178.4744      3245.1003      846.71514
        16|      7451.9213      2784.0987       739.5864
        17|      6789.9131      2399.2025      650.14159
        18|       6186.716      2077.6828      575.22206
        19|      5637.1052      1808.9545      512.22553
        20|      5136.3203      1584.2142      459.01598
        21|      4680.0237      1396.1389      413.84709
        22|      4264.2633      1238.6362      375.29686
        23|      3885.4379      1106.6361      342.21155
        24|      3540.2663      995.91868      313.65775
        25|      3225.7588      902.97087      288.88156
        26|      2939.1913      825.34561      267.17892
        27|      2678.0817      760.38714      248.10453
        28|      2440.1683      703.31872      230.76798
        29|      2223.3904      654.06491      214.98796
        30|      2025.8706      611.52854      200.84841
        31|      1845.8978      575.54121      188.40654
        32|      1681.9133      545.05078      177.45417
        33|      1532.4968      519.17845      167.81145
        34|       1396.354      497.18977      159.32199
        35|      1272.3058      478.47059      151.84907  ^
        36|      1159.2776        462.507      145.27259
        37|      1056.2906       448.8687      139.48664
        38|      962.45264       437.1951      134.39758
        39|        876.951       427.1838      129.92244
        40|      799.04509      418.58096       125.9877
        41|      728.06013      411.17333      122.52817
        42|      663.38127      404.78156      119.48615
        43|      604.44831      399.25467      116.81057
        44|      550.75079      394.46537      114.45638
        45|      501.82361      390.30629      112.38385
        46|      457.24298      386.68666      110.55804
        47|      416.62277      383.52972       108.9483
        48|      379.61115      380.77038      107.52773
        49|      345.88755      378.35345      106.27284
        50|      315.15985      377.24088      105.38259  *
        51|      287.16192      382.01408      105.95963
        52|      261.65124      389.65489       107.7111
        53|      238.40687      396.94246      110.12192
        54|      217.22746      398.32045       111.7516
        55|      197.92957      399.72318      113.59134
        56|      180.34605      401.75368      115.49682
        57|      164.32461      404.46026       117.3465
        58|      149.72646      405.28304      118.73463
        59|      136.42518       405.2511       120.1721
        60|      124.30554       405.2761      121.62263
        61|      113.26258      403.59011      122.41581
        62|      103.20064      401.82587      122.98928
        63|      94.032582      402.94599      124.26148
        64|      85.678986      404.20592      125.21789
        65|      78.067501      403.68408      125.62712
        66|        71.1322      400.91215      125.64499
        67|      64.813011       398.9517      126.02457
        68|      59.055202      397.76927      126.60418
        69|        53.8089      396.84309      127.16789
        70|      49.028666      395.36465      127.77929
        71|      44.673094      392.86311      128.06788
        72|       40.70446      391.49788      128.48992
        73|      37.088388      391.07007      129.00451
        74|      33.793558      392.16177      129.49754
        75|      30.791431      395.08297      129.54637
        76|      28.056005      398.32513      129.52706
        77|      25.563587      401.15399      129.44648
        78|      23.292588      403.24593      129.10851
        79|      21.223339      405.54289      128.94792
        80|      19.337916      409.33005      129.52204
        81|      17.619989      414.58054      130.50225
        82|      16.054678      423.29174      131.10197
        83|      14.628424      431.51624      130.67818
        84|      13.328875      436.86415      129.31034
        85|      12.144775      440.37741      128.09369
        86|      11.065867      442.49849      127.09852
        87|      10.082806      444.85132      126.41494
        88|      9.1870769      447.34397      125.97551
        89|      8.3709223       449.9048      125.72547
        90|      7.6272726      452.47857      125.62067
        91|      6.9496867      455.02332      125.62572
        92|      6.3322957      457.50773      125.71243
        93|       5.769752      459.90901      125.85849
        94|      5.2571831      462.21121      126.04634
        95|      4.7901495      464.40372      126.26225
        96|      4.3646058      466.48019      126.49555
        97|      3.9768663      468.43756      126.73804
        98|      3.6235724      470.27531      126.98348
        99|      3.3016642      471.99485      127.22718
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=20.27 20:22:44

. // we should have 144-130-1=14 folds
. assert 13==`e(nfolds)'
r; t=0.00 20:22:44

.
. cvlasso air L(1/12).air, rolling origin(130) fixedwin
Rolling forecasting cross-validation with 1-step ahead forecasts. Elastic net with alpha=1.
Training from-to (validation point): 13-130 (131), 14-131 (132), 15-132 (133), 16-133 (134), 17-134 (135), 18-135 (136), 19-136 (137), 20-137 (138), 21-138 (139), 22-139 (140), 23-140 (141), 24-141 (142), 25-142 (143), 26-143 (144).
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      30083.535      29342.536      7604.6329
         2|      27410.996      24556.677      6355.4314
         3|      24975.879       20570.95      5316.2899
         4|      22757.091      17250.611      4451.7039
         5|      20735.414      14483.694      3732.1806
         6|      18893.337      12177.154      3133.2195
         7|      17214.905      10253.662       2634.466
         8|       15685.58      8648.9434      2219.0087
         9|      14292.116      7309.5692      1872.7961
        10|      13022.444      6191.1202      1584.1517
        11|      11865.566      5256.6626      1343.3724
        12|      10811.462      4475.4822      1142.3943
        13|      9851.0014      3822.0328      974.51561
        14|      8975.8656      3272.4349      844.16278
        15|      8178.4744      2805.5335      735.84716
        16|      7451.9213      2415.5597       645.3886
        17|      6789.9131      2089.5994      569.63807
        18|       6186.716      1816.9795      505.97842
        19|      5637.1052      1588.8216      452.25745
        20|      5136.3203      1397.7387       406.7116
        21|      4680.0237       1237.584      367.90116
        22|      4264.2633      1103.2409      334.65486
        23|      3885.4379      990.44955      306.02247
        24|      3540.2663       895.6626      281.23456
        25|      3225.7588      816.25649      259.59417
        26|      2939.1913      750.07662      240.58066
        27|      2678.0817      693.47635      223.73861
        28|      2440.1683      643.46868      208.49267
        29|      2223.3904       599.2883       194.5465
        30|      2025.8706      561.87629      182.29443
        31|      1845.8978       530.1486      171.52546
        32|      1681.9133      503.19944      162.05771
        33|      1532.4968      480.27153      153.73349
        34|       1396.354      460.73137      146.41531
        35|      1272.3058      444.04865      139.98272  ^
        36|      1159.2776       429.7791      134.32978
        37|      1056.2906      417.55025      129.36305
        38|      962.45264      407.04957      124.99996
        39|        876.951      398.01456      121.16748
        40|      799.04509      390.22455      117.80101
        41|      728.06013      383.49384      114.84345
        42|      663.38127      377.66597       112.2444
        43|      604.44831      372.60897      109.95941
        44|      550.75079      368.21137      107.94939
        45|      501.82361      364.37892      106.17998
        46|      457.24298      361.03178      104.62109
        47|      416.62277      358.10226      103.24635
        48|      379.61115      355.53282      102.03273
        49|      345.88755      353.27454      100.96014  *
        50|      315.15985      353.56351      100.54566
        51|      287.16192      358.15619      101.22159
        52|      261.65124      365.35705      102.96975
        53|      238.40687      369.66508      104.79961
        54|      217.22746      370.95016      106.38565
        55|      197.92957      372.74966      108.15476
        56|      180.34605      375.87984      109.75375
        57|      164.32461      378.13286      111.19205
        58|      149.72646      379.31752      112.39925
        59|      136.42518      379.96884      113.65128
        60|      124.30554      379.47216      114.64207
        61|      113.26258       378.6107       115.2831
        62|      103.20064      379.47067      116.07434
        63|      94.032582      380.87369      116.91882
        64|      85.678986      382.03715      117.67983
        65|      78.067501      380.53668      118.00548
        66|        71.1322        377.904       117.9601
        67|      64.813011      376.68599      118.51554
        68|      59.055202      376.04184       118.9979
        69|        53.8089      375.66725      119.47501
        70|      49.028666      374.18355      120.01102
        71|      44.673094      372.68744      120.23184
        72|       40.70446      372.63602      120.62715
        73|      37.088388      372.96002      120.98856
        74|      33.793558      375.67225       121.2765
        75|      30.791431      379.83266      121.13771
        76|      28.056005      383.96921      121.02467
        77|      25.563587      387.82565      120.59418
        78|      23.292588      391.20473      120.20296
        79|      21.223339      395.06233      120.19574
        80|      19.337916      400.12432      120.81217
        81|      17.619989       408.9831      121.88139
        82|      16.054678      419.70456      122.19761
        83|      14.628424      427.29042      121.84983
        84|      13.328875      432.32449      120.51138
        85|      12.144775      434.70003      119.27437
        86|      11.065867      437.29344       118.3797
        87|      10.082806      440.01255      117.75625
        88|      9.1870769      442.78574      117.34583
        89|      8.3709223      445.55799      117.10114
        90|      7.6272726      448.28774      116.98402
        91|      6.9496867      450.94415      116.96386
        92|      6.3322957      453.50503      117.01624
        93|       5.769752        455.955      117.12177
        94|      5.2571831      458.28413      117.26519
        95|      4.7901495      460.48672      117.43449
        96|      4.3646058      462.56036      117.62036
        97|      3.9768663      464.50518      117.81559
        98|      3.6235724      466.32322      118.01467
        99|      3.3016642      468.01793      118.21343
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=21.95 20:23:06

. assert 14==`e(nfolds)'
r; t=0.00 20:23:06

.
. ********************************************************************************
. *** panel example
. ********************************************************************************
.
. use "http://fmwww.bc.edu/ec-p/data/macro/abdata.dta", clear
(Layard & Nickell, Unemployment in Britain, Economica 53, 1986 from Ox dist)
r; t=0.84 20:23:07

.
. // FE and noftools options
. cvlasso ys l(0/3).k l(0/3).n, fe seed(123)

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      46.945458      .00843492      .00058496
         2|      42.774952      .00813196       .0005897
         3|      38.974944      .00773276      .00056315
         4|      35.512517      .00737473      .00053581
         5|      32.357683      .00706573       .0005092
         6|      29.483116       .0068078       .0004852
         7|      26.863917      .00659238       .0004636
         8|        24.4774      .00641237      .00044421
         9|      22.302896      .00626186      .00042685
        10|      20.321568      .00613594      .00041134
        11|      18.516256      .00603053      .00039754
        12|      16.871323       .0059422      .00038527
        13|      15.372521      .00586815      .00037439
        14|      14.006868      .00580767      .00036394
        15|      12.762537      .00575894      .00035376
        16|      11.628748      .00571635      .00034367
        17|      10.595682      .00567365      .00033312
        18|      9.6543911      .00563169      .00032285
        19|      8.7967216      .00558916      .00031273  ^
        20|      8.0152451      .00555189      .00030398
        21|      7.3031928      .00551614      .00029582
        22|      6.6543973       .0054842      .00028853
        23|       6.063239      .00545554      .00028109
        24|      5.5245976      .00543376      .00027373
        25|      5.0338075      .00541646      .00026706
        26|      4.5866179      .00540234      .00026121
        27|      4.1791554      .00539083      .00025608
        28|      3.8078908      .00538147      .00025161
        29|      3.4696083      .00537447      .00024786
        30|      3.1613778      .00536953      .00024474
        31|      2.8805297      .00536569      .00024204
        32|      2.6246314      .00536274       .0002397
        33|      2.3914664      .00536129      .00023773
        34|      2.1790151       .0053607      .00023603
        35|      1.9854374      .00536049      .00023456  *
        36|      1.8090566       .0053616      .00023354
        37|       1.648345      .00536378      .00023229
        38|      1.5019106      .00536851      .00023011
        39|       1.368485       .0053741      .00022843
        40|      1.2469126      .00537969      .00022697
        41|      1.1361403      .00538588      .00022581
        42|      1.0352087      .00539219      .00022482
        43|      .94324363      .00539811      .00022394
        44|      .85944846      .00540365      .00022315
        45|      .78309743      .00540967      .00022263
        46|      .71352921       .0054163      .00022214
        47|      .65014124      .00542284      .00022161
        48|      .59238449      .00542904      .00022113
        49|      .53975868      .00543495      .00022071
        50|      .49180801      .00544044      .00022032
        51|      .44811714      .00544564      .00021997
        52|      .40830765      .00545055      .00021963
        53|      .37203472        .005455      .00021921
        54|      .33898418      .00545904      .00021881
        55|      .30886976       .0054628      .00021846
        56|      .28143062       .0054662      .00021811
        57|       .2564291      .00546937      .00021779
        58|      .23364865      .00547234      .00021749
        59|      .21289195      .00547504      .00021723
        60|      .19397921      .00547749        .000217
        61|      .17674663      .00547977       .0002168
        62|      .16104495      .00548186      .00021661
        63|      .14673816      .00548379      .00021644
        64|      .13370235      .00548544      .00021626
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=1.54 20:23:09

. savedresults save ftools e()
r; t=0.01 20:23:09

. cap noi assert "`e(noftools)'"==""  // will be error if ftools not installed
r; t=0.00 20:23:09

. cvlasso ys l(0/3).k l(0/3).n, fe seed(123) noftools

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      46.945458      .00843492      .00058496
         2|      42.774952      .00813196       .0005897
         3|      38.974944      .00773276      .00056315
         4|      35.512517      .00737473      .00053581
         5|      32.357683      .00706573       .0005092
         6|      29.483116       .0068078       .0004852
         7|      26.863917      .00659238       .0004636
         8|        24.4774      .00641237      .00044421
         9|      22.302896      .00626186      .00042685
        10|      20.321568      .00613594      .00041134
        11|      18.516256      .00603053      .00039754
        12|      16.871323       .0059422      .00038527
        13|      15.372521      .00586815      .00037439
        14|      14.006868      .00580767      .00036394
        15|      12.762537      .00575894      .00035376
        16|      11.628748      .00571635      .00034367
        17|      10.595682      .00567365      .00033312
        18|      9.6543911      .00563169      .00032285
        19|      8.7967216      .00558916      .00031273  ^
        20|      8.0152451      .00555189      .00030398
        21|      7.3031928      .00551614      .00029582
        22|      6.6543973       .0054842      .00028853
        23|       6.063239      .00545554      .00028109
        24|      5.5245976      .00543376      .00027373
        25|      5.0338075      .00541646      .00026706
        26|      4.5866179      .00540234      .00026121
        27|      4.1791554      .00539083      .00025608
        28|      3.8078908      .00538147      .00025161
        29|      3.4696083      .00537447      .00024786
        30|      3.1613778      .00536953      .00024474
        31|      2.8805297      .00536569      .00024204
        32|      2.6246314      .00536274       .0002397
        33|      2.3914664      .00536129      .00023773
        34|      2.1790151       .0053607      .00023603
        35|      1.9854374      .00536049      .00023456  *
        36|      1.8090566       .0053616      .00023354
        37|       1.648345      .00536378      .00023229
        38|      1.5019106      .00536851      .00023011
        39|       1.368485       .0053741      .00022843
        40|      1.2469126      .00537969      .00022697
        41|      1.1361403      .00538588      .00022581
        42|      1.0352087      .00539219      .00022482
        43|      .94324363      .00539811      .00022394
        44|      .85944846      .00540365      .00022315
        45|      .78309743      .00540967      .00022263
        46|      .71352921       .0054163      .00022214
        47|      .65014124      .00542284      .00022161
        48|      .59238449      .00542904      .00022113
        49|      .53975868      .00543495      .00022071
        50|      .49180801      .00544044      .00022032
        51|      .44811714      .00544564      .00021997
        52|      .40830765      .00545055      .00021963
        53|      .37203472        .005455      .00021921
        54|      .33898418      .00545904      .00021881
        55|      .30886976       .0054628      .00021846
        56|      .28143062       .0054662      .00021811
        57|       .2564291      .00546937      .00021779
        58|      .23364865      .00547234      .00021749
        59|      .21289195      .00547504      .00021723
        60|      .19397921      .00547749        .000217
        61|      .17674663      .00547977       .0002168
        62|      .16104495      .00548186      .00021661
        63|      .14673816      .00548379      .00021644
        64|      .13370235      .00548544      .00021626
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
r; t=0.99 20:23:10

. assert "`e(noftools)'"=="noftools"
r; t=0.00 20:23:10

. savedresults comp ftools e(), exclude(macros: lasso2opt)
r; t=0.00 20:23:10

.
. ********************************************************************************
. ***  check residuals with fe                                                                                             ***
. ********************************************************************************
.
. clear
r; t=0.00 20:23:10

. use https://www.stata-press.com/data/r16/nlswork
(National Longitudinal Survey.  Young Women 14-26 years of age in 1968)
r; t=2.75 20:23:12

.
. replace ln_w = . if year == 80
(1,847 real changes made, 1,847 to missing)
r; t=0.00 20:23:12

.
. cvlasso ln_w grade age c.age#c.age ttl_exp c.ttl_exp#c.ttl_exp tenure ///
>                 c.tenure#c.tenure 2.race not_smsa south , fe

K-fold cross-validation with 10 folds. Elastic net with alpha=1.
Fold 1 2 3 4 5 6 7 8 9 10
          |         Lambda           MSPE       st. dev.
----------+---------------------------------------------
         1|      5773.8216      .19856956       .0049488
         2|      5260.8912      .19510395        .004921
         3|      4793.5281      .19181949      .00489047
         4|      4367.6843      .18901926      .00486368
         5|      3979.6712      .18662756      .00484006
         6|      3626.1282      .18458098      .00481916
         7|       3303.993      .18282633       .0048006
         8|      3010.4753      .18130821      .00478317
         9|       2743.033      .17993596        .004778
        10|      2499.3495      .17872966      .00477046
        11|      2277.3142      .17769003      .00476308
        12|      2075.0039      .17679373      .00475651
        13|      1890.6663      .17601938      .00475064
        14|      1722.7047      .17534895      .00474538
        15|      1569.6643      .17476725      .00474066
        16|      1430.2197      .17426144      .00473641
        17|      1303.1629      .17382067      .00473259
        18|      1187.3935      .17343575      .00472914
        19|      1081.9087      .17309888      .00472603
        20|      985.79495      .17280815      .00472298
        21|      898.21965      .17259251      .00472315
        22|      818.42429       .1724332      .00472221
        23|      745.71773      .17229934      .00471979
        24|      679.47022      .17218835      .00471767
        25|      619.10796      .17211746      .00471512
        26|      564.10812      .17210271      .00471632
        27|      513.99431      .17214254      .00471385
        28|      468.33247      .17222045      .00471808
        29|       426.7271      .17227965      .00472539
        30|      388.81784      .17192789       .0047269
        31|      354.27634      .17159449      .00471671
        32|       322.8034      .17131531      .00470748
        33|      294.12644      .17108137      .00469911
        34|      267.99706      .17088517      .00469151
        35|      244.18894      .17072048      .00468461
        36|      222.49586      .17058212      .00467835
        37|      202.72995      .17047156      .00467551
        38|      184.71998      .17057963      .00469366
        39|      168.30996      .17091839      .00471443
        40|      153.35777      .17124862      .00473513
        41|      139.73389      .17156271      .00475412
        42|      127.32031      .17185986      .00477153
        43|      116.00953       .1721397      .00478749
        44|      105.70356      .17240223      .00480211
        45|      96.313148      .17264771       .0048155
        46|      87.756954      .17287589      .00482755
        47|      79.960868      .17308128      .00483868
        48|      72.857365      .17325719      .00484798
        49|      66.384917      .17300192      .00484978
        50|      60.487464      .16975386      .00474188
        51|      55.113925      .16663803      .00459007
        52|      50.217755      .16390797      .00446813
        53|      45.756548      .16151347      .00436426
        54|      41.691663      .15941168      .00426958
        55|       37.98789      .15754081      .00418546
        56|      34.613151        .155927      .00410732
        57|      31.538214      .15449554      .00404327
        58|      28.736446      .15321279      .00398651
        59|      26.183579      .15206188      .00393612
        60|      23.857502      .15102807      .00389131
        61|      21.738068      .15009843      .00385139
        62|      19.806918      .14927115      .00381774
        63|      18.047326      .14852849      .00378817
        64|      16.444051      .14785866      .00376163
        65|      14.983207      .14725404      .00373777
        66|       13.65214      .14668285      .00372168
        67|      12.439321      .14613422      .00370749
        68|      11.334246      .14561919      .00368416  ^
        69|      10.327343      .14511215      .00366867
        70|      9.4098905      .14465224      .00365593
        71|      8.5739418       .1442048      .00364741
        72|      7.8122564      .14377088      .00363502
        73|      7.1182371      .14337589      .00362281
        74|      6.4858725      .14301825      .00361182
        75|      5.9096855      .14269424      .00360191
        76|      5.3846853      .14240058      .00359296
        77|      4.9063247      .14213084      .00358412  *
* lopt = the lambda that minimizes MSPE.
  Run model: cvlasso, lopt


^ lse = largest lambda for which MSPE is within one standard error of the minimal MSPE.


  Run model: cvlasso, lse
Warning: lopt is at the limit of the lambda range.
r; t=19.73 20:23:32

. cvlasso, lse postres ols
Estimate lasso with lambda=11.334 (lse).

------------------+--------------------------------
         Selected |           Lasso   Post-est OLS
------------------+--------------------------------
              age |       0.0276373      0.0330033
                  |
      c.age#c.age |      -0.0005866     -0.0006806
                  |
          ttl_exp |       0.0367445      0.0372828
           tenure |       0.0356436      0.0357082
                  |
c.tenure#c.tenure |      -0.0019053     -0.0019142
                  |
         not_smsa |      -0.0892079     -0.0899220
            south |      -0.0597044     -0.0605564
------------------+--------------------------------
r; t=0.34 20:23:32

.
. local sel = e(selected)
r; t=0.00 20:23:32

. di "`sel'"
age c.age#c.age ttl_exp tenure c.tenure#c.tenure not_smsa south
r; t=0.00 20:23:32

.
. predict double uehat  , ue noi
Use e(b) from previous lasso2 estimation (lambda=11.33424642913).
(2,253 missing values generated)
Beta used for predict:
                     c.age#                           c.tenure#
           age       c.age     ttl_exp      tenure    c.tenure    not_smsa
y1    .0330033  -.00068058   .03728278    .0357082  -.00191421  -.08992203


         south
y1  -.06055644
r; t=0.08 20:23:32

. predict double ehat  , e noi
Use e(b) from previous lasso2 estimation (lambda=11.33424642913).
(2,255 missing values generated)
Beta used for predict:
                     c.age#                           c.tenure#
           age       c.age     ttl_exp      tenure    c.tenure    not_smsa
y1    .0330033  -.00068058   .03728278    .0357082  -.00191421  -.08992203


         south
y1  -.06055644
r; t=0.10 20:23:33

. predict double xbhat  , xb noi
Use e(b) from previous lasso2 estimation (lambda=11.33424642913).
(441 missing values generated)
Beta used for predict:
                     c.age#                           c.tenure#
           age       c.age     ttl_exp      tenure    c.tenure    not_smsa
y1    .0330033  -.00068058   .03728278    .0357082  -.00191421  -.08992203


         south
y1  -.06055644
r; t=0.07 20:23:33

. predict double xbuhat  , xbu noi
Use e(b) from previous lasso2 estimation (lambda=11.33424642913).
(2,255 missing values generated)
Beta used for predict:
                     c.age#                           c.tenure#
           age       c.age     ttl_exp      tenure    c.tenure    not_smsa
y1    .0330033  -.00068058   .03728278    .0357082  -.00191421  -.08992203


         south
y1  -.06055644
r; t=0.10 20:23:33

. predict double uhat  , u noi
Use e(b) from previous lasso2 estimation (lambda=11.33424642913).
(2,255 missing values generated)
Beta used for predict:
                     c.age#                           c.tenure#
           age       c.age     ttl_exp      tenure    c.tenure    not_smsa
y1    .0330033  -.00068058   .03728278    .0357082  -.00191421  -.08992203


         south
y1  -.06055644
r; t=0.10 20:23:33

.
. xtreg ln_w `sel' if e(sample), fe

Fixed-effects (within) regression               Number of obs     =     26,279
Group variable: idcode                          Number of groups  =      4,686

R-sq:                                           Obs per group:
     within  = 0.1786                                         min =          1
     between = 0.3530                                         avg =        5.6
     overall = 0.2662                                         max =         14

                                                F(7,21586)        =     670.64
corr(u_i, Xb)  = 0.1930                         Prob > F          =     0.0000

-------------+----------------------------------------------------------------
      ln_wage |      Coef.    Std. Err.       t    P>|t|      [95% Con f. Interval]
-------------+----------------------------------------------------------------
         age |    .0330033    .0029458     11.20    0.000      .0272294     .0387772
             |
 c.age#c.age |   -.0006806    .0000487    -13.97    0.000     -.0007761    -.0005851
             |
     ttl_exp |    .0372828    .0015061     24.75    0.000      .0343307     .0402349
      tenure |    .0357082    .0017123     20.85    0.000       .032352     .0390644
             |
    c.tenure#|
    c.tenure |   -.0019142    .0001095    -17.47    0.000     -.0021289    -.0016995
             |
    not_smsa |    -.089922    .0099008     -9.08    0.000     -.1093284    -.0705157
       south |   -.0605564    .0114483     -5.29    0.000     -.0829959     -.038117
       _cons |    1.074643    .0433838     24.77    0.000      .9896076     1.159678
-------------+----------------------------------------------------------------
     sigma_u |  .35740248
     sigma_e |  .29207998
         rho |  .59956903   (fraction of variance due to u_i)
-------------+----------------------------------------------------------------
F test that all u_i=0: F(4685, 21586) = 6.23                 Prob > F = 0.0000
r; t=1.22 20:23:34

. mat bxtreg = e(b)
r; t=0.01 20:23:34

.
. predict double uehat_xtreg   , ue
(2,253 missing values generated)
r; t=0.02 20:23:34

. predict double ehat_xtreg   , e
(2,255 missing values generated)
r; t=0.15 20:23:34

. predict double xbhat_xtreg  , xb
(441 missing values generated)
r; t=0.01 20:23:34

. predict double xbuhat_xtreg  , xbu
(2,255 missing values generated)
r; t=0.13 20:23:34

. predict double uhat_xtreg  , u
(2,255 missing values generated)
r; t=0.13 20:23:35

.
. assert abs(ehat_xtreg-ehat)<10e-8 | (missing(ehat_xtreg) | missing(ehat))
r; t=0.01 20:23:35

. assert abs(uehat_xtreg-uehat)<10e-8 | (missing(uehat_xtreg) | missing(uehat))
r; t=0.01 20:23:35

. assert abs(xbhat_xtreg-xbhat)<10e-8 | (missing(xbhat_xtreg) | missing(xbhat))
r; t=0.01 20:23:35

. assert abs(xbuhat_xtreg-xbuhat)<10e-8 | (missing(xbuhat_xtreg) | missing(xbuhat))
r; t=0.01 20:23:35

. assert abs(uhat_xtreg-uhat)<10e-8 | (missing(uhat_xtreg) | missing(uhat))
r; t=0.01 20:23:35

.
.
. ********************************************************************************
. *** finish                                                                   ***
. ********************************************************************************
.
. cap log close