Announcement

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

  • Getting selected variables from cvlasso

    My read of "help cvlasso" is that e(varXmodel) should contain only variables chosen by cvlasso. However, it keep returning all of the variables, despite only a subset being chosen. Example of issue below (meaningly empirical example). Has anyone experienced this? Alternatively, does anyone have another way to get the selected variables (to be used elsewhere as variables in a regression)?

    Thank you!

    CODE:
    local coeffs "total_duration max_duration tmmx tmmn vs sph pr mvs_10m snwd_s snow_s awnd_s wsf2_s wsf5_s"

    local conditions "fe nf(5) lc(150) seed(1234)"

    local sv "lse"
    local estsample_dum "year>2015&year<2021&rand<=.8"

    cvlasso cmi_dum `coeffs', `conditions' `sv', if `estsample_dum'&rand<.1


    RESULTS:
    K-fold cross-validation with 5 folds. Elastic net with alpha=1.
    Fold 1 2 3 4 5
    | Lambda MSPE st. dev.
    ----------+---------------------------------------------
    1| 5380.1722 .06756452 .00049734
    ...cut...
    14| 2408.8119 .06663226 .00047482 ^
    ...cut...
    88| 24.84424 .06617284 .00047316 *
    ...cut...
    * 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=2408.812 (lse).

    ---------------------------------------------------
    Selected | Lasso Post-est OLS
    ------------------+--------------------------------
    max_duration | 0.0437135 0.0838706
    vs | 0.0008427 0.0071744
    sph | 1.5681662 4.9519355
    wsf5_s | 0.0003178 0.0003982
    ---------------------------------------------------


    . dis e(varXmodel)
    total_duration max_duration tmmx tmmn vs sph pr mvs_10m snwd_s snow_s awnd_s wsf2_s wsf5_s

    . dis e(varX)
    total_duration max_duration tmmx tmmn vs sph pr mvs_10m snwd_s snow_s awnd_s wsf2_s wsf5_s

    . dis e(partial)
    .



  • #2
    I've had this problem too. In fact, it is a quintessential problem faced by my command which uses cvlasso. What you are interested in however is the post estimation predict command
    Code:
    predict preds, lse

    Comment


    • #3
      Unfortunately, I am having lots of issues with predict and cvlasso. For one, I'm convinced the ols subcommand isn't doing ols. Second, I often get errors like:

      . predict cmi_pred_lopt, lopt ols
      No xb or residuals options specified. Assume xb (fitted values).
      Use e(betaOLS) from previous lasso2 estimation (lambda=20793.05904734).
      variable c1 not found
      r(111);

      . predict cmi_pred_lopt, lopt
      No xb or residuals options specified. Assume xb (fitted values).
      Use e(b) from previous lasso2 estimation (lambda=20793.05904734).
      conformability error
      r(503);

      Comment


      • #4
        Okay now, using the code delimiters please, show me the exact lasso you've tried a well as the predict command after.

        I'm convinced the ols subcommand isn't doing ols.
        Why are you convinced of this?

        Comment

        Working...
        X