I have already asked a question how to check for a variable's existence. Nick Cox answered it. Then I tried to modify the answer and to use a foreach
loop, but it did not work:
foreach var in var1 var2 var3 {
capture su `var', meanonly
if _rc == 0 {
local varMean = r(mean)
local varMin = r(min)
local varMax = r(max)
}
else display `var' "DOES NOT EXIST"
}
I also tried to use of
instead of in
...still no result. I get a message var2 not found
and it stops executing. Does capture
have to prefix the foreach
? I tried that...did not work?