Announcement

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

  • Stop executing command and move to another command in a do file (Continue, GoTo)

    Dear all,

    stata is not the package I am most fluent with so I apologise if this is basic.

    I just wonder if there is away to stop execution of a command in Stata under certain conditions, i.e. the equivalent of continue, next, goto - I would prefer goto as I do not have a loop.

    Essentially I would like start counting time on a given line, wait say 100 seconds to see if my estimation converge and move on to the next estimation line (I have some post-estimation in between) or even better to a given line if it does not converge

    Thanks,
    Renato


  • #2
    Code:
    capture some_estimation_command
    if !_rc {
        some post estimation commands
    }
    capture next_estimation_command
    if !_rc {
        some post estimation commands
    }
    etc.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      I don't think Maarten's solution will give you 100 seconds worth of estimation before moving on. It simply tries to estimate the model, and if convergence fails, it moves on to the next command rather than halting. To my knowledge, it is not possible in Stata to set a specific time limit on an estimation command.

      What you can do, is specify that you're only willing to go up to a certain number of iterations in the estimation process. You can specify that with the -iterate()- option. So that might look like this:

      Code:
      estimation_command varlist, other_options iterate(50)
      next_estimation_command varlist, other_options iterate(50)
      etc.
      (I just picked 50 arbitrarily to illustrate the approach, and how much time that would take would vary from model to model.)

      Comment


      • #4
        The "iterate" option is often available in several Stata estimation commands and you should take a look.

        But from your post it sounds like you want Stata to automatically stop executing something on a timer (e.g. timeout on UNIX or signal in Python). Is that right? If that is the case, I do not think Stata can do this. Interactively, you can manually hit the break button to halt execution of most programs, but I don't think you can do this programatically (though I'd be happy to be proven wrong).

        If you can make your estimation commands execute asynchronously, however, you might be able to hack your way around this by using the built-in "sleep" command.

        Comment

        Working...
        X