Hi everyone,
I'm currently writing a master's thesis and using a dataset that looks like this:
The explanation of the variables is as follows:
I'm using the code shown in this topic:
(modified with help from ChatGPT):
Any kind of help would be greatly appreciated.
I'm currently writing a master's thesis and using a dataset that looks like this:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float(fam_id mem_id relation gender marital educ) 1 1 1 1 2 4 1 2 2 0 2 3 1 3 3 1 1 2 2 1 1 1 2 4 2 2 2 0 2 4 2 3 3 0 1 3 2 4 3 0 1 2 2 5 3 0 1 0 3 1 1 1 2 3 3 2 2 0 2 4 3 3 3 1 2 4 3 4 5 0 2 4 3 5 6 1 1 0 4 1 1 0 2 3 4 2 2 1 2 3 4 3 3 1 2 4 4 4 5 0 2 4 4 5 6 1 1 0 4 6 4 0 2 4 4 7 5 1 2 3 4 8 6 1 1 1 4 9 6 1 1 0 5 1 1 1 3 4 5 2 3 0 2 3 5 3 5 1 2 4 5 4 6 1 1 0 6 1 1 1 2 4 6 2 2 0 2 4 6 3 3 0 3 3 6 4 6 1 1 0 end
- Relationship: 1 "Head of household," 2 "Spouse," 3 "Child/stepchild," 4 "Foster child," 5 "Son/daughter-in-law," 6 "Grandchild"
- Gender: 0 "Female," 1 "Male"
- Marital Status: 1 "Not married," 2 "Married," 3 "Divorced"
- Education: 0 "Uneducated," 1 "Elementary school," 2 "Middle school," 3 "High school," 4 "College"
I'm using the code shown in this topic:
HTML Code:
https://www.statalist.org/forums/forum/general-stata-discussion/general/1518828-generating-parents-education-variable
Code:
// Generate binary variables for child and parent relationships gen byte child1 = (relation == 3) gen byte child2 = (relation == 6) gen byte father1 = (relation == 1 | relation == 2) & (gender == 1) & (marital == 2 | marital == 3) gen byte father2 = (relation == 3 | relation == 4 | relation == 5) & (gender == 1) & (marital == 2 | marital == 3) gen byte mother1 = (relation == 1 | relation == 2) & (gender == 0) & (marital == 2 | marital == 3) gen byte mother2 = (relation == 3 | relation == 4 | relation == 5) & (gender == 0) & (marital == 2 | marital == 3) // Calculate minimum educational attainment for fathers and mothers egen father_educ1 = min(educ / father1), by(fam_id) egen mother_educ1 = min(educ / mother1), by(fam_id) // Recode educational attainment to missing for non-child cases replace father_educ1 = . if !child1 replace mother_educ1 = . if !child1 egen father_educ2 = min(educ / father2), by(fam_id) egen mother_educ2 = min(educ / mother2), by(fam_id) // Recode educational attainment to missing for non-child cases replace father_educ2 = . if !child2 replace mother_educ2 = . if !child2
Comment