Announcement

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

  • Saving a Matrix from the Predict Command

    I'm interested in saving a matrix generated by Mark Schaffer 's cvlasso from lassopack so that I may do other things with it. Here's my code
    Code:
    import delim "https://raw.githubusercontent.com/synth-inference/synthdid/master/data/california_prop99.csv", clear
    qui {
    egen id = group(state) // makes a unique ID
    
    xtset id year, y // We now have yearly panel data
    
    drop state treated // irrelevant for our purposes
    
    rename packs sale // I didn't like the original variable name
    
    greshape wide sale, j(id) i( year) // Note that I use greshape, but feel free to use normal reshape
    tsset year, y
    
    loc stub sale
    }
    qui cvlasso `stub'3 sale1 sale2 sale4-sale39 if year < 1989, roll h(2) lglmnet
    predict cf, lse noi
    As we can see, the predict command (when the noisy option is specified anyways) returns the predictors of interest. How might I save this matrix into another matrix, Matrix A for example, such that I can
    Code:
    mat l A
    and it spits these betas back at me. I'm familiar with using matrices generated by I guess what we'd call "normal" estimation commands, but I've never had to do this with the predict command. Any ideas on how I'd do this?

  • #2

    Last edited by William Lisowski; 01 Apr 2022, 19:21. Reason: Withdrawn, misunderstood question

    Comment


    • #3
      I dont think you can.
      I just tried your example, and I didn't see any information left out by predict.
      Thus, I imagine there are 2 options.
      1) contact the author and ask him to "save" the matrix somewhere it can be recovered
      2) create a pseudo version of his command, and hack it so the preferred beta matrix is saved somewhere

      For instance, if you look into lasso_p.ado one line in the code says
      Code:
                      if ("`ols'"=="") {
                              di as text "Use e(b) from previous lasso2 estimation (lambda=`lambda')."
                              mat `betaused' = e(b)
                      }
                      else {
                              di as text "Use e(betaOLS) from previous lasso2 estimation (lambda=`lambda')."
                              mat `betaused' = e(betaOLS)
                      }
      So you could add an added condition of storing this in another matrix (not a temporary one).

      Comment


      • #4
        I was hoping I could use the collect prefix to do it somehow... but if push comes to shove, I'll edit it

        Comment

        Working...
        X