Stata 15 help for rcof

Title

[P] rcof -- Verify return code

Syntax

rcof ["]stata_cmd["] rest_of_expression

This command is intended for authors of certification scripts -- do-files used to test that commands work properly; see [P] cscript.

Description

rcof executes stata_cmd and then verifies that the return code is as indicated.

Remarks

In a certification script, one might purposely issue a stata_cmd that should produce an error and then verify that the expected error is produced. If the assertion is true, the script continues. If the assertion is false, the script stops.

Examples

. discard /* thus removing estimation results */ . rcof "regress" == 301

. rcof "regress mpg weight badvar" == 111

If the return code from the command is 111, that is, if, had you typed just the command, you would have seen,

. regress mpg weight badvar badvar not found r(111);

then the certification script will continue. Output from stata_cmd is suppressed. If you want to see the output (which would typically be an error message), include noisily (see [P] quietly) in the stata_cmd:

. rcof "noisily regress mpg weight badvar" == 111

In that case, you will see

. rcof "noisily regress mpg weight badvar" == 111 badvar not found

but the certification script will not stop. On the other hand, here is what happens when the return code is not as you assert:

. rcof "regress mpg weight badvar" == 198

rcof: _rc == 198 *NOT TRUE* from regress mpg weight badvar _rc == 111 r(9);

You may omit the double quotes when stata_cmd does not contain the characters =, <, >, ~, and !.

. rcof noisily regress mpg weight badvar == 111

would work but

. rcof gen mpg = 3 == 110

would not have the intended result. In this case, you must code

. rcof "gen mpg = 3" == 110

Omitting the double quotes is not encouraged.


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index