Dear Statalisters,
I am trying to count the number of children falling in certain age categories.
The age is provided by the year of birth of each child: i.e q7210y_1 for child 1 , q7210y_2 for child 2 until child 17.
It was easy to do it for children younger three years of age or younger as below.
yet, it would be harder when trying to identify the number of children older than 6 years old. So, I tried to automate it as below but something went wrong:
Could you please guide me to a solution to this issue?
Best regards,
Maye
I am trying to count the number of children falling in certain age categories.
The age is provided by the year of birth of each child: i.e q7210y_1 for child 1 , q7210y_2 for child 2 until child 17.
It was easy to do it for children younger three years of age or younger as below.
Code:
*Number of children three years old or younger gen nochild3age=0 foreach x of varlist q7210y* { replace nochild3age =1 if `x'==2012 | `x'==2011 | `x'==2010 replace nochild3age =3 if `x'==2012 & `x'==2011 & `x'==2010 replace nochild3age =2 if `x'==2012 & `x'==2011 replace nochild3age =2 if `x'==2011 & `x'==2010 } lab var nochild3age "number of children aged three years old or younger. Year of birth of children is 2012,2011 or 2010"
Code:
*No of children older than 3 and less than 7 gen nochild4to6age=0 foreach x of varlist q7210y* { bysort indid: count if `x'>2006 & `x'<2010 local counting=r(N) replace nochild4to6age = `counting' }
Best regards,
Maye
Comment