Page 1 of 1

Continuing a program if solve fails to converge

Posted: Thu Oct 22, 2020 8:47 am
by DBW
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)

Re: Continuing a program if solve fails to converge

Posted: Thu Oct 22, 2020 4:59 pm
by EViews Matt
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.

Re: Continuing a program if solve fails to converge

Posted: Fri Oct 23, 2020 2:16 am
by DBW
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.

Re: Continuing a program if solve fails to converge

Posted: Fri Oct 23, 2020 9:08 am
by EViews Matt
Yes, that's right.