Announcement

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

  • sex of the first born child

    hi stata user ,

    I'm having trouble in generating sex of the first born child. can anyone help me ?

    information I have in the data
    unit of analysis : mother
    total number of children
    sex by birth order
    for eg b4_01(most recent birth) .......b4_19(first born)

    how can generate sex of the first born /?

    Click image for larger version

Name:	Screen Shot 2019-10-09 at 2.53.21 AM.png
Views:	1
Size:	1.08 MB
ID:	1519685

  • #2

    Code:
    * initialise: only the right answer for a mother with 19 children
    gen wanted = b4_19
    
    * count down 18 ... 1 making sure that 9 8 ... 2 1 are mapped to 09 08 ... 02 01.
    
    quietly forval k = 18(-1)1 {
        local K : display %02.0f `k'
        replace wanted = b4_`K' if missing(wanted)
    }

    Comment


    • #3
      Thank you Nick Cox !
      It worked

      Comment


      • #4
        You could also go

        Code:
        gen wanted = b4_01 
        
        forval k = 2/19 { 
              local K : display %02.0f `k' 
              replace wanted = b4_`K' if !missing(b4_`K') 
        }

        Comment


        • #5
          Nick Cox Hi nick,
          Thank you for help!

          I was able get sex of the 2nd born 3rd born and so on by using chain of commands. Is there a simpler and shorter ways of doing this?

          where b4_* is birth order b4_20 is last born ....b4_01 most recent birth
          v201 is # of children to a mother
          wanted birth order=1
          wanted 2 birth order = 2
          Wanted 3 birth order = 3 and so on

          Also attaching my Stata output for the reference.
          Attached Files

          Comment


          • #6
            Please read and act on FAQ Advice #12 and give a decent data example, not screenshots.

            Comment

            Working...
            X