Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Parsing syntax in an ado file


From   "Sergiy Radyakin" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Parsing syntax in an ado file
Date   Wed, 6 Feb 2008 14:15:49 -0500

I agree that it is reasonable that Stata's default behaviour is to
complain whenever a variable is used in the if clause, which is not in
the active dataset. But I am looking for the easiest way to change
this, default behaviour, and I know that it is possible, since -use-
does not complain. The question is if there is a shortcut to do it.

It is of course possible to send all this as options, but It will look
quite unnatural in my case.

Thanks, Sergiy



On 2/6/08, Nick Cox <[email protected]> wrote:
> Sorry, but I am not much clearer. If a user calls a command referring to
> a variable that doesn't exist, it seems to me utterly reasonable for
> Stata to complain. If you wish to subvert that, I think you'll need some
> non-standard method, such as -if()- or -in()- options followed by
> processing of problems within your program. If you're the user that's
> one thing. If you have to explain this to other users, that's an extra
> problem, or so it would seem.
>
> Nick
> [email protected]
>
> Sergiy Radyakin
>
> Nick is not clear with what I mean by "other parameters". By "other
> parameters" I mean parameters that are not listed in #1-4 in my
> original posting, and these would be parameters other than Stata's
> command "use" supports. As an example in the syntax statement I've
> included a parameter "saving".
>
> Nick suggests trying sequential syntax statements and using namelist
> instead of varlist. This helps, but not completely. Namelist
> substitutes for varlist, but I do not see similar substitutes for if
> and in.
>
> Example:
>
> . clear
> . mycommand income age using "myfile.ext" if female==1,
> saving("anotherfile.ext")
> female not found
> r(111)
>
> On 2/6/08, Nick Cox <[email protected]> wrote:
> > I am not clear what you mean by "other parameters" in this context.
> >
> > I can't speak for the internals of -use-, but I am not clear why you
> are
> > dismissing -capture syntax-. That is exactly what I would try.
> >
> > capture syntax <syntax 1>
> > if _rc syntax <syntax 2>
> >
> > Also, consider using -namelist- as an alternative to -varlist-. Then
> > after
> > -syntax- check whether the namelist is a varlist.
> >
> > Nick
> > [email protected]
> >
> > Sergiy Radyakin
> >
> > I am writing an ado file and I want it to support:
> > 1. varlist
> > 2. using clause
> > 3. if
> > 4. in
> > 5. Other parameters
> >
> > I am using syntax statement to do the job.
> > syntax [varlist] [using/] [if] [in] [,clear] [SAVing(string)]
> >
> > The program in the ado file is supposed to
> > A. do something with the parameters
> > B. do something with the file specified in using (as usual, the word
> > using may be omitted when varlist is empty)
> > C. load another file with the specified varlist, if, and in
> >
> > However, since that file in C is not in the memory, (say I have no
> > data in the memory at all) the call to my program fails. And this is
> > reasonable, since no variables are in memory -- hence varlist may not
> > be "non-empty", etc.
> >
> > I know I can parse the `0' macro myself with gettoken. But I am
> > looking for a more elegant solution to do it.
> >
> > Q: How do I get the parts of the command named in the syntax even if
> > some of the parts can't be evaluated at the moment? E.g. I want
> > unknown_syntax_command [varlist] [using/] [if] [in] [,clear]
> > [SAVing(string)]
> > to fill in the local varlist with the specified string, ignoring the
> > fact, that the variables with the specified  names are not present in
> > the dataset, that in spans the range beyond the current max, etc...
> >
> > capture syntax .... either does what syntax does, or does nothing, so
> > is of no use.
> >
> > Q2: since use is a built-in command, I can't see how the syntax is
> > defined there. But it is what I would want to replicate in my ado.
> >
>
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index