Announcement

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

  • How to merge datasets using joinby?

    I have the following data. In Data set A, I have rows of children with "h13hhidc" indicating their household ID including the relevant sub-household ID information. "h13hhidc" is not unique to the children since multiple children of the same household are found within the data. Data Set B includes parents (some single households and some married households). These are also uniquely identified by h13hhidc. I would like to merge Data A and Data B so that the final result includes all parents in Data B having a new row for each child present in Data A, that has a matching h13hhidc. I want to keep people in Data B that do not have children in Data A (as a I later have more child data sets to import), but again, have several lines for parents that did in fact have matching children in Data A.

    I have searched the forum and feel like this would be the proper time for the joinby command, but I am not getting the desired result. Any help is greatly appreciated.

    Data A
    Code:
    
    
    . list hhid opn h13hhidc psubhh qsubhh education  in 1/500 , sepby (hhid)
    
         +------------------------------------------------------+
         |   hhid   opn   h13hhidc   psubhh   qsubhh   educat~n |
         |------------------------------------------------------|
      1. | 010004   101    0100040        0        0          . |
      2. | 010004   201    0100040        0        0          . |
      3. | 010004   202    0100040        0        0          . |
      4. | 010004   604    0100040        0        0          . |
      5. | 010004   605    0100040        0        0          . |
    Data B

    Code:
    . list hhid pn h13hhidc in 6/20, sepby (hhid)
    
         +-------------------------+
         |   hhid    pn   h13hhidc |
         |-------------------------|
      6. | 010003   020          . |
      7. | 010003   030    0100030 |
         |-------------------------|
      8. | 010004   010          . |
      9. | 010004   040    0100040 |
         |-------------------------|
     10. | 010013   010          . |
     11. | 010013   040    0100131 |
         |-------------------------|
     12. | 010038   010    0100380 |
     13. | 010038   040    0100380
Working...
X