Hello all,
For data cleaning purposes, I'm trying to find a quick and efficient way to list variables that do not meet a certain condition. For instance, if I'm expecting a group of variable (who have the same name structure for instance) to have a range going from 1 to 5, I would be interested to know all the variables that have at least one observation superior to 5, or out of the range from 1 to 5. Or if I'm expecting a group of variable to only have "Yes" or "No" or "I don't know" as an answer, I would like to know all the variables that have another option than these three. That way, I can store the variables in a macro and make adjustments for each of these variables in a loop using this macro.
For instance here, if I ask Stata to report all variables among Bs that have at least one observation different than 1, 2, 3, 4, or 5 (yes, in String, because I also want to check before destringing it if there is any nonnumeric value too), I expect it to return B1. And if I ask Stata to report all variables among As that have at least one observation different than "Yes" or "No", I expect it to return A2. Is there any command or function that can do something like this ?
Thanks a lot for your help.
For data cleaning purposes, I'm trying to find a quick and efficient way to list variables that do not meet a certain condition. For instance, if I'm expecting a group of variable (who have the same name structure for instance) to have a range going from 1 to 5, I would be interested to know all the variables that have at least one observation superior to 5, or out of the range from 1 to 5. Or if I'm expecting a group of variable to only have "Yes" or "No" or "I don't know" as an answer, I would like to know all the variables that have another option than these three. That way, I can store the variables in a macro and make adjustments for each of these variables in a loop using this macro.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 A1 str4 A2 str2 B1 str1 B2 "Yes" "Yes" "2" "3" "No" "Blue" "30" "2" "No" "Yes" "2" "5" "No" "No" "7" "1" end
Thanks a lot for your help.
Comment