Hi everyone, I am trying to to in-sample and out of sample prediction with lasso. The following steps worked perfectly find with linear regression but not with lasso, so I wonder why this is the case and how I can solve it.
Step 1. Generate data
matrix def c = J(8,8,0)
matrix list c
forvalues i = 1/8{
forvalues j = 1/8{
local toaddin = 0.5^(abs(`i' - `j'))
matrix c[`i',`j'] = `toaddin'
}
}
set seed 12345
set obs 20
drawnorm x1 x2 x3 x4 x5 x6 x7 x8, cov(c)
gen e = rnormal(0,1)
gen y = 3*x1 + 1.5*x2 + 2*x5 + e
Step 2. Save the model
lasso2 y x1 x2 x3 x4 x5 x6 x7 x8
lasso2, lic(ebic)
estimates store regression3
Note: the insample prediction as the following works perfectly fine
predict yhat_lasso, residual lic(ebic)
gen yhat_lasso_2 = yhat_lasso^2
summ yhat_lasso_2
local yhat_lasso_2_mean = r(mean)
di `yhat_lasso_2_mean'
Step 3. Generate new data for out-of-sample prediction
drop _all
set seed 12345
set obs 1000
drawnorm x1 x2 x3 x4 x5 x6 x7 x8, cov(c)
gen e = rnormal(0,1)
gen y = 3*x1 + 1.5*x2 + 2*x5 + e
Step 4: Try to do out-of-sample prediction
set seed 12345
estimates restore regression3
ereturn list
predict yhat_lasso, residual lic(ebic)
Here is where the error message "No observation" comes out.
The ereturn list commend works well, which means the regression result has been successfully restored. So I am unsure why can't I predict again here?
Thanks everyone who tries to help!
Related Posts with Estimates Restore with Lasso - "no observations" error
mycolours package available on SSCThanks as always to Kit Baum who maintains SSC, a new package mycolours is available from SSC. The p…
problems creating a graph, diagram, etc.Hello, Creating a graph, a diagram etc. doesn't work in my Stata program. The small box, that usuall…
Error using xtreg - r(2000) "No observations"Hello, I am trying to perform a lagged regression on a panel dataset, using xtreg. I get the error …
Choice model margins problem: margins after cmclogit producing _outcome#altDear all, I am using data from a choice experiment with an unbalanced panel of 2-3 alternatives per…
How to get to a balanced panel from weakly balanced panel?Hi, I working with individual data for two rounds- 2005 and 2012. I have accounted for attrition an…
Subscribe to:
Post Comments (Atom)
0 Response to Estimates Restore with Lasso - "no observations" error
Post a Comment