I am trying to use the classic -decode- / -encode- combination that one should use when appending datasets with a variable labeled differently across files. However, it appears that in the different files I am trying to append, one variable can :
1) either have a label with labeled values
2) or have a label but without labeled values
I am using the following code:
But for datasets having variables facing the problem 2), I get the following output:
value label A4B not found
r(111);
Indeed, when I run
, it is written "Type: Numeric (byte) Label: A4B, but label does not exist".
What can I do to make this code run? The loop stopped at this dataset:
a4a is a variable that got successfully decoded, a4b did not. I could try using the command "capture label val `varlabel'" within the loop, but I think this will make it worse as I think it will make my labeled variables label-less. Is there some sort of way to assert that a variable actually has labels for its values ?
Thanks for the help!
1) either have a label with labeled values
2) or have a label but without labeled values
I am using the following code:
Code:
foreach country of global countrieslist {
use ``country'', clear
foreach varlabel of global label_variables {
capture confirm variable `varlabel' // Check whether variable exists in every dataset
if !_rc {
decode `varlabel', gen(_`varlabel')
drop `varlabel'
rename _`varlabel' `varlabel'
}
}
save ``country'_AR', replace
}
foreach country of global countrieslist {
append using ``country'_AR'
}
value label A4B not found
r(111);
Indeed, when I run
Code:
codebook a4b
What can I do to make this code run? The loop stopped at this dataset:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input byte(a1 a4b) str19 a4a 12 52 "Retail" 12 52 "Retail" 12 51 "Other Services" 12 51 "Other Services" 12 52 "Retail" 12 52 "Retail" 12 51 "Other Manufacturing" 12 51 "Other Manufacturing" 12 52 "Retail" 12 52 "Retail" 12 51 "Other Services" 12 51 "Other Services" 12 52 "Retail" 12 52 "Retail" 12 52 "Other Services" 12 52 "Other Services" 12 51 "Other Services" 12 51 "Other Services" 12 52 "Retail" 12 52 "Retail" end label values a1 A1 label def A1 12 "El Salvador", modify label values a4b A4B
Thanks for the help!

Comment