Differences between revisions 2 and 3
Revision 2 as of 2023-06-08 21:10:06
Size: 2120
Comment:
Revision 3 as of 2025-10-24 17:04:02
Size: 1458
Comment: Rewrite
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
The '''`display`''' command prints text to the output. '''`-display-`''' prints text to the output.
Line 29: Line 29:
----

=== Directives ===

`-display-` interprets a set of directives.

 * '''`_newline`''' prints a newline character
 * '''`_newline(N)`''' prints `N` newlines
 * '''`_continue`''' suppresses the automatic newline character at the end
 * '''`_skip(N)`''' moves the cursor forward `N` characters, effectively printing `N` space characters.
 * '''`_char(N)`''' prints the character corresponding to ASCII or Windows-1252 codepoint `N`. This is useful for showing characters that would otherwise need to be escaped, or for Windows-1252 codepoints that should instead be encoded in Unicode for display.
 * '''`_column(N)`''' moves the cursor to the `N`th columnar position. Column positions index from 1.
Line 33: Line 44:
== Directives == == Styles ==
Line 35: Line 46:
The `display` command also understands a set of directives that add macrotized output.

The '''`_newline`''' directive prints a newline character. The '''`_newline(N)`''' directive prints `N` of them.

the '''`_continue`''' directive suppresses the automatic newline character that follows a `display` command.

The '''`_skip(N)`''' directive moves the cursor forward `N` characters, effectively printing `N` space characters.

The '''`_char(N)`''' directive prints the character corresponding to ASCII or Windows-1252 codepoint `N`. This is useful for showing characters that would otherwise need to be escaped, or for Windows-1252 codepoints that should instead be encoded in Unicode for display.
`-display-` operates in styles. By default, it does not reset the style, so it may be necessary to begin a program's output like:
Line 46: Line 49:
display "Backticks look like " _char(96)
display "The British Pound sign looks like " _char(163)
display as text ...
Line 50: Line 52:
The '''`_column(N)`''' directive moves the cursor to the `N`th columnar position. (Consider the start of a line to be the 1st position.) This is useful for creating columnar output, like:

{{{
display "1st 2nd 3rd"
display "--- --- ---"
display "1" _column(5) "11" _column(9) "111"
display "999" _column(5) "99" _column(9) "9"
}}}

----



== Styling ==

By default, `display` will print as plain text. To print with a bolded style, try:

{{{
display as result "Something about `r(N)' of them"
}}}

To print with a red color, try:

{{{
display as error "Something about `r(N)' of them"
}}}

These styles continue to be applied until a new one is set, so if using them, adjust all 'normal' `display` commands to `display as text`.
The other styles are:
 * `result` (bold)
 * `error` (red)
Line 85: Line 62:
[[https://www.stata.com/manuals/pdisplay.pdf|Stata manual for display]]
[[https://www.stata.com/manuals/pdisplay.pdf|Stata manual for -display-]]

Stata Display

-display- prints text to the output.


Usage

display "Hello, world"

// arithmetic
display _N+1

// scalars
display "There are " _N " cases"

// stored results
display "Something about `r(N)' of them"

// macros
display "Something about ${globals} and `locals'"

Directives

-display- interprets a set of directives.

  • _newline prints a newline character

  • _newline(N) prints N newlines

  • _continue suppresses the automatic newline character at the end

  • _skip(N) moves the cursor forward N characters, effectively printing N space characters.

  • _char(N) prints the character corresponding to ASCII or Windows-1252 codepoint N. This is useful for showing characters that would otherwise need to be escaped, or for Windows-1252 codepoints that should instead be encoded in Unicode for display.

  • _column(N) moves the cursor to the Nth columnar position. Column positions index from 1.

Styles

-display- operates in styles. By default, it does not reset the style, so it may be necessary to begin a program's output like:

display as text ...

The other styles are:

  • result (bold)

  • error (red)


See also

Stata manual for -display-


CategoryRicottone

Stata/Display (last edited 2025-10-24 17:04:02 by DominicRicottone)