4 display — Display strings and values of scalar expressions
In any case, users can reset the styles by selecting Edit > Preferences > General Preferences in
Windows or Unix(GUI) or by selecting Preferences > General Preferences in Mac.
The display directives as text, as result, as error, and as input allow you, the programmer,
to specify in which rendition subsequent items in the display statement are to be displayed. So if
a piece of your program reads
quietly summarize mpg
display as text "mean of mpg = " as result r(mean)
what might be displayed is
mean of mpg =
where, above, our use of boldface for the 21.432432 is to emphasize that it would be displayed
differently from the “mean of mpg =” part. In the Results window, if we had a black background,
the “mean of mpg =” part would be in green and the 21.432432 would be in yellow.
You can switch back and forth among styles within a display statement and between display
statements. Here is how we recommend using the styles:
as result should be used to display things that depend on the data being used. For statistical output,
think of what would happen if the names of the dataset remained the same but all the data changed.
Clearly, calculated results would change. That is what should be displayed as result.
as text should be used to display the text around the results. Again think of the experiment where
you change the data but not the names. Anything that would not change should be displayed as
text. This will include not just the names but also table lines and borders, variable labels, etc.
as error should be reserved for displaying error messages. as error is special in that it not only
displays the message as an error (probably meaning that the message is displayed in red) but also
forces the message to display, even if output is being suppressed. (There are two commands for
suppressing output: quietly and capture. quietly will not suppress as error messages but
capture will, the idea being that capture, because it captures the return code, is anticipating
errors and will take the appropriate action.)
as input should never be used unless you are creating a special effect. as input (white on a black
background) is reserved for what the user types, and the output your program is producing is by
definition not being typed by the user. Stata uses as input when it displays what the user types.
display used with quietly and noisily
display’s output will be suppressed by quietly at the appropriate times. Consider the following:
. program list example1
example1:
1. di "hello there"
. example1
hello there
. quietly example1
. _