Announcement

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

  • How to create birth order variable?

    I am trying to create a birth order variable with the categories of oldest, middle, and youngest. In my data I have a variable that asks how many children do your parents have (answers range 1-16), and another question that asks which order are you within those children (1st-16th). I know for the oldest it would be all those who said they are the first born, but how would you suggest I go about coding the middle and youngest categories?

  • #2
    This might help get you started.

    Say the order variable is "order" and there's a household_id.

    clear
    input byte(household_id order)
    1 1
    2 1
    2 2
    3 1
    3 2
    3 3
    4 1
    4 2
    4 3
    4 4
    5 1
    5 2
    5 3
    5 4
    5 5
    6 1
    6 2
    6 3
    6 4
    6 5
    6 6
    7 1
    7 2
    7 3
    7 4
    7 5
    7 6
    7 7
    8 1
    8 2
    8 3
    8 4
    8 5
    8 6
    8 7
    8 8
    9 1
    9 2
    9 3
    9 4
    9 5
    9 6
    9 7
    9 8
    9 9
    10 1
    10 2
    10 3
    10 4
    10 5
    10 6
    10 7
    10 8
    10 9
    10 10
    end


    Code:
    egen kidcount = count(order), by(household_id)
    
    egen order_last = max(order), by(household_id)
    egen order_med = median(order), by(household_id)
    
    g firstborn = order == 1
    g lastborn  = order == order_last
    g medborn = order == int(order_med) if kidcount>2
    The issue is the middle born, since with even numbers, you have a tie. You could have 2 middle born in these cases, adding a medborn2 variable with int(order_med)+1





    Comment


    • #3
      Originally posted by George Ford View Post
      This might help get you started.

      Say the order variable is "order" and there's a household_id.

      clear
      input byte(household_id order)
      1 1
      2 1
      2 2
      3 1
      3 2
      3 3
      4 1
      4 2
      4 3
      4 4
      5 1
      5 2
      5 3
      5 4
      5 5
      6 1
      6 2
      6 3
      6 4
      6 5
      6 6
      7 1
      7 2
      7 3
      7 4
      7 5
      7 6
      7 7
      8 1
      8 2
      8 3
      8 4
      8 5
      8 6
      8 7
      8 8
      9 1
      9 2
      9 3
      9 4
      9 5
      9 6
      9 7
      9 8
      9 9
      10 1
      10 2
      10 3
      10 4
      10 5
      10 6
      10 7
      10 8
      10 9
      10 10
      end


      Code:
      egen kidcount = count(order), by(household_id)
      
      egen order_last = max(order), by(household_id)
      egen order_med = median(order), by(household_id)
      
      g firstborn = order == 1
      g lastborn = order == order_last
      g medborn = order == int(order_med) if kidcount>2
      The issue is the middle born, since with even numbers, you have a tie. You could have 2 middle born in these cases, adding a medborn2 variable with int(order_med)+1




      Unfortunately I do not have a household_id variable, just the two variables listed and the person's id.

      Comment


      • #4
        Code:
        clear all
        set obs 100
        
        g kidshave = int(runiform(0,17))
        g myrank = int(runiform(1,15))
        
        g first = myrank==1
        g last = myrank==kidshave
        g mid = myrank==int(kidshave/2)

        Comment


        • #5
          I think the code in #4 works well, except for the mid variable. You could create that using this code instead:

          Code:
          g mid = !first & !last
          As an aside, you might get a more sensible toy dataset with this:

          Code:
          clear all
          set obs 100
          
          g kidshave = runiformint(1, 17)
          g myrank = runiformint(1, kidshave)
          Last edited by Hemanshu Kumar; 11 Jul 2024, 06:58.

          Comment

          Working...
          X