Hello Statalist Users,
I have two general questions about creating commands in Ado files. I am just learning to make my own commands in Ado files.
I am using Stata 15.1 on Windows 10.
#1: QUESTION #1
I would like one of the options in the command to be constrained to one of four strings that I specify in the program, for when the user specifies the option. An illustrative example follows.
program animal
version 15.1
syntax varlist(max=9999 string) [, valuein(varname) skip(numlist max=1) move(string)]
end
So a command calling that program might look like the following.
animal(v1 v2 v3), valuein(dog) skip(3) move(up)
If I put something in the brackets associated with "valuein" that isn't a variable, I'll get a Stata produced error message, and Stata will stop running, a good thing / exactly the response I want.
If I put something in the brackets associated with "skip" that isn't a number, I'll get an error message, and Stata will stop running, a good thing / exactly the response I want. If I put two numbers into the brackets associated with "skip", I'll get an error message, also exactly the response I want.
What I don't know how to do is to constrain the strings that can be put into the brackets associated with the option "move" to just four strings: "up", "down", "left" and "right". I want to receive a Stata produced error message if something else is put inside those brackets, even if it is a string. Furthermore, if I put two or more of those four strings in, I also want to receive an error message.
What is the correct syntax to do this?
I am able to write my own syntax to verify that one of those four strings was input into the option "move" later in the program than the syntax line, but I want to know how to do this with the tools that Stata makes available, if they exist. I'm guessing there is a concise way to constrain the strings that can be used in a particular option in the syntax line.
#1: QUESTION #2
The default is for "options to be optional". In other words, if I type the command
animal(v1 v2 v3), valuein(dog)
no error message will result, since I can omit the options "skip" and "move" in the command.
How do I specify that an option is required? In other words, if the option isn't specified, an error command will result?
Thanks for the help,
Carl
0 Response to Help with ado file created command options
Post a Comment