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 on April 23, and its replacement, is already up and running.

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

Re: st: Beginning question

From   Nick Cox <>
To   "" <>
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

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.


On 8 April 2013 21:55, Hurley, Sharon <> 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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index