~dricottone/ado-personal

ref: fa4c1624b47056a024f2e931cc742209fa3c0612 ado-personal/cf_vallabels.ado -rw-r--r-- 1.2 KiB
fa4c1624Dominic Ricottone Time travel 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
44
45
46
47
48
49
50
51
// Dominic R, 7/1/2021

program cf_vallabels
	args file1 file2

	clear
	use "`file1'"
	tempfile labels1
	quietly log using "`labels1'", text
	label list
	quietly log close

	clear
	quietly import delimited "`labels1'"
	quietly {
		generate flag_variable=strpos(v1,":")==strlen(v1)
		generate flag_value=strpos(v1,"        ")==1
		keep if flag_variable==1 | flag_value==1
		generate variable=v1 if flag_variable==1
		replace variable=variable[_n-1] if flag_variable==0
		generate value=v1 if flag_value==1
		keep if flag_value==1
	}
	keep variable value
	tempfile dictionary1
	save "`dictionary1'"

	clear
	use "`file2'"
	tempfile labels2
	quietly log using "`labels2'", text
	label list
	quietly log close

	clear
	quietly import delimited "`labels2'"
	quietly {
		generate flag_variable=strpos(v1,":")==strlen(v1)
		generate flag_value=strpos(v1,"        ")==1
		keep if flag_variable==1 | flag_value==1
		generate variable=v1 if flag_variable==1
		replace variable=variable[_n-1] if flag_variable==0
		generate value=v1 if flag_value==1
		keep if flag_value==1
	}
	keep variable value

	merge 1:1 variable value using "`dictionary1'"
	list _merge variable value if _merge!=3
end