Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: Difficulties iterating over a do-file within a foreach loop

From   Michael Housman <>
To   "" <>
Subject   st: RE: Difficulties iterating over a do-file within a foreach loop
Date   Tue, 12 Jun 2012 23:50:23 +0000

Hi folks,

Long time listener, first time caller.  I was wondering if you guys could help me with something that I'm trying to do.

I've developed code that engages in a long, involved analysis of different performance metrics that we've collecting for employees.  For example, we want to look at things like schedule adherence, quality assurance, absenteeism, customer satisfaction, etc.

What I'd like to do is use a foreach statement and then run a loop that will select a metric, call a certain do-file, run the code in that do-file, and then select another metric do this all over again until we've gotten through each of the metrics.  Here's an idea of what I have in mind:

foreach metric in schedule_adherence quality_assurance absenteeism customer_satisfaction {
              do "C:\Filepath\Do"

The problem that I've run into is that this will work exactly once.  It select the first metric, runs the do-file, and then the program ends once it reaches the end of the do-file.

Has anyone run into this problem before?  Is there something that I'm doing wrong?  Perhaps this has something to do with the fact that there's a "clear" command at the top of the do-file that it calls before it imports a dataset?

Thanks in advance for your help!


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index