forked from wbuchanan/eda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grlabsplit.ado
79 lines (56 loc) · 2.65 KB
/
grlabsplit.ado
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
********************************************************************************
* Description of the Program - *
* Utility to split variable labels for multiline titles/axis titles *
* *
* Program Output - *
* char varname[ti1] - First half of graph titles/labels for this variable *
* char varname[ti2] - Second half of graph titles/labels for this variable *
* char varname[title] - A string that can be used for titles in graphs *
* *
* Lines - *
* 80 *
* *
********************************************************************************
*! grlabsplit
*! v 0.0.0
*! 20OCT2015
// Drop program from memory if loaded
cap prog drop grlabsplit
// EDA subroutine that writes split graph titles to dataset characteristics
prog def grlabsplit
// Requires a variable list
syntax varlist [, GRLABLength(int 50)]
// Loop over variable list
foreach v in `varlist' {
// Get variable label
loc graphlab : var l `v'
// Remove apostrophes
loc graphlab : subinstr loc graphlab "'" "", all
// Get the length of the x-axis variable lable
loc lablength : length loc graphlab
// Get the number of chunks needed to split the label
loc chunks = ceil(`lablength' / `grlablength')
// Make sure to allocate enough chunks in cases where the label length
// is less than the grlablength parameter
if `lablength' > `grlablength' & `chunks' < 2 {
// Add one to the chunk macro
loc chunks = 2
} // End IF Block for shorter variable labels than split length
// Holder for title string
loc title `""'
// If the variable label is longer than `grlablength' characters split it
forv i = 1/`chunks' {
// Extracts a chunk from the variable label
loc tmplab : piece `i' `grlablength' of `"`: var label `v''"', nobreak
// Stores the label chunk in a characteristic
char `v'[ti_chunk_`i'] "`tmplab'"
// Add chunk to title string
loc title `"`title'"`tmplab'" "'
} // End IF Block for splitting variable labels
// Store the title string in a characteristic
char `v'[title] "`title'"
// Store the length of the original label
char `v'[lablen] `lablength'
} // End Loop over variable list
// End of subroutine for splitting variable labels for titles
end