Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: capture blocks


From   Philipp Rehm <[email protected]>
To   [email protected]
Subject   Re: st: capture blocks
Date   Sun, 29 Jun 2008 13:26:56 +0200

.
Many thanks for this, Svend!

It seems that -, nostop- is a file-wide option (if I understand it correctly).

However, I want to force only parts of the do-file trough -capture-.

Any ideas?

Thank you again!

All best,
Philipp



Svend Juul wrote:

Philipp wrote:
My question is whether there is a way to force Stata to run trough a do-file without aborting when there is an error. ...
=======================================================
. help do
tells about the -nostop- option. It does what you want.
Svend
________________________________________________________ Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6 DK-8000 Aarhus C, Denmark Phone, work: +45 8942 6090 Phone, home: +45 8693 7796 Fax: +45 8613 1580 E-mail: [email protected] _________________________________________________________
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/


.
My question is whether there is a way to force Stata to run trough a do-file without aborting when there is an error. I know that I can use -capture- for this. Example:

sysuse auto, clear
cap noisily rename rep76 whatever
cap noisily rename rep77 foo
cap noisily rename rep78 bar

I was hoping / expecting that -capture- with {} would let me do this on a whole block of commands. Example:

sysuse auto, clear
capture noisily {
rename rep76 whatever
rename rep77 foo
rename rep78 bar
}

However, this will abort after the first line (which contains an error). This behavior is documented in the manual: "If any of the commands in the capture block fail, the subsequent commands in the block are aborted" ([P], Release 9, p. 21)

So, is there a way to run a *block* of commands without having to put the -capture- in front of each command?

Stata 9, Win XP.
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




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