I want to merge data from three levels: individual---household---community,and nine waves: 1989,1991,1993,1997,2000,2004,2006,2009 and 2011,to merge as unbalanced panel data, the basic master file I used is rst1.dta, about the relationship of family numbers. If the person answered the survey, mark his/her a specific IDind, and ask him/her who is your father/mother/spouse, mark as IDind_f,IDind_m,IDind_s respectively, and ask him/her the relationship to the head of the household,mark as a5,
a5=0,head of household,a5=1,spouse;a5=2,father/mother;a5=3,son/daughter;a5=4,brother/sister
1. I need to match a child's mother and father in each year(Because the analysis object is child, about how family factors affect a child's health and education)
2.I need to differentiate father,mother and children's height, weight, age and education, in the original dataset, they are mixed
3.I need to know the number of children in a specific family
This is rst file:
I use this file as basic master file to merge other files, and the question is, I need to differ variables of father,mother and child,for example, as age/height, I need to know height_m,height_f,height_c, age_f,age_m, age_c. The mothod I thought was to rename the using file,for example,treat all of them as mother,and use IDind_m as key to merge,and then repeat for father,spouse, so the left will be child, and I drop spouse because I don't need it. My code are as follows, but I when I sum age,
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
age | 157,207 35.73894 20.3092 -6.1 108.8
This isn't what I exactly want.
So I don't know how to do
a5=0,head of household,a5=1,spouse;a5=2,father/mother;a5=3,son/daughter;a5=4,brother/sister
1. I need to match a child's mother and father in each year(Because the analysis object is child, about how family factors affect a child's health and education)
2.I need to differentiate father,mother and children's height, weight, age and education, in the original dataset, they are mixed
3.I need to know the number of children in a specific family
This is rst file:
Code:
. use rst1,clear (Written by R. ) . sum IDind IDind_m IDind_f IDind_s a5 hhid wave Variable | Obs Mean Std. Dev. Min Max -------------+--------------------------------------------------------- IDind | 156,645 3.92e+11 9.46e+10 1.11e+11 5.52e+11 IDind_m | 38,601 3.98e+11 9.18e+10 1.11e+11 5.52e+11 IDind_f | 35,555 3.97e+11 9.18e+10 1.11e+11 5.52e+11 IDind_s | 66,118 3.79e+11 9.89e+10 1.11e+11 5.52e+11 a5 | 151,205 2.144466 1.934509 0 10 -------------+--------------------------------------------------------- hhid | 156,645 3.92e+08 9.46e+07 1.11e+08 5.52e+08 wave | 156,645 2000.816 7.683592 1989 2011
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
age | 157,207 35.73894 20.3092 -6.1 108.8
This isn't what I exactly want.
So I don't know how to do
Code:
*----------------------- *-merge individual data ------------------------ use rst1,clear merge m:1 IDind using mast1 drop _merge save mergeind,replace *Merge pexam use mergeind,clear merge 1:1 IDind wave using pexam1 drop _merge save mergeind,replace -*Ectract mother's height&weight use pexam1,clear rename IDind IDind_m rename height height_m rename weight weight_m save pexam_m,replace use mergeind,clear merge m:1 IDind_m wave using pexam_m drop if _merge==2 drop _merge save mergeind,replace -*Extract father's height&weight use pexam1,clear rename IDind IDind_f rename height height_f rename weight weight_f save pexam_f,replace use mergeind,clear merge m:1 IDind_f wave using pexam_f drop if _merge==2 drop _merge save mergeind,replace -*Exrtact spouse's height&weight use pexam1,clear rename IDind IDind_s rename height height_s rename weight weight_s save pexam_s,replace use mergeind,clear merge m:1 IDind_s wave using pexam_s drop if _merge==2 drop _merge save mergeind,replace -*Merge education use mergeind,clear merge 1:1 IDind wave using educ1 drop _merge save mergeind,replace -*Extract father's edu use educ1,clear rename IDind IDind_f rename a11 a11_f rename a12 a12_f rename a13 a13_f save educ_f,replace use mergeind,clear merge m:1 IDind_f wave using educ_f drop if _merge==2 drop _merge save mergeind,replace -*Extract mother's edu use educ1,clear rename IDind IDind_m rename a11 a11_m rename a12 a12_m rename a13 a13_m save educ_m,replace use mergeind,clear merge m:1 IDind_m wave using educ_m drop if _merge==2 drop _merge save mergeind,replace -*Extract spouse's edu use educ1,clear rename IDind IDind_s rename a11 a11_s rename a12 a12_s rename a13 a13_s save educ_s,replace use mergeind,clear merge m:1 IDind_s wave using educ_s drop if _merge==2 drop _merge save mergeind,replace -*Merge age use mergeind,clear merge 1:1 IDind wave using survey1 drop _merge save mergeind,replace -*Extract father's age use survey1,clear rename IDind IDind_f rename age age_f save survey_f,replace use mergeind,clear merge m:1 hhid IDind_f wave using survey_f drop if _merge==2 drop _merge save merge09,replace -*Extract mother's age use survey1,clear rename IDind IDind_m rename age age_m save survey_m,replace use mergeind merge m:1 hhid IDind_m wave using survey_m drop if _merge==2 drop _merge save mergeind,replace -*Extract spouse's age use survey1,clear rename IDind IDind_s rename age age_s save survey_s,replace use mergeind merge m:1 hhid IDind_s wave using survey_s drop if _merge==2 drop _merge save mergeind,replace *------------- *-Household level *------------- -*Merge subh1 use mergeind,clear merge m:1 hhid wave using subh1 drop if _merge==2 drop _merge save merghh,replace -*Merge hhinc1 use mergehh,clear merge m:1 hhid wave using hhinc1 drop if _merge==2 drop _merge save mergehh,replace -*Merge asset1 use mergehh,clear merge m:1 hhid wave using asset1 drop if _merge==2 drop _merge save mergehh,replace *-------------------------------- *-Merge community level *-------------------------------- use mergehh,clear merge m:1 commmid wave using commin1 drop _merge save mergecomm,replace use mergecomm,clear merge m:1 commid wave using communityfm1 drop _merge save mergecomm,replace
Comment