-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcreating-tables-sprintf.e
64 lines (50 loc) · 1.36 KB
/
creating-tables-sprintf.e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
** Using sprintf
**
** Accompanies the blog
** "How to Create a Simple Table with sprintf in GAUSS"
**
** Published 4/02/2020
*/
// Simple printing example with text
sprintf("%s is %d", "Steve", 38);
/*
** First iteration of table
*/
// Create a 3x1 string array
var_names = "population" $| "poverty rate" $| "inflation";
// Create two 3x1 vectors
beta_ = { -0.65582591,
0.94648444,
1.7365981 };
se = { 0.19095146,
0.25047475,
0.11009904 };
sprintf("%s %f %f", var_names, beta_, se);
/*
** Changing format of the
** table for improved appearance
*/
// Create 3x1 string array
var_names = "population" $| "poverty rate" $| "inflation";
// Create two 3x1 vectors
beta_ = { -0.65582591,
0.94648444,
1.7365981 };
se = { 0.19095146,
0.25047475,
0.11009904 };
sprintf("%12s %9f %9f", var_names, beta_, se);
// Surround SE format specifier with parentheses
sprintf("%12s %9f (%9f)", var_names, beta_, se);
// Decrease field width of final column
// and add one space before the '('
sprintf("%12s %9f (%8f)", var_names, beta_, se);
/*
** Precision
*/
// Decrease field width of final column
// and add one space before the '('
sprintf("%12s %9f (%8f)", var_names, beta_, se);
// Decrease field width for numeric columns to remove extra spaces
sprintf("%12s %7.4f (%6.4f)", var_names, beta_, se);