My dataset has around 1300 columns (variables) with about 900 come with value labels.
For example, in the gender variable called "pt1a". 1 is labeled as "Male", 2 is labeled as "Female", 5 is labeled as "Transgender"...
However, there's a chance of having invalid data (e.g., 99 or 98) in the gender variable, same happened to the other variables.
I want to find out (list) all the variables that contain any "yet-to-be-labeled" values.
I used the following code, but it doesn't seem to work. The "serviceid" variable has all value labelled, but the code result also include it (see the sample data).
Sample data attached.
Thanks.
For example, in the gender variable called "pt1a". 1 is labeled as "Male", 2 is labeled as "Female", 5 is labeled as "Transgender"...
However, there's a chance of having invalid data (e.g., 99 or 98) in the gender variable, same happened to the other variables.
I want to find out (list) all the variables that contain any "yet-to-be-labeled" values.
I used the following code, but it doesn't seem to work. The "serviceid" variable has all value labelled, but the code result also include it (see the sample data).
Code:
quietly ds, has(vallabel) // List variables with value labels local vallabelled_vars `r(varlist)' foreach var of local vallabelled_vars { quietly tabulate `var', missing nolabel // Tabulate values without labels if r(miss) > 0 { // If there are uncoded values di "`var' has uncoded values" } }
Thanks.
Comment