I would like to create an indicator variable "Biokids" using the following variable listed in the snapshot below (r2ownkidkn-r12ownkidkn), that would result in the following:
This is the coding that I attempted, which did not work:
if r2ownkidkn-r12ownkidkn are missing datat, i.e., "." then return "0" for Biokids, orHere is a snapshot of the variables and what I would like the new indicator variable "Biokids" to show, given the results in r2ownkidkn-r12ownkidkn.
if r2ownkidkn-r12ownkidkn = 0 then return "0" for Biokids, otherwise
Biokids = 1 (meaning there is a result greater than zero, or not missing, in the series r2ownkidkn-r12ownkidkn)
hhidpn | r2ownkidkn | r3ownkidkn | r4ownkidkn | r5ownkidkn | r6ownkidkn | r7ownkidkn | r8ownkidkn | r9ownkidkn | r10ownkidkn | r11ownkidkn | r12ownkidkn | Biokids |
1234 | 4 | 0 | 0 | . | . | . | . | . | . | . | . | 1 |
5678 | 8 | 8 | 8 | 8 | . | . | . | . | . | . | . | 1 |
9101 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | 5 | . | 1 |
2134 | . | . | . | . | . | . | . | . | . | . | . | 0 |
5167 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
generate byte Biokids = 1Any ideas or assistance would be much appreciated.
foreach v of varlist r2ownkidkn-r12ownkidkn {
replace Biokids = 0 if (r2ownkidkn-r12ownkidkn) ==0
}
else replace Biokids = 0 if (r2ownkidkn-r12ownkidkn) ==.
}
Comment