Variable list


I have named and labelled my variables so that I can see them under "variables" e.g A to Z. I would like to create a foreach command including only some of these variables.

If i write:

foreach var of varlist A-Z....

I will include all the variables A-Z.

Is it possible to create another separate list with only the variables I am interested in and then do the foreach command only for these variables?

OR is there a better way to do this?

Thank you!
Last edited:
Thank you for your reply.

Is there another way to do it? Since if you have many variables you would like to write them each time you want to make a foreach command.


Well you could store the variable list in a local macro:
local myvars="A B D M N Q"

foreach var of varlist `myvars' {
(do something...)

foreach var of varlist `myvars' {
(do something else...)
Is that what you mean?