Hello,
I want to calculate the sum of only certain categories' value in a group. Here is a part of the sample (I randomly chose the numbers).
In Family 1, there are three family members; in Family 2, four family members; and in Family 3, two members.
I want to calculate the sum of Person 1 and 2's income. So, for Family 1, it should be 100+110 = 220 and for Family 2, 50+60=110.
I want to create this below data set:
I tried to use this code, but I don't know how to make conditions.
bys Family: egen Income_1_2 = total(Income)
Thank you in advance.
I want to calculate the sum of only certain categories' value in a group. Here is a part of the sample (I randomly chose the numbers).
| Family | Person | Income |
| 1 | 1 | 100 |
| 1 | 2 | 110 |
| 1 | 3 | 130 |
| 2 | 1 | 50 |
| 2 | 2 | 60 |
| 2 | 3 | 70 |
| 2 | 4 | 80 |
| 3 | 1 | 40 |
| 3 | 2 | 50 |
I want to calculate the sum of Person 1 and 2's income. So, for Family 1, it should be 100+110 = 220 and for Family 2, 50+60=110.
I want to create this below data set:
| Family | Person | Income | Income_1_2 |
| 1 | 1 | 100 | 210 |
| 1 | 2 | 110 | 210 |
| 1 | 3 | 130 | 210 |
| 2 | 1 | 50 | 110 |
| 2 | 2 | 60 | 110 |
| 2 | 3 | 70 | 110 |
| 2 | 4 | 80 | 110 |
| 3 | 1 | 40 | 90 |
| 3 | 2 | 50 | 90 |
bys Family: egen Income_1_2 = total(Income)
Thank you in advance.

Comment