Hello all,

I'm running several instances of a maximum likelihood routines in a first set of loops. In the second loop I'd only like to run the subset of instances that actually converged, rather than the full set that was run in the first loop. It seem like the solution would be based on setting a set of conditional locals, but I've tried a few attempts at this with no success. Below is some stylized code to show what I'm trying to accomplish. Ideally, this would log and then call every treatment-outcome combinations that converged, but it's sufficient to just log each treatment for which any outcome converged. I'm running this code over several groups, so any reduction in computer run time over the second set of loops will save me a lot of time. I'm sure my issue is with how I'm using embedded quotes.Thanks in advance for any guidance!

Code:
foreach treatment in aaaa bbbb cccc dddd eeee {
        foreach outcome in nnnn mmmm oooo pppp {
        
        [estimation code]

        local zzzz [...generate local/ add to local based on each treatment (ideally, each treatment-outcome combination) that converged using e(converged)]
}
}

foreach treatment of local zzzz {
        foreach outcome in nnnn mmmm oooo pppp {
        
        [estimation code]
}
}