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)
Continuing a program if solve fails to converge
Moderators: EViews Gareth, EViews Moderator
-
- EViews Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: Continuing a program if solve fails to converge
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:
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.
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
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.
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 Developer
- Posts: 563
- Joined: Thu Apr 25, 2013 7:48 pm
Re: Continuing a program if solve fails to converge
Yes, that's right.
Who is online
Users browsing this forum: Google [Bot] and 20 guests