-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrenamevaluelabel.ado
46 lines (34 loc) · 1.3 KB
/
renamevaluelabel.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
program define renamevaluelabel
// Written by Shafique Jamal ([email protected]). 25 Nov 2012
// syntax anything(id="variable and values" name=arguments)
syntax anything(id="original and new label name" name=labelnames)
version 9.1
// steps:
// 1. drop the label with the new label name, if it exists
// 2. create the new label from the old label
// 3. apply this new label to variables with the old label
// di "labelnames = `labelnames'"
foreach item of local labelnames {
// di `"item = `item'"'
}
tempname originallabelname
local `originallabelname' : word 1 of `labelnames'
tempname newlabelname
local `newlabelname' : word 2 of `labelnames'
// di `"``originallabelname'', ``newlabelname''"'
// Step 1. drop the label with the new label name, if it exists
cap label drop ``newlabelname''
// Step 2. create the new label from the old label
label copy ``originallabelname'' ``newlabelname''
// Step 3. replace value labels of variables that have the old label, with this new label
tempname valuelabelofvariabel
foreach var of varlist * {
local `valuelabelofvariabel' : value label `var'
if ("``valuelabelofvariabel''"=="``originallabelname''") {
// di "---------------------------------"
// d `var'
label values `var' ``newlabelname''
// d `var'
}
}
end