首页 > 解决方案 > 如何在 Mata 中抛出错误并退出

问题描述

我正在 Stata 中编写一个函数,在其中进行一些逻辑检查并可能引发错误。可能看起来像这样:

if ! r(N) {
    disp as error "There are no observations with a value of 1 in the subgroup."
    exit
}

现在,我也在运行一些 Mata 代码,我也想在 Mata 中进行逻辑检查,并且可能会抛出一个类似上面的错误。我该怎么做?

标签: stata

解决方案


阅读 Mata 的exit()error()功能。

help mf_exit 

help mf_error 

推荐阅读