Announcement

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

  • Finding the height of a mother for each child per household

    Hi all,

    Bit of a hard one to explain but hopefully I can.

    I'm trying to obtain the height of the mother for each child, however as shown in the data below the variable hh_b15 indicates who their mother is in terms of their individual id: indidy2 [with 97-99 being mother not available].

    So what I need is a function that uses the "Who's the mother" information and then looks up this mother's height and outputs the value on the same line as the child, but notably per household. If that makes sense?

    I've tried this but to no success:

    Code:
    by y2_hhid: egen mother_height = max(hh_u04) if indidy2 == hh_b15
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str16 y2_hhid byte indidy2 double hh_u04 byte(hh_b12 hh_b15) float age
    "0101014002017101" 1 160.60000610351563 98 98 70
    "0101014002017101" 2  141.6999969482422 98 98 60
    "0101014002017101" 3                  .  1  2 27
    "0101014002017101" 4 167.39999389648438  1  2 20
    "0101014002017101" 5                  . 98 97  8
    "0101014002028401" 1  164.3000030517578 98 98 38
    "0101014002028401" 2 141.60000610351563 98 97 22
    "0101014002028401" 3  91.30000305175781  1  2  4
    "0101014002028401" 4  44.20000076293945  1  2  0
    "0101014002029701" 1 175.10000610351563 98 98 52
    end
    label values hh_b12 hh_b12
    label def hh_b12 98 "Dead", modify
    label values hh_b15 hh_b15
    label def hh_b15 97 "Living out of the household", modify
    label def hh_b15 98 "Dead", modify

    Thanks,
    Alex

  • #2
    Thanks for the data example. Here I use rangestat from SSC.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str16 y2_hhid byte indidy2 double hh_u04 byte(hh_b12 hh_b15) float age
    "0101014002017101" 1 160.60000610351563 98 98 70
    "0101014002017101" 2  141.6999969482422 98 98 60
    "0101014002017101" 3                  .  1  2 27
    "0101014002017101" 4 167.39999389648438  1  2 20
    "0101014002017101" 5                  . 98 97  8
    "0101014002028401" 1  164.3000030517578 98 98 38
    "0101014002028401" 2 141.60000610351563 98 97 22
    "0101014002028401" 3  91.30000305175781  1  2  4
    "0101014002028401" 4  44.20000076293945  1  2  0
    "0101014002029701" 1 175.10000610351563 98 98 52
    end
    label values hh_b12 hh_b12
    label def hh_b12 98 "Dead", modify
    label values hh_b15 hh_b15
    label def hh_b15 97 "Living out of the household", modify
    label def hh_b15 98 "Dead", modify
    
    rangestat wanted=hh_u04, int(indidy2 hh_b15 hh_b15) by(y2_hhid)
    
    list, sepby(y2_hhid)
    
         +-------------------------------------------------------------------------------------------------+
         |          y2_hhid   indidy2      hh_u04   hh_b12                        hh_b15   age      wanted |
         |-------------------------------------------------------------------------------------------------|
      1. | 0101014002017101         1   160.60001     Dead                          Dead    70           . |
      2. | 0101014002017101         2       141.7     Dead                          Dead    60           . |
      3. | 0101014002017101         3           .        1                             2    27       141.7 |
      4. | 0101014002017101         4   167.39999        1                             2    20       141.7 |
      5. | 0101014002017101         5           .     Dead   Living out of the household     8           . |
         |-------------------------------------------------------------------------------------------------|
      6. | 0101014002028401         1       164.3     Dead                          Dead    38           . |
      7. | 0101014002028401         2   141.60001     Dead   Living out of the household    22           . |
      8. | 0101014002028401         3   91.300003        1                             2     4   141.60001 |
      9. | 0101014002028401         4   44.200001        1                             2     0   141.60001 |
         |-------------------------------------------------------------------------------------------------|
     10. | 0101014002029701         1   175.10001     Dead                          Dead    52           . |
         +-------------------------------------------------------------------------------------------------+

    Comment


    • #3
      The techniques demonstrated for the similar questions in

      https://www.statalist.org/forums/for...running-slowly

      https://www.statalist.org/forums/for...-in-the-survey

      might start you in a useful direction.

      Comment


      • #4
        Thank you both for your replies, very helpful. Nick that got me exactly what I wanted thank you!

        Comment

        Working...
        X