Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • return code r(9611) as ado file but not as do file

    Hi Stata listers

    Looking for insight into an odd error. The file below runs correctly when executed as a do from a do file window but returns

    r(9611)

    OR

    foreach ifs1 in `if1' {
    program 0while already defined
    r(110);
    r(110);

    interchangeably when run as an ado file. The include command calls another do file which uses the locals (strv indv etc)

    In the code I migrated the globals to locals from user input to splice with the existing code of the included do file and also to try and weed out the problem if it was related to global and local issues.

    The included do file is not buggy and has worked for several months properly so I don't suspect that.
    My hunch is that it is something to do with the translation from global to local and that the ado vs do execution has some subtle difference in the referencing of these macros?

    Any insight would be appreciated.

    cheers

    Darren


    ************************************************** *************************************************

    program cubeit

    clear
    macro drop _all

    display"Enter Dataset type Adult=1 Child=2: "_request(rdstyp)
    display"Enter dataset year: "_request(rdsyr)
    display"Enter weight variable: "_request(rwtvar)
    display"Enter categorical=1 or continuous=2 variables: "_request(rcatcon)
    display"Enter vari list: "_request(rvaril)
    display"Enter strat list: "_request(rstratl)
    display"Enter if1 list (default is dumif): "_request(rif1l)
    display"Enter if2 list (default is dumif): "_request(rif2l)
    display"Enter if3 list (default is dumif): "_request(rif3l)
    display"Enter geographies: "_request(rgeogl)
    *migrate globals to locals and align names to the compiler code
    local strv $rstratl
    local indv $rvaril
    local if1 dumif $rif1l
    local if2 dumif $rif2l
    local if3 dumif $rif3l
    local dsyr $rdsyr
    local geov $rgeogl
    local date=c(current_date)
    local dstyp=$rdstyp
    local catcon=$rcatcon
    *+"_"+ c(current_time)

    macro list

    if `dstyp'==1 {
    use "Q:\STATA\Surveys\master_data\urfs\SRHS`dsyr'_Mast er", clear
    }
    *
    if `dstyp'==2 {
    use "Q:\STATA\Surveys\master_data\urfs\CHS`dsyr'_Maste r", clear
    }
    *
    svyset [pweight=$rwtvar]
    gen dumif=90
    gen state=300000
    label drop _all

    if `catcon'==1 {
    include "Q:\STATA\Surveys\est_db\CUBE 2.0\datacube\code\static_code\cube2compiler_catvar .do"
    }
    *
    if `catcon'==2 {
    include "Q:\STATA\Surveys\est_db\CUBE 2.0\datacube\code\static_code\cube2compiler_convar .do"
    }
    *
    if `dstyp'==1 {
    save "Q:\STATA\Surveys\est_db\cubecompiler\SRHS`dsyr'`d ate'"
    }
    *
    if `dstyp'==2 {
    save "Q:\STATA\Surveys\est_db\cubecompiler\CHS`dsyr'`da te'"
    }

    end
    exit


  • #2
    Use trace to identify where the program is failing:

    Code:
    set more off
    set trace on
    cubeit
    If the output is too verbose, set the depth of the trace much lower (2, 3, or 5):
    Code:
    set tracedepth 3
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      Thanks Carole

      I may have discovered the answer in the archive (below) And the trace function does show that the error triggers right at:

      foreach ifs1 in `if1' {
      program 0while already defined
      r(110);


      Very strange error. I will post if the suggested solution fixes the problem

      Darren

      __________________________________________________ _____________________________
      From "Brian Karfunkel" <[email protected]>
      To [email protected]
      Subject Re: st: Error r(9611)
      Date Fri, 17 Oct 2008 10:55:16 -0700


      In trying to find out precisely what was causing the problem, I made some vary simple test programs that sort of mimic the structure of my original program: there is -run_test.do-, which calls the other programs, -test_loop.do-, which just does a simple for-loop, and -run_program.ado-, which simply tries to run/do/include -test_loop.do- (see complete code below). Running -run_test.do- causes error r(9611) just like my original program, but it does not have the problem with modifying the loop variable in the loop (which is a problem for other reasons anyway, though, so thanks for catching it). What I have concluded from my tests is that the error is thrown when an ADO-file -INCLUDE-s a do-file with a loop (any kind, foreach, forvalues, or while). The error is thrown at the moment the loop in the DO-file starts. Note that including the loop itself in the ADO-file doesn't cause an error, nor does -run-ing or -do-ing the DO-file with the loop. Indeed, I have developed a work-around for my original problem by simply copying the code I was trying to -include- and pasting it in the ado-file itself; so the code in question works when literally in the ado-file but not when it is in a do-file that is -include-d in the ado-file. It seemed fishy how capricious the error was to me, so I tried it on another Windows machine and on a UNIX machine using Stata IC, both of which also threw the error. Thanks for everyone's help again. CODE:

      Comment


      • #4
        No banana, the same code that is refered to in the " include" causes the same problem when pasted into the "include" position in the code above. In this configuration the ado wont run at all and
        the r(9611) appears after you type "cubeit". The code at include "Q:\STATA\Surveys\est_db\CUBE 2.0\datacube\code\static_code\cube2compiler_catvar .do" is fine and runs fine from a do window (see attached code)

        Stumped....

        Any insights appreciated

        Darren
        Attached Files

        Comment


        • #5
          [P] error says

          9xxx. Various messages, all indicating an unexpected system failure. You should never see such a message. If one occurs, save your data, and exit Stata immediately. Please email [email protected] to report the problem.
          FWIW, I can't see any gain whatsoever from trying to convert this to a program. In various places you refer to a compiler but there is no Stata compiler. Your program would remain interpreted code even if it worked. As it wires in very specific details it's entirely appropriate as a .do file.
          Last edited by Nick Cox; 20 Apr 2016, 02:47.

          Comment


          • #6
            Perhaps try adding:

            Code:
             
            cap prog drop cubeit
            On the line immediately prior to the one with program cubeit on it. It could be an issue of the program still residing in memory without being dropped and reloaded.

            Comment


            • #7
              I think Stata is getting confused with file references. There is nothing in the program that seems to explain any reference to a program 0while and although I am speculating too the use of include is to me more suspicious. But you don't need to solve the problem. The do-file works fine as a do-file and recasting it as a program is pointless any way.

              Comment


              • #8
                Thanks Nick and Mr(?) Buchanan.

                I will give the drop cubeit command a go to se if it works. It makes sense that there is something in memory but I have completely re-booted stata and re run the program with the same outcome so only a little hopeful.

                Nick, I use the term compiler in a loose sense ( the code builds large blocks of estimates in Mata iteratively so I called it a compiler, probably a bad choice) .
                The r(9xxx) warning is concerning. I will follow your advice and save it as a .do. Using "include" in a program is warned against in the documentation too ( committing multiple crimes) .

                Thanks for your help and advice.

                Darren

                Comment


                • #9
                  Darren White since all of the parameters are passed interactively there isn't any reason to make it an .ado. If, however, users were asked to supply parameters on invocation it would be a bit different. Without knowing anything about the .do files that are being executed there isn't a ton that anyone could do to potentially help you refactor it into an executable program. In general, it seems that this isn't the best candidate for a program (e.g., highly specific script that calls other highly specific scripts). I'll generally avoid creating an .ado file when the use case is limited to only a single task (e.g., even if the task is running other specific tasks) and in a case like this would typically create a master .do file that I could use to selectively execute specific things.

                  Comment


                  • #10
                    Thanks Mr Buchanan. I will run it as an .do. And thanks for the programming tips.

                    Darren

                    Comment

                    Working...
                    X