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: make syntax options optional


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: make syntax options optional
Date   Tue, 11 Sep 2012 07:43:21 +0100

The default is just the default. If you specify some specific value,
that overrides the default. All is done automatically for the user.

However, the syntax

if "`firm_id'"!="" {

is confused in your case. "`firm_id'" will be "5" if no firm_id was
specified (see above) and something else in double quotes if a
specific integer value was given. "`firm_id'" will never be empty.

Otherwise put, you specified -firm_id()- as taking an integer
argument. It's perfectly legal to put " " around that and make it a
string, so Stata doesn't object to your syntax.

One way to approach this is to have an impossible default, say an
identifier of -1. Then you can do this

if `firm_id' == -1 {
     odbc load, exec("select * from readership where id_value=`doc_id' ")
}
else  odbc load, exec("select * from readership where
id_value=`doc_id' and source_id=`firm_id' ")

Nick

On Tue, Sep 11, 2012 at 3:16 AM, tashi lama <[email protected]> wrote:

>       //begin  file.ado //
> program file
> syntax, doc_id(int) [firm_id(int)]
> if "`firm_id'"!="" {
>      odbc load, exec("select * from readership where id_value=`doc_id' and source_id=`firm_id' ")
> }
> else {
>      odbc load, exec("select * from readership where id_value=`doc_id' ")
> }
> list
> end
>
>
> . file, doc_id(7) firm_id(6429)
>
> invalid syntax
>
> I searched for archive and found out that we need to give a default value for optional options like following
>
> syntax, doc_id(int) [firm_id(int 5)]
>
> I am not sure if I understood this. Does this not fix firm_id=5? In my case, firm_id will vary.
*
*   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