I wrote a program and gave its syntax the optional option nosort
. It's behaving strangely and my hunch is that it might be a reserved word of some kind. Here is some example code. Two programs that do the exact same thing but behave differently on my machine depending on what I name the option:
clear all
capture program drop my_test
program define my_test
syntax [, hw]
if "`hw'" != "" n dis "Hello world"
if "`hw'" == "" n dis "Am I insane?"
end
capture program drop my_test2
program define my_test2
syntax [, nosort]
if "`nosort'" != "" n dis "Hello world"
if "`nosort'" == "" n dis "Am I insane?"
end
my_test
my_test, hw
my_test2
my_test2, nosort
For me, this code yields:
. my_test
Am I insane?
. my_test, hw
Hello world
.
. my_test2
Am I insane?
. my_test2, nosort
Am I insane?
They say "the definition of insanity is doing the same thing over and over and expecting different results", so I'll admit that I'm a little worried about my sanity.
The question can be answered directly:
Are there reserved words or locals in Stata program syntax?
Yes, and search reserved
for example leads to documentation.
But this is not the problem, which is however to do with special syntax here. See help syntax
and the subheading option_descriptor optionally_off
.
(I am having bizarre problems posting code, so I will stop there for the moment, except with a comment that I never use option names such as nosort
starting with no
, which triggers the problem here if not used correctly. I just would have a default and then use an option such as sort
to override the default. The name here suggests that sorting is much or all of what you intend the program to do, in which case your problem may already have a better solution.)