I am working with string data and I would like to identify observations that have special characters ("/" "?" "*" "(" "." ")" and others), numbers and whitespace (except leading and trailing spaces) in a string variable.
The dataset is like
string_var |
E.V.A |
F7010P |
175/70R14 |
C B U Q |
*E.D.T.A |
(S6X60D) |
COLA |
In particular, I would like the dataset to be as the following
string_var | has_special_char |
E.V.A | 1 |
F7010P | 1 |
175/70R14 | 1 |
C B U Q | 1 |
*E.D.T.A | 1 |
(S6X60D) | 1 |
COLA | 0 |
Could you help me to find a solution for that?
Thank you very much!
Below I provide the code for importing the example dataset into Stata:
clear
input str10 string_var
"E.V.A"
"F7010P"
"175/70R14"
"C B U Q"
"*E.D.T.A"
"(S6X60D)"
"COLA"
end
0 Response to How to identify observations with special characters, numbers and whitespaces (expect leading and trailing spaces) - string var
Post a Comment