Is there a way to write a program definition such that the program uses both the name of a local macro and the content? I'd like to send a program any number of variables stored as a local macro, and then have some commands evaluated using the name of the local, and other commands evaluated for each variable that make up the value of the local.
Something like this:
I hope this is just one level of quote or backtick away from working, but feel free to tell me if there's a better way to do this where I can use the name of the list and each member of the list regardless of how many variables there are in said list.
Thanks!
Something like this:
Code:
sysuse auto, clear
cap program drop simple
program define simple
args listofvars
cap frame drop `listofvars'
frame create `listofvars'
frame `listofvars': set obs 5
frame `listofvars': gen mean=.
local i=1
foreach var of local ``listofvars'' {
summ `var'
frame `listofvars': replace mean=r(mean) in `i'
local i=`i'+1
}
end
local mylist price mpg headroom trunk
simple mylist
I hope this is just one level of quote or backtick away from working, but feel free to tell me if there's a better way to do this where I can use the name of the list and each member of the list regardless of how many variables there are in said list.
Thanks!

Comment