I am using Stata 15 MP
My questionnaire dataset: obs: 7,153 vars: 1,714 size: 26,938,198

I have variables that are incorrectly coded. They have missing instead of 'Not answered'
I need therefore to use a completion variable to recode the missings into not answered and truly missing.

So variables:
xz3001 (and others) Coded 0=no 1=once 2=two times 3=three times .=missing
xza Numeric (int) Age in months at completion range [1137, 1166] unique values: 25 Missing 1,141 examples: 1140 1140 1141 1143

I have tried generating a dummy variable and recoding very many ways and am getting stuck each time. I have gotten to as below but it is not working. What am I coding wrongly?


foreach item of varlist xz3001 xz3101 xz3201 xz3301 {
gen notimes_`item'=xza
replace notimes_`item'=`item' if xza>0.5
replace notimes_`item'=. if xza==.
replace notimes_`item'=0 if xza>0.5&`item'>0.5
_crcslbl notimes_`item' `item'
tab `item',miss
tab notimes_`item',miss
tab notimes_`item' xz,miss
}