Differences between revisions 9 and 11 (spanning 2 versions)
Revision 9 as of 2023-06-07 18:28:18
Size: 3879
Comment:
Revision 11 as of 2023-06-13 21:07:03
Size: 4479
Comment:
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
Stata uses '''display formats''' to extend the [[Stata/DataTypes|type system]]. In the topic of data formats in Stata, the concept of '''display formats''' is of primary interest. Stata uses display formats to extend the [[Stata/DataTypes|type system]].

Several commands have internal ideas about data formats.
Line 15: Line 17:
=== Numeric Data === === Numeric Formats ===
Line 36: Line 38:
=== Date and Datetime Data === === Date and Datetime Formats ===
Line 50: Line 52:
These formats can be customized with specific components.

||'''Component'''||'''Specification'''||'''Displays As'''||
||Century ||`CC` ||`01` ||
||Century ||`cc` ||`1` ||
||Year ||`YY` ||`01` ||
||Year ||`yy` ||`1` ||
Line 52: Line 61:
=== String Data === JJJ day within year 001–366
jjj day within year 1–366
Mon month Jan, Feb, . . . , Dec
Month month January, February, . . . , December
mon month jan, feb, . . . , dec
month month january, february, . . . , december
NN month 01–12
nn month 1–12
DD day within month 01–31
dd day within month 1–31
DAYNAME day of week Sunday, Monday, . . . (aligned)
Dayname day of week Sunday, Monday, . . . (unaligned)
Day day of week Sun, Mon, . . .
Da day of week Su, Mo, . . .
day day of week sun, mon, . . .
da day of week su, mo, . . .
Datetime display formats — Display formats for dates and times 3
h half 1–2
q quarter 1–4
WW week 01–52
ww week 1–52
HH hour 00–23
Hh hour 00–12
hH hour 0–23
hh hour 0–12
MM minute 00–59
mm minute 0–59
SS second 00–60 (sic, due to leap seconds)
ss second 0–60 (sic, due to leap seconds)
.s tenths .0–.9
.ss hundredths .00–.99
.sss thousandths .000–.999
am show am or pm am or pm
a.m. show a.m. or p.m. a.m. or p.m.
AM show AM or PM AM or PM
A.M. show A.M. or P.M. A.M. or P.M.
. display period .
, display comma ,
: display colon :
- display hyphen -
display space
/ display slash /
\ display backslash \
!c display character c
+ separator

Note: + displays nothing; it may be used to separate one code from the next to make the
format more readable. + is never necessary. For instance, %tchh:MM+am and %tchh:MMam
have the same meaning, as does %tc+hh+:+MM+am.



=== String Formats ===
Line 62: Line 123:
The '''`list`''' command examines data to (re-)allocate text width. If the longest value for a string variable with format `%18s` is 12 characters long, then `list` will only allocate 12 columns for that variable. This behavior can be disabled using the '''`nocompress`''' option.

Note that the default behavior has an impact on performance, especially for large datasets. As such, there is a '''`fast`''' option which is simply an alias for `nocompress`.

To truncate string values specifically, use the '''`string`''' option.

{{{
list comment, string(10)
}}}



=== String Value Alignment ===

The `list` command automatically shifts between two output modes based on the width of the listed variables and the width of the screen.

In '''table format''', the `list` command right-justifies all string values.

In '''display format''', string values are aligned according to the display format. A string value would be left-justified if the variable had a format of `%-18s`.



=== Variable Names ===

The `list` command also abbreviates variable names (defaulting to 8 characters). To increase that character limit, use the '''`abbreviate`''' option.

{{{
list very_long_variable_name, abbreviate(50)
}}}



=== Value Labels ===

The `list` command also uses labels (as opposed to values) when available. To override this behavior, use the '''`nolabel`''' option.

Value labels are aligned in the same way as string values; based on the output mode and the display format. Just as a string value would be left-justified if the variable had a format of `%-18s`, a label would be justified if the variable had a format of `%-8g`.
The '''`list`''' command resizes and reformats output to try and maximize accessibility. This involves automated truncation and alignment overriding display formats. For information on formatting the output of `lists`, see [[Stata/List#Data_Formats|here]].

Stata Data Formats

In the topic of data formats in Stata, the concept of display formats is of primary interest. Stata uses display formats to extend the type system.

Several commands have internal ideas about data formats.


Display Formats

Numeric Formats

The default display format for each numeric data type is as follows:

Type

Format

double

%10.0g

float

%9.0g

long

%12.0g

int

%8.0g

byte

%8.0g

The available numeric formats are e, f, and g. The general format (g) indicates that the number of decimal places should be shifted to improve readability. The fixed width format (f) indicates that a fixed number of decimal places should be shown. The scientific format (e) indicates that scientific notation should be used.

Value

With format %9.4g

With format %9.4f

With format %9.2e

3.14159

3.142

3.14

3.14e+00

314.159

314.2

314.16

3.14e+02

A c can be appended to any numeric format to indicate that commas should be shown.

Date and Datetime Formats

Dates and datetimes are numeric data with unit-specific display formats. These are:

Format

Unit

%tc

milliseconds ignoring leap seconds

%tC

milliseconds with leap seconds

%td

days

%tw

weeks

%tm

months

%tq

quarters

%th

half-years

%ty

years

These formats can be customized with specific components.

Component

Specification

Displays As

Century

CC

01

Century

cc

1

Year

YY

01

Year

yy

1

JJJ day within year 001–366 jjj day within year 1–366 Mon month Jan, Feb, . . . , Dec Month month January, February, . . . , December mon month jan, feb, . . . , dec month month january, february, . . . , december NN month 01–12 nn month 1–12 DD day within month 01–31 dd day within month 1–31 DAYNAME day of week Sunday, Monday, . . . (aligned) Dayname day of week Sunday, Monday, . . . (unaligned) Day day of week Sun, Mon, . . . Da day of week Su, Mo, . . . day day of week sun, mon, . . . da day of week su, mo, . . . Datetime display formats — Display formats for dates and times 3 h half 1–2 q quarter 1–4 WW week 01–52 ww week 1–52 HH hour 00–23 Hh hour 00–12 hH hour 0–23 hh hour 0–12 MM minute 00–59 mm minute 0–59 SS second 00–60 (sic, due to leap seconds) ss second 0–60 (sic, due to leap seconds) .s tenths .0–.9 .ss hundredths .00–.99 .sss thousandths .000–.999 am show am or pm am or pm a.m. show a.m. or p.m. a.m. or p.m. AM show AM or PM AM or PM A.M. show A.M. or P.M. A.M. or P.M. . display period . , display comma , : display colon : - display hyphen - display space / display slash / \ display backslash \ !c display character c + separator

Note: + displays nothing; it may be used to separate one code from the next to make the format more readable. + is never necessary. For instance, %tchh:MM+am and %tchh:MMam have the same meaning, as does %tc+hh+:+MM+am.

String Formats

Alignment is controlled by the presence or absence of a negative sign (-) ahead of the width. A string variable formatted as %-18s will be left-justified; with a format of %18s it would have been right-justified.


List

The list command resizes and reformats output to try and maximize accessibility. This involves automated truncation and alignment overriding display formats. For information on formatting the output of lists, see here.


CategoryRicottone

Stata/DataFormats (last edited 2025-03-05 02:10:25 by DominicRicottone)