I want to generate an Indicator Variable that takes the value 1 for the Person 1, if in a ID group there exists a Person 3 otherwise 0.
The context: ID is unique to each household. Person 3 is a child of Person 1 in that household given by the ID. Want to generate HasAChild = 1 for Person = 1 when there exists a Person = 3 in the Household(given by the ID).
ID <- c(200, 200, 200, 211, 211, 222, 222, 222, 233, 233, 233, 233)
Person <- c(1, 3, 5, 1, 2, 1, 2, 3, 1, 2, 4, 5)
Is_A_Child <- c(0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0)
Has_A_Child <- c(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0)
df <- data.frame(ID, Person, Is_A_Child, Has_A_Child)