Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Beginning question


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Beginning question
Date   Tue, 9 Apr 2013 00:44:45 +0100

It's difficult to improve on the help here.

I use -capture- [no SHOUTING please] when something might lead a
program to fail, but I want to trap the failure, including the error
message.

It's usually an example of the Yogi Berraism, "When you come to a fork
in the road, take it".

For example, I test for something being numeric -- if so, I do one
thing -- if not (it's string), I do another thing.

confirm numeric var myvar

would lead a program to fail if the assumption was wrong, but I don't
want that. I have a back-up plan. For example, I might -encode- the
string variable so that I have something numeric to work with. So, I

capture confirm numeric var myvar
if _rc {
          <back-up plan goes here goes here>
}

-if _rc- is going to be true (non-zero) if the return code _rc is non-zero.

-capture- is also often used with -assert-.

-capture- is also often used when you don't want the default error
message, but to substitute your own.

Nick
[email protected]


On 8 April 2013 21:55, Hurley, Sharon <[email protected]> wrote:

> I am transistioning from SAS.  The one thing I don't get is when is
> CAPTURE used?  It seems very arbitrary at the moment.
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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