Announcement

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

  • Help with Matching children with parents' height in Survey Data

    Dear All,

    I am working with a survey data consisting of individuals with unique ids (pid). I have the following variables- age (the individuals age), pid_mother (the unique identifier of the mother of the individual), and height_adult (height measure of the individual). For example, individual with pid 315005 (aged 53) is the mother of 2 individuals- 720804 (aged 25) and 720805 (aged 19). The mother's height is 159.3. I want to create/generate a new variable which should be equal to the mother's height for all children with unique mother pids in the dataset. Any help will be greatly appreciated.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long pid float(age pid_mother height_adult)
    304623 39 304624   175
    304624 74      . 156.6
    305249 21 305250 161.5
    305250 52      . 166.5
    305268 55      . 161.5
    305269 28 305250     .
    620952  4 305269     .
    319161 24      . 168.6
    305291 51      .     .
    309522 56      .     .
    402779  9      .     .
    582536 29 305291     .
    583034 27 305291     .
    302034 23 302003   151
    303039 44      . 176.5
    305649 52 311353 169.9
    311353 90      . 154.2
    407393  8 316584     .
    407397  6      .     .
    319052 34 321630     .
    321630 52      .   157
    321631 60      . 157.3
    410590 13      .     .
    301903 26      . 188.5
    381188 22      .     .
    409493 14 381215     .
    409494 17 381215     .
    620604  2 381188     .
    319823 50      .     .
    319824 22 319825     .
    319825 46      .     .
    470329 18 319825     .
    315004 54 315006 172.6
    315005 53      . 159.3
    407674 17 315005 170.9
    408582 11 315007     .
    408583  7 315007     .
    720802  3 720804     .
    720803  2 720805     .
    720804 25 315005 163.4
    720805 19 315005 173.8
    317604 44      . 156.5
    406032 15 317604 167.5
    406047 11 317604     .
    315604 26 315637     .
    315637 63      .   159
    315641 22 315637   168
    408605 12 710322     .
    408615  5 722782     .
    408664  4 710322     .
    722782 34 315637   159
    304185 68      . 156.1
    304188 48 304185 174.8
    405518 15      . 153.5
    730216 41 304185 168.5
    316341 22 316342   162
    316342 46      . 164.3
    316343 24 316342   172
    409641  4 316341     .
    409642 17 316342 156.9
    409643 14 316342     .
    630586  1 316341     .
    306543 27      . 161.3
    403621  7 306543     .
    630953  2 306543     .
    301653 31 303944 169.5
    723499 32      .     .
    723500  8 723499     .
    408875 14 302456     .
    408876 12 302456     .
    730607 24      . 157.5
    733520  4 730607     .
    733885 19      . 165.5
    306694 26      .     .
    309494 29      .     .
    402298  6 306694     .
    582954 21 391228     .
    323711 59      . 152.4
    324003 34 323711 170.1
    501980 36 323711 172.1
    734420  3      .     .
    305641 50      .     .
    305642 46      . 157.1
    401085  7 305642     .
    401790 16 305642 149.6
    401791 12 305642     .
    491873  6 305642     .
    319927 84      . 158.2
    321498 19      . 164.9
    411326 17      .     .
    733875 18      .   177
    304410 43      .     .
    303904 44      .     .
    303905 38      .   167
    406407 12      .     .
    406589 19      .   158
    406595  6 312204     .
    406610 10      .     .
    406623  6      .     .
    501576 38 312202     .
    734969  3 735979     .
    735979 25      . 158.8
    312921 37      . 165.5
    407580 16 312921 173.6
    409301  7 312921     .
    306650 43      . 154.5
    402408 15 306650 169.3
    402409  9 306650     .
    402410 18 306650 175.3
    620111  3 306650     .
    720481 21 306650 157.2
    734967  0 720481     .
    306349 47      .   163
    313211 24 316779     .
    316779 58      .   158
    316785 23 316779   175
    406208  5 313211     .
    406216  8 501665     .
    406217 10 710608     .
    406218  9 710608     .
    501665 31 316779     .
    321599 32 321600 157.5
    321600 57      . 149.8
    410397  5 321599     .
    620322  2 321599     .
    407160 19      .     .
    731748 32      .   165
    312690 36      .     .
    312691 62      . 155.5
    318119 26      .     .
    319540 44      .     .
    502185 53      .     .
    721757 16 319540     .
    323676 26      . 160.6
    412471  9 323676     .
    412479  5 323676     .
    734643 31      . 165.6
    735870  9      .     .
    316009 42      . 161.7
    408678 15 316009 146.3
    501773 77      .     .
    303336 40      . 175.5
    303338 37      . 161.7
    405022 12 303338     .
    405023  7 303338     .
    630474  0 303338     .
    310164 48      .   176
    730386  8 734562     .
    732995 18 734562   151
    734562 46      .   152
    311174 91      .    -3
    324365 26      . 163.5
    732917 29      . 170.5
    312928 36      . 163.7
    407749  5 312928     .
    407750 16 312928     .
    313128 26 582610 173.4
    318452 50      .   170
    408575  6 582812     .
    408576  8 582812     .
    582812 24 582811   154
    725570 16 725580   169
    725571  7 725580     .
    725577 69      . 169.3
    725578 69      . 155.6
    725581 30 725578 176.5
    302418 49      . 151.2
    302421 22 302418 166.4
    306639 55      . 179.6
    401941 15 302418 180.1
    304654 47      .     .
    302139 36      . 166.7
    302152 20 302139 175.7
    401050  8 302139     .
    307960 23      .     .
    309549 20 301580 163.8
    309967 62      . 155.9
    309999 61      . 152.9
    317266 63      . 165.8
    732672 45 317266   172
    733814 39      . 161.2
    735635  0 733814     .
    323870 71      .     .
    306580 39      . 173.5
    724252 29      . 162.3
    724253  1 724252     .
    735020  0 724252     .
    735853 16      . 146.3
    307169 30      . 167.4
    405106  7 307169     .
    630777  1 307169     .
    724265 27      . 164.6
    724266 14      .     .
    724267  8 724265     .
    724268 16      . 159.5
    316129 39      .   152
    409565 14 316129     .
    409567  8 316129     .
    409568  7 316129     .
    620223  3 316129     .
    end

  • #2
    Code:
    frame put pid height_adult, into(mothers)
    frlink m:1 pid_mother, frame(mothers pid)
    frget mother_height = height_adult, from(mothers)
    drop mothers
    frame drop mothers

    Comment


    • #3
      Thank you very much Clyde Schechter.

      Comment

      Working...
      X