Hi there,
I have a question relating to a dataset that looks something like this:
The dataset has been created by merging two datasets from a national demographic survey: one with child-related information (collected via a survey where the respondents are knowledgeable adults) and the other with adult-related information (collected via addressing surveys to the adults themselves). The *_c* and *_a* of the variable names indicates which of the two datasets the variable comes from. ID is the variable which uniquely identifies observations - each child and each adult has a unique ID number. In the dataset above, IDs 1-5 are children; 6-9 are adults.
For my research I am interested primarily in child outcomes, such as anthropometric measures and school attendance. In analysing these variables, I need to add data about the caregiver of the child to each child's record. For example, in the child dataset, the ID number of the child's primary caregiver ('caregiver_id_c') is recorded, whereas the adult dataset contains data corresponding to that ID number (e.g. 'gender_a'). So what I would need to do is fill the final column above by creating a new variable, 'gender_caregiver', with values which are identical to the values of 'gender_a' when 'ID' is equal to 'caregiver_id_c'. For example, the first two rows include data for children with IDs 1 and 2. These children's caregiver has an ID of 6, and from the adult dataset, the gender of adult with ID 6 takes a value of 0. I need to add this 0 to the 'gender_caregiver' variable for children with IDs 1 and 2. I would have to repeat the process for children with IDs 3-5 using data from adults with IDs 7-9.
I've looked in the forums and Stata help without success. Generally what I have found is how to generate a new variable from a second variable using values of a third variable when the third variable takes on specific values (e.g. gen mpg2 = mpg if foreign==0). What I need is something like gen gender_caregiver = gender_a if caregiver_id_c = ID. I.e., gen var1 = var2 when var3 and var4 take on identical values, whatever that value may be.
I am using Stata version 13.0. This is my first post and I'm not that experienced with Stata, so apologies in advance if I haven't searched the forums and the Stata help sufficiently, or if this query is too basic.
Thanks,
Zoheb Khan
PhD candidate, Development Studies
University of Johannesburg
I have a question relating to a dataset that looks something like this:
ID | caregiver_id_c | gender_c | gender_a | gender_caregiver |
1 | 6 | 1 | ||
2 | 6 | 0 | ||
3 | 7 | 1 | ||
4 | 8 | 1 | ||
5 | 9 | 1 | ||
6 | 0 | |||
7 | 1 | |||
8 | 0 | |||
9 | 0 |
For my research I am interested primarily in child outcomes, such as anthropometric measures and school attendance. In analysing these variables, I need to add data about the caregiver of the child to each child's record. For example, in the child dataset, the ID number of the child's primary caregiver ('caregiver_id_c') is recorded, whereas the adult dataset contains data corresponding to that ID number (e.g. 'gender_a'). So what I would need to do is fill the final column above by creating a new variable, 'gender_caregiver', with values which are identical to the values of 'gender_a' when 'ID' is equal to 'caregiver_id_c'. For example, the first two rows include data for children with IDs 1 and 2. These children's caregiver has an ID of 6, and from the adult dataset, the gender of adult with ID 6 takes a value of 0. I need to add this 0 to the 'gender_caregiver' variable for children with IDs 1 and 2. I would have to repeat the process for children with IDs 3-5 using data from adults with IDs 7-9.
I've looked in the forums and Stata help without success. Generally what I have found is how to generate a new variable from a second variable using values of a third variable when the third variable takes on specific values (e.g. gen mpg2 = mpg if foreign==0). What I need is something like gen gender_caregiver = gender_a if caregiver_id_c = ID. I.e., gen var1 = var2 when var3 and var4 take on identical values, whatever that value may be.
I am using Stata version 13.0. This is my first post and I'm not that experienced with Stata, so apologies in advance if I haven't searched the forums and the Stata help sufficiently, or if this query is too basic.
Thanks,
Zoheb Khan
PhD candidate, Development Studies
University of Johannesburg
Comment