Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creation of variable "mother of a single-parent family" - HELP

    Dear community,

    I hope you can help me.

    I need to create a variable for >>> single mother heads of family<<<< , since the database I'm using does not contain the type of family and this complicates my analysis.

    I have the code of each family and the following variables that can help:
    • Gender: 0 male, 1 female
    • Parentage: 1 Head of household, 2 spouse, 3 child, 4 others
    • Family status: 0 single, 1 married
    So I tried several ways to create a variable for that:
    Single mother = Female (Gender=1), Head of household (Parentage=1), Single (Family status=0) + with at least one member of her family being a child (Parentage=3)
    I've tried creating a variable just for being a son, another one for only married women, but I can't link everything together.

    Can you help me?


  • #2
    As you do not show example data, I have written code for an imaginary data set that, hopefully, is reasonably similar to what you have. You will have to adapt the code to fit your actual data.

    Code:
    by household, sort: egen has_child = max(parentage == 3)
    gen byte single_mom_head = has_child & gender == 1 & parentage == 1 & family_status == 0
    In the future, when asking for help with code, please use the -dataex- command and show example data. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X