Statalist


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

Re: st: Error r(9611)


From   [email protected] (William Gould, StataCorp LP)
To   [email protected]
Subject   Re: st: Error r(9611)
Date   Fri, 17 Oct 2008 11:23:52 -0500

Brian Karfunkel <[email protected]> reports, "I'm getting a weird error,
-r(9611)-, when I run my program."  Brian quoted about 50 lines of code.

I beleive I have uncovered the problem.  In Code Block 1, Brian has 
the following 

        foreach var of varlist `model_varlist' {
                ...
                if (...) {
                        local model_varlist "`model_varlist' ..."
                }
        }

To wit, Brian changes the contents of the macro controlling the 
loop, `model_varlist', in the body of the loop.

That is not allowed.  It is not allowed in any of the syntactical 
variants of -foreach-, including -foreach ... of varlist-, 
-foreach ... of local-, ..., or -foreach ... in-.  It is not allowed
for speed-of-execution reasons.

One way to code what Michael wants to do is 
        
        local i = 1
        local var : word `i' of `model_varlist'
        while ("`var'"!="") {
                ...
                if (...) {
                        local model_varlist "`model_varlist' ..."
                }
                local var : word `++i' of `model_varlist'
        }

By the way, another way of coding 

                local var : word `++i' of `model_varlist'

is 

                local i = `i' + 1
                local var : word `i' of `model_varlist'


-- Bill
[email protected]
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index