Announcement

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

  • replacing the age of the child with zero if certain condition of the mother is fulfilled

    I have a data where the age of the child is 1 but I want to replace all the household with children aged 1 to zero which fulfills the following condition

    If the age difference between age of the person(age) and the age at first birth(D1) is 1 and there is a new born in the household whose age is 1(age is 1) then I want to replace all the age of the child with age 1 to be zero.
    An example of my data
    HID PPID Rela sex age D1 D2
    1 1 Head 2. Female 26 1. Yes 25
    1 2 Daughter 2. Female 1
    2 1 Head 2. Female 30 1. Yes 29
    2 2 Daughter 2. Female 1
    3 1 Head 2. Female 31 1. Yes 30
    3 2 Daughter 2. Female 1
    4 1 Head 2. Female 17 1. Yes 15
    4 2 Daughter 2. Female 1
    Can you please suggest how can I do that in STATA

    thank you

  • #2
    Welcome to Statalist.

    To start with, it is not clear to me that what you want to do is advisable.

    Are you certain that your households contain only one family? The panel data I have worked with often will have, for example, a husband and wife who are the "heads" of the household, and then an adult son or daughter living with them, who in turn has one or more children of his or her own. The identifiers you show in your data do not seem sufficient to ensure that the daughter is the daughter of the head. But perhaps what you are calling a household is actually a family.

    Perhaps this sample code using your data will start you in a useful direction.
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(hid ppid) str8 rela str9 sex byte age str6 d1 byte d2
    1 1 "Head"     "2. Female" 26 "1. Yes" 25
    1 2 "Daughter" "2. Female"  1 ""        .
    2 1 "Head"     "2. Female" 30 "1. Yes" 29
    2 2 "Daughter" "2. Female"  1 ""        .
    3 1 "Head"     "2. Female" 31 "1. Yes" 30
    3 2 "Daughter" "2. Female"  1 ""        .
    4 1 "Head"     "2. Female" 17 "1. Yes" 15
    4 2 "Daughter" "2. Female"  1 ""        .
    end
    generate t1 = 0
    replace t1 = 1 if rela=="Head" & d1=="1. Yes" & d2==age-1
    bysort hid (ppid): egen t2 = max(t1)
    generate newage = age
    replace newage = 0 if rela=="Daughter" & age==1 & t2==1
    list, sepby(hid) noobs
    which gives the following results
    Code:
    . list, sepby(hid) noobs
    
      +--------------------------------------------------------------------------+
      | hid   ppid       rela         sex   age       d1   d2   t1   t2   newage |
      |--------------------------------------------------------------------------|
      |   1      1       Head   2. Female    26   1. Yes   25    1    1       26 |
      |   1      2   Daughter   2. Female     1             .    0    1        0 |
      |--------------------------------------------------------------------------|
      |   2      1       Head   2. Female    30   1. Yes   29    1    1       30 |
      |   2      2   Daughter   2. Female     1             .    0    1        0 |
      |--------------------------------------------------------------------------|
      |   3      1       Head   2. Female    31   1. Yes   30    1    1       31 |
      |   3      2   Daughter   2. Female     1             .    0    1        0 |
      |--------------------------------------------------------------------------|
      |   4      1       Head   2. Female    17   1. Yes   15    0    0       17 |
      |   4      2   Daughter   2. Female     1             .    0    0        1 |
      +--------------------------------------------------------------------------+

    Comment


    • #3
      Thank you but the relation of the person who is 1 year old can be anything not just daughter. For example in the household the age 1 can be son, daughter , niece, nephew or other family relatiove. And the relationship is not necessarily head. It can be spouse or other relationship. How do we then assign age of the child with age to be 1 if the difference between the age of the woman in that household and the age at first birth is 1.

      Your valuable comment will be very helpful

      Thank you

      Comment


      • #4
        If the data for the child does not include the identifier of its mother, it is not possible to do this reliably.

        That is what I expressed my concern about at the start of post #2. I suspected, and you have confirmed, that your pretend data is not at all realistic.

        Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post, looking especially at sections 9-12 on how to best pose your question. It is particularly helpful to post a small hand-made example, perhaps with just a few variables and observations, showing a realistic variety of the data before the process - not just mothers and daughters, but complicaged households - and how you expect it to look after the process. In particular, please read FAQ #12 and use dataex and CODE delimiters when posting to Statalist.

        The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

        Comment

        Working...
        X