Hello all: I am trying tweak this code here to make it copy variables label AND copy the values labels from the value label do file I created. How do I sneak in the code to apply the value labels to the collapsed file? The variable label part works well.
label save using txlabel-v1.do, replace
// COPY VARIABLE LABELS PRECOLLAPSE
foreach v of var * {
local l`v' : variable label `v'
if `"`l`v''"' == "" {
local l`v' "`v'"
}
}
// Collapsing/relabel row level tx data for final merges for consumption by 05_allmerge-v1.do later.
{
preserve
collapse (firstnm) clltx1-rttxn (max) cllchem-txnonlymphoma (firstnm) rttx1cat-clltx1cat rtx1-tox, by(studyid) // Reuse copied variable labels
foreach v of var * {
label var `v' `"`l`v''"'
}
save ".\rtproject\rawdata\05.1_txcollapsed-v1.dta", replace
restore
}
save ".\rtproject\rawdata\05_txcleaned-v1.dta", replace // Cleaned Tx-response file
* Example generated by -dataex-. For more info, type help dataex
clear
input int studyid byte rtx1
1 .
1 .
1 .
1 .
1 .
1 .
1 .
1 .
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
3 .
3 .
3 .
3 .
3 .
3 .
3 .
3 .
3 6
3 6
3 6
3 6
3 6
3 6
3 6
3 6
4 .
4 .
4 .
4 .
4 .
4 .
4 .
4 .
4 6
4 6
4 6
4 6
4 6
4 6
4 6
4 6
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
6 .
6 .
6 .
6 .
6 .
6 .
6 .
6 .
6 2
6 2
6 2
6 2
6 2
6 2
6 2
6 2
7 .
7 .
7 .
7 .
end
label values rtx1 rtx1
label def rtx1 2 "BTKi/BCL2i", modify
label def rtx1 6 "Chemo-R-CHOP/CHOP-like", modify
[/CODE]
label save using txlabel-v1.do, replace
// COPY VARIABLE LABELS PRECOLLAPSE
foreach v of var * {
local l`v' : variable label `v'
if `"`l`v''"' == "" {
local l`v' "`v'"
}
}
// Collapsing/relabel row level tx data for final merges for consumption by 05_allmerge-v1.do later.
{
preserve
collapse (firstnm) clltx1-rttxn (max) cllchem-txnonlymphoma (firstnm) rttx1cat-clltx1cat rtx1-tox, by(studyid) // Reuse copied variable labels
foreach v of var * {
label var `v' `"`l`v''"'
}
save ".\rtproject\rawdata\05.1_txcollapsed-v1.dta", replace
restore
}
save ".\rtproject\rawdata\05_txcleaned-v1.dta", replace // Cleaned Tx-response file
* Example generated by -dataex-. For more info, type help dataex
clear
input int studyid byte rtx1
1 .
1 .
1 .
1 .
1 .
1 .
1 .
1 .
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
2 .
3 .
3 .
3 .
3 .
3 .
3 .
3 .
3 .
3 6
3 6
3 6
3 6
3 6
3 6
3 6
3 6
4 .
4 .
4 .
4 .
4 .
4 .
4 .
4 .
4 6
4 6
4 6
4 6
4 6
4 6
4 6
4 6
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
5 .
6 .
6 .
6 .
6 .
6 .
6 .
6 .
6 .
6 2
6 2
6 2
6 2
6 2
6 2
6 2
6 2
7 .
7 .
7 .
7 .
end
label values rtx1 rtx1
label def rtx1 2 "BTKi/BCL2i", modify
label def rtx1 6 "Chemo-R-CHOP/CHOP-like", modify
[/CODE]
Comment