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
Related Posts with Help with ado file created command options
reshaping complex panel data[CODE] * Example generated by -dataex-. To install: ssc install dataex clear input str7 _AIHWperiod …
Fixed effects regression is doing something I'm not noticing?In Stata I complete a fixed-effects conditional logistic regression model of a binary predictor (1==…
Replacing values from one observation to anotherDear Statalist users, this may be a trivial question to you, but I am a little bit struggling to do…
Interpreting stset- outputHello, I use Stata 15.1 for survival analysis, using a Cox-model (stcox). My master dataset is the U…
Suest after fracregHello all, This seems like a simple question. I wanted to compare coefficients from two models est…
Subscribe to:
Post Comments (Atom)
0 Response to Help with ado file created command options
Post a Comment