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
Catplot column percentageHello all, I am trying to produce a vertical bar graph using 3 categorical variables: 1. numeracy …
How to calculate Jagadeesh and Titman (1993) momentum strategies in STATAI am a PhD student and working on JT(1993) momentum strategies. I am looking for a code in STATA to …
Firpo, Fortin and Lemieux methodology- recentered influence function and oaxaca decompositionDear all, I want to use the methodology defined by Firpo, Fortin and Lemieux in paper Decomposing w…
How to make group-level variable?Hello, I want to do multilevel analysis - and I have encountered a problem. I want to do an analysis…
Panel Probit/Logit Regression and time dummies- What to use?Hi all, I'm interested in running a probability model but I have some questions regarding with the …
Subscribe to:
Post Comments (Atom)
0 Response to Estimates Restore with Lasso - "no observations" error
Post a Comment