Continuing a program if solve fails to converge

For technical support, tips and tricks, suggestions, or any other information regarding the EViews model object.

Moderators: EViews Gareth, EViews Moderator

DBW
Posts: 9
Joined: Wed Jul 24, 2019 3:37 am

Continuing a program if solve fails to converge

Postby DBW » Thu Oct 22, 2020 8:47 am

Hi there,

I'm trying to run a program that applies the same model of simultaneous equations to data for a large number of companies. But there are a small number for which 'solve' fails to converge on a solution, ending the program. I've played around with various convergence criteria and so on, but it always meets a problem.

Is there a way to control for this, so that the program continues to run if the model fails to converge on a solution and just skips to the next iteration of the loop?

Thanks.

(I'm using the August 4th build of Eviews 11, by the way)

EViews Matt
EViews Developer
Posts: 560
Joined: Thu Apr 25, 2013 7:48 pm

Re: Continuing a program if solve fails to converge

Postby EViews Matt » Thu Oct 22, 2020 4:59 pm

Hello,

Yes, you can use EViews' general setmaxerrs facility to suppress an error generated during a model solve. Let me begin with a basic code outline:

Code: Select all

[loop]
   ...
   setmaxerrs 2
   [solve model]
   !no_error = @errorcount = 0
   clearerrs
   setmaxerrs 1
   if !no_error then
      [all code contingent on a successful solution]
   endif
   ...
[endloop]

The basic idea is to increase the threshold for the allowed number of errors just before the command that may produce an error, i.e., the model solve. You then use @errorcount to record whether an error occurred, and finally reset the error state back to its defaults. You can then safely run any code dependent on a successful solution and continue with the remainder of the loop.

Some people who use this facility will just set the threshold to a large number at the beginning of a program, e.g., setmaxerrs 10000, but I generally don't advise that unless you know what you're doing. Suppressing all errors makes a program harder to debug, so I recommend the tactic of keeping the error suppressing region (between "setmaxerrs 2" and "setmaxerrs 1") as small as possible.

DBW
Posts: 9
Joined: Wed Jul 24, 2019 3:37 am

Re: Continuing a program if solve fails to converge

Postby DBW » Fri Oct 23, 2020 2:16 am

Matt - thanks very much. This is perfect. It has worked a treat.

I assume I can use the same approach to alter the convergence threshold too, if required? i.e. if convergence fails at one level, I can repeat with a lower convergence criteria?

Thanks again.

EViews Matt
EViews Developer
Posts: 560
Joined: Thu Apr 25, 2013 7:48 pm

Re: Continuing a program if solve fails to converge

Postby EViews Matt » Fri Oct 23, 2020 9:08 am

Yes, that's right.


Return to “Models”

Who is online

Users browsing this forum: No registered users and 16 guests