Is it possible to make Stata throw an error by default when a global macro is not defined, instead of a missing string?

Viewed 204

A feature of Stata that is sometimes inconvenient is that calling a non-defined macro returns the missing value . [edit: Stata actually returns a missing string "", not a numerical missing value], instead of throwing an error. A piece of code, whose correct execution requires the definition of the macro, may just run giving incorrect results if the macro name is misspelled.

E.g.: having defined global $options = , vce(robust), when afterwards one writes reg y x $opt instead of reg y x $options the program runs anyway and it may be difficult to realise that the vce() option was not considered.

Is there any way to force Stata to issue an error in this case or is there some useful trick/best practice that can be used to reduce the risk of incurring this sort of mistake?

1 Answers
Related