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
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Beginning question
Date
Tue, 9 Apr 2013 09:01:22 +0200
To add to Nick's comment: I only use -capture- when programming, never
when preparing or analysing my data. This follows from Nick's logic:
When I am writing my do file for preparing or analysing my data I am
there to choose between back-up plans. I typically document such
choices in comments in the .do file. If I run the .do file again at
some later date and the file returns an error, then that is a sign
that something went wrong which I will need to check. So _not_ using
-capture- is a safety mechanism, for data analysis and preparation. It
is only when I write a program for general that I want to use
-capture- for making such choices.
-- Maarten
On Tue, Apr 9, 2013 at 1:44 AM, Nick Cox <[email protected]> wrote:
> 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/
--
---------------------------------
Maarten L. Buis
WZB
Reichpietschufer 50
10785 Berlin
Germany
http://www.maartenbuis.nl
---------------------------------
*
* 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/