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
}
Related Posts with Problem with missing/ sample n for derived variables
How to count each binary variables and only generate one variable to include all count information?Hi there, I have a set of binary variables and each of them stands for a certain health disease (e.…
discrete-time survival analysis (xtcloglog)Hi everyone, I am running a discrete-time survival analysis about firm survival on an unbalanced pan…
interaction variable with i. operatorI want to run the following regression Code: reghdfe ABPROD BORDERLINE POST BORDERLINE_POST i.sic…
Difference-in-Difference with continuous variables and fixed effectsDear Stata friends I try to run a difference-in-difference regression with a continuous treatment (…
Double loops in Stata?Dear All, I want to do the following: Code: local replace replace forvalues i = 2007(1)2017 { for…
Subscribe to:
Post Comments (Atom)
0 Response to Problem with missing/ sample n for derived variables
Post a Comment