Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 65584

Identifying and storing the iteration number in a FOREACH loop

$
0
0
Hello,

I'd like to set a conditional statement based on the first iteration of a FOREACH loop. I am not sure how to identify and store that indexed count, and currently the condition is hard-coded based on the first variable listed in the macro, instead of dynamically based on the first loop.


local logvars = "f_hdl f_a1c f_race"
foreach var in `logvars' {

.....

graph export "${prog}gph_`var'.tif", replace
graph save `var'.gph,replace
gr export temp.png, height(450) width(600) replace
if `var' == f_hdl {//I'd like to replace this with a index count = 1
png2rtf using 05_diagnostic_plots.doc, g(temp.png) replace
}
else {
png2rtf using 05_diagnostic_plots.doc, g(temp.png) append

....
}
Guidance would be appreciated.

Thank you!
Preeti

Viewing all articles
Browse latest Browse all 65584

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>