How to keep a list of variables given some of them may not exist?
问题 I have 100 dta files. I have a list of variables that I need to keep and save temporary copies on the fly. Some variables may or may not exist in a certain dta . I need Stata to keep all variables that exist in a dta and ignore those that do not exist. The following code has wrong syntax, but it could serve as a good pseudo code to give one a general idea of what should be done: forval j = 1/100 { use data`j' local myVarList ="" foreach i of varlist var1 var2 var3 var4 var5 var6 var7 var8 {