A binary variable for children under the age of 7 in a given household
I hope you had a good holiday season. When you get the chance please help me with this one. I would like to define a binary variable equal to one if there is a child or more than one under the age of seven in a given household. My main data set consists of female characteristics and the characteristics of her husband or spouse. Essentially, I have only wives in my main dataset with their characteristics plus their spouses'.
I guess I must look at the w_child files to get the pidp of the child, the birthy of the child and the mnpid, which is the identification of the mother. Now the fun starts. How do I match or merge the information from the w_child files to my main file with wives' pidp only?
Once again I would highly appreciate your help.
#1 Updated by Stephanie Auty over 1 year ago
- Status changed from New to In Progress
- % Done changed from 0 to 10
- Private changed from Yes to No
Many thanks for your enquiry. The Understanding Society team is looking into it and we will get back to you as soon as we can.
Stephanie Auty - Understanding Society User Support Officer
#2 Updated by Stephanie Auty over 1 year ago
- Status changed from In Progress to Feedback
- Assignee changed from Alita Nandi to Stephanie Auty
- % Done changed from 10 to 80
It would be better to start with the w_indall file as all individuals are listed there. Keep the variables you will need (w_hidp, w_age_dv) then create a flag which indicates whether an individual is in the age range you want (0-7):
replace w_age_u7=1 if w_age_dv>=0 & w_age_dv<=7
Then use bysort w_hidp: to indicate whether each household contains a child of that age:
bysort w_hidp: replace w_hh_u7=1 if w_age_u7==1 | w_hh_u7[_n-1]==1
Then use another bysort to keep the last record for each household which will contain the correct flag for the household:
bysort w_hidp: keep if _n==_N
Just keep w_hidp and w_hh_u7, and merge this (m:1 or 1:m depending on the order of the files) with the other file you have created using w_hidp.