Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Detecting a macro expansion error

From   Matthew White <>
Subject   st: Detecting a macro expansion error
Date   Sun, 1 Jan 2012 14:04:04 -0500

Hi all,

Using Stata 11.2 SE, I'm writing a program that requires me to parse a
string passed to the program. I want the program to exit if the string
contains a macro expansion that results in an error. Currently, Stata
displays an error about the macro expansion without exiting, and then
continues to parse the string and run the program. Generally, I want
to know how I can detect whether a command results in a macro
expansion error. Here's an example of what I mean:

. display "`='Hello world"
invalid syntax
Hello world

Here, the macro expansion `=' results in an invalid syntax error, but
-display- is still executed (after `=' evaluates to ""), and there's
no return code (r(198) is not displayed). -capture- doesn't help:

. capture display "`='Hello world"
invalid syntax

. display _rc

Essentially what I'd like is something like -capture- that I can use
to determine whether a command results in a macro expansion error. Any

Thank you,

Matthew White
Data Coordinator
Innovations for Poverty Action
101 Whitney Avenue, New Haven, CT 06510 USA
+1 434-305-9861
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index