Dear all,

I have been struggling with the
Code:
foreach
command for the following task:

Code:
local Obv profit hkgovsme_result marketing sale_no moti_self
local Sbv sex fail hkgovsme_app intelp esale fund_no esale_eu esale_none sale_no sorted_nation
local Ocv num_busp ft pt gba_ft ebus_12m
local Scv yr_bus pt num_busp buscha_uncertain hkgovsme gba_busyr

foreach T of newlist Sb Sc{
foreach n of local `T'v{
local label: variable label `n'
graph hbar, ///
over(`n') over(tech) ///
stack percent ///
asyvars ///
blabel(bar, position(center) format(%9.0f) color(white) size(2.5)) ///
legend(r(1) size(2)) ///
yline(50)  ///
ytitle("%") ///
b1title("`label'") ///
note("Conditional observation: Startups")

graph export `add'\`T'v_`n'.png, replace
}
}

foreach T of newlist Ob Oc{
foreach n of local `T'v{
local label: variable label `n'
graph hbar, ///
over(`n') over(startup) ///
stack percent ///
asyvars ///
blabel(bar, position(center) format(%9.0f) color(white) size(2.5)) ///
legend(r(1) size(2)) ///
yline(50)  ///
ytitle("%") ///
b1title("`label'") ///
note("Conditional observation: ALL")

graph export `add'\`T'v_`n'.png, replace
}
}
As you may notice, the only difference between the two -foreach- is the following
  1. objects in -newlist(.)-: Sb, Sc and Ob, Oc
  2. the variables in the - over(.)-: tech, startup
I would like to know if there is any more elegant way to get the same result? I encounter and struggle the similar problem often

Thank you