Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

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


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Difficulties iterating over a do-file within a foreach loop
Date   Wed, 13 Jun 2012 01:36:47 +0100

Nothing in your code passes the argument of -foreach- to the do-file.
However, I don't see that it will work as you say. Rather, the same
stuff should be repeated four times. I'd learn about passing arguments
to do-files.

However, if your real code does not have the form that you give as an
example, then my reply is that your question is too schematic to allow
me to give a detailed answer.

Nick

On Wed, Jun 13, 2012 at 12:50 AM, Michael Housman
<mhousman@evolvondemand.com> wrote:

> 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 File.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?

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index