In order to open source variableMetadataExtractor we need to find a way to randomize (without replacement) the order of each variable to ensure anonymity while keeping univariate properties of the variables. I need help from our stata experts (@AndyDaniel1 @anneweber or @danbfdz ?), as stata loses the value labels and I cannot save multilinguale stata-datasets in R.
@rbirkelbach as discussed here the code for stata to assign value labels (label container) to a (new) variable:
label values _varlist_ _lblname_
Here you can find the stata documentation for assigning labels: https://www.stata.com/manuals13/dlabel.pdf
I'm currently stuck here:
foreach var of varlist pid-end_y {
label values `("`var'"+_shuffled")' : value label `var'
}
Solution adopted from @AndyDaniel1 (slightly altered):
foreach var of v_first-v_last{
local vlabel: value label `var' //Write value labels to local
label values `var'_shuffled `vlabel' //Use vlabel as value label from `var'_shuffled
}
So now I need to adopt it to the variable label case and it's done.
foreach var of v_first-v_last{
local vlabel: value label `var' //Write value labels to local
local varlab: variable label `var' //Write variable labels to local
label values `var'_shuffled `vlabel' //Use vlabel as value label from `var'_shuffled
label variable `var'_shuffled `varlab' //Use varlab as variable label from `var'_shuffled
}
This should work as a comprehensive solution for val and var labs .
Thx! Will test that on monday.
It doesn't work (syntax error). Can we try to fix it together when you're back at work?
@AndyDaniel1 do you know how I can get rid of the suffix "_shuffled" from all variables of a given dataset?
@rbirkelbach
rename *_shuffled *
thx