How to prevent error messages from terminating Monte Carlo simulations

Hello, Q&A manager.

I'd like to ask you how to control error messages in Gauss.

When I run my Gauss code, it sometimes generates a singular matrix for a gradient.

Inverting it with invpd command leads to the error message, and the program stops in the middle of the Monte Carlo simulation. However, I want to keep it running such the program moves to the next Monte Carlo dataset. Is there a command like capture in STATA?

Or is there any way to check singularity of matrices and skip their inversion?

 

Regards,

Sanghyeok

1 Answer



0



You can use the trap keyword to control whether some commands print an error and stop the program, or return a scalar error code. In the most simple case, set trap to 1 to trap errors (i.e return a scalar error code instead of stopping the program. Set trap to 0 to return the default behavior (stopping the program with an error message). For example:

//Create a symmetric NON-positive definite matrix
x = { 3      6      9 
      6     12     18 
      9     18     27 }; 

//Turn error trapping on
trap 1;

//Call 'invpd'
i = invpd(x);

//Check to see if return is scalar error code
if scalmiss(i);
   //Code to handle case where 'x' is not positive-definite
endif;

The scalmiss function checks to see whether a GAUSS matrix is a scalar error code, or not. scalerr returns the error number from inside a scalar error code and you can create a scalar error code with an integer error code inside by using the error function.

aptech

1,773

Your Answer

1 Answer

0

You can use the trap keyword to control whether some commands print an error and stop the program, or return a scalar error code. In the most simple case, set trap to 1 to trap errors (i.e return a scalar error code instead of stopping the program. Set trap to 0 to return the default behavior (stopping the program with an error message). For example:

//Create a symmetric NON-positive definite matrix
x = { 3      6      9 
      6     12     18 
      9     18     27 }; 

//Turn error trapping on
trap 1;

//Call 'invpd'
i = invpd(x);

//Check to see if return is scalar error code
if scalmiss(i);
   //Code to handle case where 'x' is not positive-definite
endif;

The scalmiss function checks to see whether a GAUSS matrix is a scalar error code, or not. scalerr returns the error number from inside a scalar error code and you can create a scalar error code with an integer error code inside by using the error function.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy