My variables are id, year of birth of sibling, birth order, and gender. I need to create a dummy variable (Match_vbl in the example) by id that equals to 1 if the sex of the first two siblings is the same, and 0 otherwise. I already sorted by id and birth order, I just need a variable matching the first two gender observations like in the example below.
id | birth_year | order | gender | Match_vbl |
1 | 1998 | 1 | M | 1 |
1 | 1999 | 2 | M | 1 |
1 | 2002 | 3 | F | 1 |
2 | 1992 | 1 | M | 0 |
2 | 1995 | 2 | F | 0 |
0 Response to Generating a dummy variable for observations within another
Post a Comment