-capture- deserves a line in your do-file

-cap- (short for capture) is a dangerous but useful code . It supresses all output, including error messages, and proceeds to the next line regardless of any error. For example:

cap drop varname
gen varname=.

/* Stata will execute “drop varname,” but if varname does not exist, it will suppress the error report “variable varname not found” and continue on to the next line. If you wish to see the error message, type: “cap noisily drop varname” */

[Note: Stata ignores everything inside /*  */ ]

Have you been constantly bothered by error messages such as “log file already open” when you are re-executing your do-file? Try -cap-.

[Thanks to Utsav for introducing me to -cap-.]

Leave a Reply