I've tested it on the auto dataset with 3 iterations but the global list does not update. It seems the issue is when intersecting selected_vars with master_list (the part with the & operator). Is there a cleaner way to approach this? I tried making master_list a local but that produces an empty list as well. Thanks
Code:
sysuse auto.dta, clear
gl master_list ""
forvalues i = 1/3 {
** Subsample
set seed 2468
bsample
** Lasso
set seed 1357 // For cross-validation
lassoregress price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign
** Save selected variables
local selected_vars "`e(varlist_nonzero)'"
** Update Master with intersection
gl master_list: list master_list & selected_vars
local dropped: list master_list - selected_vars
local added: list selected_vars - master_list
di "Added variables: " " `added' "
di "Dropped variables: " " `dropped' "
di "Support: " " $master_list "
}
di " $master_list "
0 Response to Iteratively intersecting global and local lists
Post a Comment