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: -capture noisily- shorthand


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: -capture noisily- shorthand
Date   Mon, 14 Jan 2013 12:35:38 +0000

The problem with global macros is that this definition might clash
with other definitions used in other programs.

In practice, experienced Stata programmers don't use them unless
really needed, for precisely this reason, so your main risk is that
you forget about this definition when also using different code of
your own.

In practice, I would use a local macro for this purpose. This is more
a matter of style than anything else.

I see no case for allowing the abbreviated command -cn-, as it is too cryptic.

Nick

On Mon, Jan 14, 2013 at 12:27 PM, annoporci <annoporci@gmail.com> wrote:

> I want to systematically use -capture noisily- throughout a do-file with
> multiple loops (as some fail).
>
> The shortest form for it is -cap n-
>
> Not bad. However, I thought it would be neater to have something even
> shorter, say -cn-. Unfortunately that's an "unrecognized command"
> (implemented in a future version of Stata maybe?)
>
> I defined a macro to store "capture noisily" and repeatedly use the macro.
> See the example code below.
>
> I used a "global" macro so that I could use the dollar sign in front of it
> -- easy to type and remember.
>
> The trick seems to work, but is it an acceptable practice? any pitfalls?
>
> many thanks.
>
> --
> Patrick Toche.
>
>
> /// Different ways of preceding a command with -capture noisily-
>
> clear all
>
> sysuse auto
>
> capture noisily regress price mpg rep78
>
> cap n reg price mpg rep78
>
> cap n reg price mpg rep79
>
> global cn "capture noisily"
>
> $cn reg price mpg rep78
>
> $cn reg price mpg rep79
>
> regress price mpg rep78
*
*   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