Reputation: 877
I wish to create an ado
file, which has four categories of variables.
The idea is that the user can input something like:
myprog depvar biggroup, ingroup(varlist1) outgroup(varlist2)
In this example depvar
and biggroup
are single variables, while ingroup
is at least two variables and the outgroup
is the same but optional.
So far i have attempted the following:
program myprog, rclass
version 15
syntax varlist(min=2 max=2), ingroup(min=2) [outgroup]
local depvar: word 1 of `varlist'
...
end
I can pull apart varlist
based on word count
to create the depvar
and biggroup
variables as I did for depvar
.
However, I am unsure how to create the additional lists for ingroup
and outgroup
. The issue is that they can both include a varied number of variables and I do not know how to differentiate them with either the syntax
or args
commands.
Upvotes: 0
Views: 198
Reputation:
You can also use a varlist
for each option. Or alternatively you could pass them as strings.
Here's the solution using a varlist
:
capture program drop myprog
program define myprog, rclass
version 14
syntax varlist(min=2 max=2), ingroup(varlist min=2) [outgroup(varlist min=2)]
display ""
display "`varlist'"
display ""
display "`ingroup'"
display ""
display "`outgroup'"
end
. clear
. generate one = runiform()
. generate two = runiform()
. generate three = runiform()
. generate four = runiform()
. generate five = runiform()
. generate six = runiform()
. generate seven = runiform()
. myprog one two, ingroup(three four) outgroup(five six seven)
one two
three four
five six seven
Upvotes: 2