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 10:37:21 -0500

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)

Best,
   Sergiy


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.
>
> Any suggestions are very welcomed!
>
> Thank you,
>   Sergiy Radyakin
*
*   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