I want to create a new column in my cross-section survey dataset, that includes the education of a woman's husband. I have IDs of household (hid) and individual (HL1), and the following information:
- MA1== whether woman is married (data only observable for women)
- MA2== age of husband (data only observable for women who are married)
- HL4== sex (data observable for all individuals)
- HL6== age (data observable for all individuals)
- ED4A== highest level of education (data observable for all individuals)
In essence, I want to create code to do the following:
- First look at whether wife is currently married (MA1)
- If yes, then look at age of husband (MA2)
- Then pair age of husband (MA2) with age of male in household (HL6)
- Then see what that male's education is (ED4A) and put that education in a new column, but in the same row as the woman's line number.
I tried this but it doesn't work:
bysort hid (HL6) : gen husb_educ = ED4A[MA2]
Below is a sample from the dataset:
+-----+----------+-----+-----+--------+-----+----------+
| HL1 | MA1 | MA2 | hid | HL4 | HL6 | ED4A |
+-----+----------+-----+-----+--------+-----+----------+
| 1 | | | 106 | Male | 57 | Diploma |
| 2 | | | 106 | Female | 53 | Intermed |
| 3 | | | 106 | Male | 30 | Higher S |
| 4 | No, not | | 106 | Female | 24 | Bachelor |
| 5 | | | 106 | Male | 22 | Diploma |
| 6 | | | 106 | Male | 17 | Secondar |
| 7 | | | 106 | Female | 10 | Primary |
| 8 | Yes, cur | 22 | 106 | Female | 23 | Diploma |
| 9 | | | 106 | Female | 0 | |
+-----+----------+-----+-----+--------+-----+----------+
So in this example, I want a new column which says Husband's education, and in row 8, puts Diploma as the value in the new column (since the woman's husband is 22years old, and the male 22 year old in the household has a diploma).
Same sample, without value labels:
+-----+-----+-----+-----+-----+-----+------+
| HL1 | MA1 | MA2 | hid | HL4 | HL6 | ED4A |
+-----+-----+-----+-----+-----+-----+------+
| 1 | | | 106 | 1 | 57 | 4 |
| 2 | | | 106 | 2 | 53 | 2 |
| 3 | | | 106 | 1 | 30 | 6 |
| 4 | 3 | | 106 | 2 | 24 | 5 |
| 5 | | | 106 | 1 | 22 | 4 |
| 6 | | | 106 | 1 | 17 | 3 |
| 7 | | | 106 | 2 | 10 | 1 |
| 8 | 1 | 22 | 106 | 2 | 23 | 4 |
| 9 | | | 106 | 2 | 0 | |
+-----+-----+-----+-----+-----+-----+------+
One especially large household:
input
HL1 MA1 MA2 hid HL4 HL6 ED4A
1 . . 365809 1 33 1
2 1 33 365809 2 26 1
1 . . 365810 1 58 1
2 . . 365810 2 54 .
3 . . 365810 1 23 3
4 . . 365810 1 23 2
5 . . 365810 1 18 3
6 . . 365810 1 15 2
7 . . 365810 2 12 2
8 . . 365810 1 33 3
9 1 dk 365810 2 31 1
10 . . 365810 2 13 2
11 . . 365810 2 11 1
12 . . 365810 1 9 1
13 . . 365810 1 6 1
14 . . 365810 2 3 .
15 . . 365810 1 2 .
16 . . 365810 1 33 3
17 1 33 365810 2 30 1
18 . . 365810 1 8 1
19 . . 365810 2 6 1
20 . . 365810 2 5 .
21 . . 365810 1 1 .
22 . . 365810 1 32 4
23 1 32 365810 2 30 1
24 . . 365810 1 5 .
25 . . 365810 2 3 .
26 . . 365810 1 2 .
27 . . 365810 1 30 4
28 1 30 365810 2 28 1
29 . . 365810 2 2 .
30 . . 365810 1 0 .
31 . . 365810 1 27 2
32 1 27 365810 2 27 1
33 . . 365810 2 2 .
34 . . 365810 2 0 .
end
ED4A[42]within the current household. That will usually be missing and it's not what you want. - Nick Cox