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: have string macro default in syntax


From   Nick Cox <njcoxstata@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: have string macro default in syntax
Date   Wed, 26 Sep 2012 12:07:17 +0100

By the way, this was not quite what I suggested.

You have

if "`stat'"!="" {
   graph pie varname, by(varname) plabel(_all `stat')
}
else {
   graph pie varname, by(varname) plabel(_all percent)
}

which I would code as

if "`stat'" == "" local stat "percent"
graph pie varname, by(varname) plabel(_all `stat')

The difference is a matter of taste, but if shorter code is good, it's
two lines to six.

On Tue, Sep 25, 2012 at 6:40 PM, tashi lama <ltashi32@hotmail.com> wrote:
> Thanks. To the last comment, I am using odbc to get the varnames. I decided not putting in the question to be concise. I was actually trying to avoid 'if' somethng like we do for integers i.e. [firm(int -1)] .  I had done something like this prior to posting. At least, the way you suggested makes my code shorter.
>
> syntax, [firm(str)]
> if "`stat'"!="" {
>   graph pie varname, by(varname) plabel(_all `stat')
> }
> else {
>   graph pie varname, bu(varname) plabel(_all percent)
> }
>

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


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