Hello,

I am trying to drop all observations in my dataset that have the value "0" in variable "occsoc". Unfortunately, the command

drop if occsoc=0

is returning 'type mismatch'.

This may be because the variable has leading blanks. So to play it safe I created an identical variable 'occsoc_num' and removed the leading blanks with strtrim(occsoc_num). But the command

drop if occsoc_num=0

is still returning 'type mismatch'.

Please see my screenshot below (I know we are not supposed to post screenshots in the forum, but I wasn't able to make dataex work for this example):

Array
I think the 'type mismatch' error may have something to do with the fact that occsoc (and therefore occsoc_num) are string variables. However, these variables contain 'X' in addition to numbers (see data extract below). Can I destring a variable that includes the character X? Numerically, all X's could be replaced with a 0.


See example below:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str6 occsoc
"     0"
"     0"
"436010"
"173020"
"     0"
"     0"
"     0"
"436010"
"     0"
"471011"
"395012"
"311010"
"319091"
"252020"
"513020"
"412010"
"     0"
"     0"
"     0"
"434051"
"     0"
"     0"
"     0"
"491011"
"212011"
"     0"
"537064"
"     0"
"372012"
"499071"
"     0"
"     0"
"     0"
"373010"
"514XXX"
"436010"
"     0"
"113031"
"232011"
"399011"
"434181"
"351012"
"372012"
"     0"
"332011"
"252020"
"     0"
"     0"
"37201X"
"37201X"
"     0"
"     0"
"472111"
"436010"
"37201X"
"412010"
"212011"
"352010"
"     0"
"     0"
"372012"
"435081"
"     0"
"     0"
"     0"
"292021"
"519196"
"411011"
"     0"
"131070"
"151122"
"     0"
"     0"
"     0"
"     0"
"516063"
"311010"
"     0"
"352010"
"     0"
"471011"
"     0"
"471011"
"273043"
"     0"
"     0"
"412010"
"411011"
"     0"
"434051"
"291141"
"151150"
"291060"
"253000"
"     0"
"     0"
"     0"
"111021"
"395012"
"     0"
end

Best of thanks for your consideration.