Dear statalist users,
I want to write a small program that just takes integers as input values and then does something with them. What exactly is irrelevant to the description of my problem.
I would also like to define an option with which I can define the name of the returned local.
According to Stata psyntax help I can only use varlist|namelist|anything as arguments. Isn't there actually an option to use numlist here too?
Since I couldn't find this option, I now used anything as input, which works somehow.
BUT:
If I use the additional option local(name) and write the comma that separates the option from the argument directly after the argument, then it is not parsed correctly, but the comma is read as part of the argument. If I write a space before the options comma, everything works.
This is what happens in different situations:
So what am I doing wrong here and how can I correctly specify the program syntax?
Thanks in advance for your help!
Benno Schönberger
I want to write a small program that just takes integers as input values and then does something with them. What exactly is irrelevant to the description of my problem.
I would also like to define an option with which I can define the name of the returned local.
According to Stata psyntax help I can only use varlist|namelist|anything as arguments. Isn't there actually an option to use numlist here too?
Since I couldn't find this option, I now used anything as input, which works somehow.
BUT:
If I use the additional option local(name) and write the comma that separates the option from the argument directly after the argument, then it is not parsed correctly, but the comma is read as part of the argument. If I write a space before the options comma, everything works.
Code:
program define tinytest syntax anything(everything)[, Local(name)] args number if !missing(`"`local'"') display as result in smcl `"Option defined: `local'"' // lets calculate something just for illustration display as result in smcl `number'^2 end
Code:
. tinytest 5 25 . tinytest 5 , local(name) Option defined: name 25 . tinytest 5, local(name) Option defined: name 5 ^2 invalid name r(198);
Thanks in advance for your help!
Benno Schönberger
Comment