Dear all,
I am trying to generate a date of birth using century month code (CMC) format. I found SPSS code from Unicef website (MICS data) that does what I want. To be honest, I am very new to SPSS so I can understand some commands and operators in SPSS and convert them to Stata such as compute equals generate command in Stata. But, I do not totally understand about if and trunc functions in the following SPSS code. Thus, I would appreciate it if someone who is familiar with both SPSS and Stata could help me out with this issue.
In this code example, WM8Y is years of birth and WM8M is months of birth, WM9 is age in years, cmcdoiw is date of interview in CMC format, and values 9996 and 96 denote don't know.
I am trying to generate a date of birth using century month code (CMC) format. I found SPSS code from Unicef website (MICS data) that does what I want. To be honest, I am very new to SPSS so I can understand some commands and operators in SPSS and convert them to Stata such as compute equals generate command in Stata. But, I do not totally understand about if and trunc functions in the following SPSS code. Thus, I would appreciate it if someone who is familiar with both SPSS and Stata could help me out with this issue.
In this code example, WM8Y is years of birth and WM8M is months of birth, WM9 is age in years, cmcdoiw is date of interview in CMC format, and values 9996 and 96 denote don't know.
Code:
* calculate the CMC date of birth and age. do if (WM8Y < 9996 and WM8M < 96). + compute wdob = (WM8Y - 1900)*12 + WM8M. else if (WM8Y < 9996). + compute aldob = cmcdoiw - WM9*12 - 11. + compute audob = cmcdoiw - WM9*12 - 0. + compute ldob = (WM8Y - 1900)*12 + 1. + compute udob = (WM8Y - 1900)*12 + 12. + if (ldob >= aldob & ldob <= audob) wdob = trunc(rv.uniform(ldob,audob)). + if (aldob >= ldob & aldob <= udob) wdob = trunc(rv.uniform(aldob,udob)). + if (ldob > audob | aldob > udob) wdob = trunc(rv.uniform(aldob,audob)). else. + compute aldob = cmcdoiw - WM9*12 - 11. + compute audob = cmcdoiw - WM9*12 - 0. + compute wdob = trunc(rv.uniform(aldob,audob)). end if.
Comment