-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel_reverse.ado
52 lines (44 loc) · 1.04 KB
/
label_reverse.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
*! version 1.0.1 May 12, 2004 @ 10:46:09
*! reverses badly ordered ordinal labels
program define label_reverse
version 8.2
local me "label_reverse"
syntax , old(name) new(name) [min(str) max(str)]
capture lab l `new'
if !_rc {
display as error "[`me']: The new macro `new' already exists!"
exit 110
}
quietly label list `old'
local omin `r(min)'
local omax `r(max)'
if "`max'"!="" & "`min'"!="" {
display as error "[`me']: please specify only max or min!"
exit 198
}
if "`min'"!="" {
capture confirm integer number `min'
if _rc {
display as error "[`me']: min must be an integer!"
exit _rc
}
}
else {
local min "`omin'"
}
if "`max'"!="" {
capture confirm integer number `max'
if _rc {
display as error "[`me']: max must be an integer!"
exit _rc
}
local min = `omin' - `omax' + `max'
}
forvalues oldval = `omin'/`omax' {
local newval = `omax'-`oldval'+`min'
local oldlab : label `old' `oldval'
if `"`oldlab'"'!="`oldval'" {
label define `new' `newval' `"`oldlab'"', modify
}
}
end