Stata 15 help for capture

[P] capture -- Capture return code


capture [:] command

capture { stata_commands }


capture executes command, suppressing all its output (including error messages, if any) and issues a return code of zero. The actual return code generated by command is stored in the built-in scalar _rc.

capture can be combined with {} to produce capture blocks, which suppress output for the block of commands. See the technical note in [P] capture for more information.


capture is useful in do-files and programs because their execution terminates when a command issues a nonzero return code. Preceding sensitive commands with the word capture allows the do-file or program to continue despite errors. Also do-files and programs can be made to respond appropriately to any situation by conditioning their remaining actions on the content of the scalar _rc.

capture can be combined with noisily to display the output and any error messages regardless of the return code. For example,

. capture noisily regress y x

will either display an error message and store the return code in _rc or display the output and store a return code of zero in _rc.

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