~dricottone/ado-personal

ref: 9c2e7acaeba0ce0eb93bdfc0d3f97a9c35a35059 ado-personal/cf_varlabels.ado -rw-r--r-- 857 bytes
9c2e7aca — dricottone Formatting 3 years ago
                                                                                
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
// Dominic R, 7/1/2020

program cf_varlabels
	args file1 file2
	if "`file1'"=="" {
		display as error "No such file '`file1''"
		error(601)
	}
	if "`file2'"=="" {
		display as error "No such file '`file2''"
		error(601)
	}
	use "`file1'", clear
	foreach v of varlist _all {
		if strlen("`v'")==31 {
			local shortened = substr("`v'",1,30)
			local _`shortened': variable label `v'
		}
		else {
			local _`v': variable label `v'
		}
	}
	use "`file2'", clear
	foreach v of varlist _all {
		local file2label: variable label `v'
		
		if strlen("`v'")==31 {
			local shortened = substr("`v'",1,30)
			local file1label `_`shortened''
		}
		else {
			local file1label `_`v''
		}
		
		capture assert "`file1label'"=="`file2label'"
		if _rc!=0 {
			display "Labels changed in `v':"
			display "  File 1: `file1label'"
			display "  File 2: `file2label'"
		}
	}
end