One simple approach first uses the -syntax- command to capture the list of
arguments, followed by the -gettoken- command to place the first and remaining
arguments in separate macros (see help gettoken).
If your arguments are variable names, as would be the case in the regression
command examples you mention, you will probably want to use varlist with
-syntax-, eg.:
capture program drop jw
program define jw
syntax varlist(min=2)
gettoken firstvar othervars : varlist
di " varlist: `varlist'"
di " firstvar: `firstvar'"
di "othervars: `othervars'"
end
sysuse auto
jw make-weight
Using namelist in place of varlist in the syntax command relaxes the variable
argument requirement but still allows the min=2 restriction, though I don't
think you can include numeric arguments in the list.
- Gary
Jacob Wegelin wrote:
Inside a program, I would like to differentiate between the first
argument and all the other arguments--just as the regression functions
do. Just as with regression functions, I would like to pass an
arbitrary number of arguments (mininum 2) to this program. Thus, is
there a straightforward macro for "all subsequent arguments after the
first"? I mean code sort of like the following:
program mine
/* Some kind of introductory material: an appropriate - syntax
- command? */
regress `1' `all_subsequent_arguments'
/* More code */
end
Thanks for any tips. This must be well-known and obvious and the answer
probably lies in plain sight in [P] syntax or in the nc151 lecture
notes, but I have not found it yet in those references.
Jake Wegelin
P.S. I do know that `0' means all arguments (confirmed below); I just
don't know how to get all arguments *but* the first.
capture program drop callROCtab
program define callROCtab
di "Response is `1'"
di "First predictor is `2' "
di "All arguments are `0'"
end
*
* 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/