Announcement

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

  • Program (that I wrote) acts as if clear command had been used instead of running fine

    Dear Statalisters,

    I have written an ado program for treatment effects evaluation which can compute 4 estimators called DID, CIC, TC and LQTE. These are specified via the wald_lqte( ) option. There can only be 4 variables entered in the varlist: the outcome variable y, the treatment group variable g, the period indicator t and the actual treatment indicator d, all in this specific order. My program has worked fine so far on the databases I tested it with, but I have just had an awkward (and serious) problem with a new dataset. When I try to run the program (all variables are numeric as required), it stops right at the beginning (at the syntax step), claims "variable y not found" and my Stata session clears the database I am using. Unfortunately I can neither give you the database (access restricted base) and my program is several thousands lines long. I can still give you the very beginning of my .ado so that you can perhaps spot some basic programming mistakes I made at the start of the program:

    /*do file command use:*/

    fuzzydid y g t d if t>=0, wald_lqte(DID)


    /*Ado file:*/

    clear all
    clear mata

    /**********************/
    /*Interface with users*/
    /**********************/

    quietly capture program drop fuzzyDID
    quietly program fuzzyDID, byable(recall) eclass sortpreserve


    version 12

    if replay() {
    if "‘e(cmd)'"!="wald_did" & "‘e(cmd)'"!="wald_tc" & ///
    "‘e(cmd)'"!="wald_cic" & "‘e(cmd)'"!="lqte" {
    error 301
    }
    else{
    syntax [, ‘options']
    }
    }

    else{

    syntax varlist(min=4 numeric) [if] [in] ///
    [, cluster(varlist numeric) yextrareg(varlist numeric) ///
    dextrareg(varlist numeric) ///
    LINEAR MOREOUTPUT CDFGRAPH TEST wald_lqte(namelist min=1 max=1) ///
    new_categ(numlist) ///
    bwidth_method(name) continuous(varlist numeric) discrete(varlist numeric) ///
    breps(numlist int>=2 max=1)]



    /*LONG PROGRAMMING BIT*/

    /*end of the program:*/

    ereturn local sample=`touse'

    }

    end




    N.B: I issue the e(cmd) variable within each subprogram.



    Thanks in advance and sorry for the lack of reproducible code and data!!!

    Yannick Guyonvarch

  • #2
    I do not understand the question. The very first command in your ado-file is

    clear all
    What did you expect Stata to do, but clear all?

    From the help file

    clear all and clear * are synonyms. They remove all data, value labels, matrices,
    scalars, constraints, clusters, saved results, sersets, and Mata functions and objects
    from memory. They also close all open files and postfiles, clear the class system, close
    any open Graph windows and dialog boxes, drop all programs from memory, and reset all
    timers to zero.
    Note that you should never ever include such lines of code in an ado-file that you intend to share with others.

    [Edit]
    Here is a guess why you might be irritated. Stata will clear all only the first time you call fuzzydid. This is because the program is not defined at this point in time. Stata finds fuzzydid.ado and runs that file - which wipes out everything, as you requested by typing clear all. The next time you call fuzzydid the program is already loaded into memory (given it has not been discarded or dropped since). Stata does not need to re-run fuzzydid.ado and, thus, does not clear all again. I hope this clarifies things.

    Note that capital letters in program names will get you into trouble when not using a Windows OS.
    [/Edit]

    Best
    Daniel
    Last edited by daniel klein; 14 Oct 2015, 08:36.

    Comment


    • #3
      Thanks a lot Daniel,

      That must seem really silly from an outside perspective but I forgot to remove those two lines when I changed my package from a do file to an ado file, and then I did not even consider the problem could stem from such an idiot mistake...

      Sorry about that post (it saved me a lot of time of useless debugging though)! ^^

      Comment


      • #4
        I use comments a lot, when developing programs, so not to forget removing certain lines of code. I usually also add a to-do-list at the very beginning of the file, so I remember what to implement or change, when I pick up programming after a longer break. You might want to do something similar in the future. Had I coded these lines, they would probably read something like

        Code:
        /*
            to do
                
                - review comments
        */
        
        ...
        
        clear all // <- REMOVE THIS LINE OF CODE !!!
        [Edit]
        One last thing: get rid of the

        Code:
        capture program drop pgname
        I see this line of code very often, yet I do not think it has any use in an ado-file. If a program with that name exists and is loaded into memory, then these lines of code are never executed. If a program with the same exists, but is not loaded into memory, then the one earlier down the adopath will get loaded and defined.
        [/Edit]

        Best
        Daniel
        Last edited by daniel klein; 14 Oct 2015, 08:58.

        Comment


        • #5
          Another useful convention is to use key search terms to find code in "draft" stage, to review, etc. Something like // {-- remove this line --}, so that you can search for {-- and find all code to review before finalization.

          Comment


          • #6
            Thank you guys for those pieces of advice!

            Comment

            Working...
            X