Please help identify why this loop wont work on "`x'=="Z591". I get the message "type mismatch" before the command is fully executed.

generate vaed_homeless=0
foreach x of varlist TDIAG1-TDIAG40 {
recode vaed_homeless (0=1) if (`x'=="Z590"|`x'=="Z591")
}