I would like to add a variable to a global variable list only if they are not already included. I have a set of independent variables that I need to add one by one to a global "current" varlist. The code below adds the variable regardless if already included in the "current" variable list. I want to add the variable only if it is not already included. If already included, skip and add next one. Anyone knows how to modify the code below? Thanks.
Code:
* This is the CURRENT list of variables
global M3 "LogSize MOM12 DY MOM36 retvol Debt_Price Sales_Price mom1 rd_mve turn bm agr chatoia egr grCAPX grltnoa invest ROE CEI hire ChLTI ill TAN indmom idiovol nincr LogIssues36 ES divo Accruals_old chmom_old sgr pchsale_pchrect"
* Defining new models to test. Starting from model M5, M6...
local t 5
* Add one by one variables. I would like to incorporate a condition that skip the variable in this list if already included in the CURRENT list (M3) above:
local plus " ROA LogAG MOM6 Accruals_old Accruals LogIssues12 Beta StdDev Turnover cash chmom chnanalyst chcsho chinv grltnoa invest pchsale_pchinvt GP_A OP_BE NOA chmom_old grltnoa_old divi divo pchgm_pchsale pchsale_pchrect pctacc sgr ms OSc ChCOL ChNNCWC ChNNCOA ChNCOA ChNCOL ChLTI NWCCh AL stdev_turn_w turn_w"
foreach add in `plus' {
global M`t' $M3 `add'
di `t'
di "${M`t'}"
di "`add'"
local t = (`t' + 1)
}
0 Response to Add a variable to a global variable list only if it is not already included
Post a Comment