Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Beginning question


From   Nick Cox <njcoxstata@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
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
njcoxstata@gmail.com


On 8 April 2013 21:55, Hurley, Sharon <Sharon.Hurley@uphs.upenn.edu> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index