Hello Stata Users :-)

I have a dataset comprised of 71 variables containing responses to items on a satisfaction survey.

All of the variables are measured on a 5-point Likert scale. Most of the variables are stored as numbers, but many are stored as strings.

Missing values for variables stored as numbers show up as "."

Missing values for variables stored as strings show up as "X"

Question: How can I write a looping command to change "X" values contained in string variables to "." values contained in numeric variables?

The code below gives a "type mismatch"

Code:
foreach var of varlist q1-q71 {
    replace `var' = "." if `var'=="X"
}
My hunch is that I must use an "if" statement to separate out string from numeric variables, but I have little experience writing loops within "if" statements. Any help would be very much appreciated.

Again, a sample of the data is below.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str1(q15 q16 q17 q18 q19)
"X" "4" "5" "4" "X"
"1" "5" "5" "2" "1"
"5" "5" "5" "5" "5"
"5" "5" "5" "5" "5"
"2" "4" "4" "4" "4"
"4" "4" "3" "2" "3"
"5" "2" "3" "1" "3"
"4" "5" "4" "5" "5"
"5" "5" "5" "4" "5"
"X" "2" "3" "2" "X"
end
Thanks so much,
Adam