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


From   Nick Cox <[email protected]>
To   [email protected]
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 <[email protected]> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index