Announcement

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

  • Merging Datasets

    I have 2 datasets I would like to merge but I am having problems due to the nature of the data - multiple time points and cycle numbers. Below is a sample of dataset 1 and 2. I would be grateful for help in merging these 2 datasets.

    Dataset 1
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(TRIALNO CYCNO TIMEPOIN) float(ae AEexp grading count)
    1  1 1  3 1 1  1
    1  1 1 14 0 0  2
    1  1 1  2 0 0  3
    1  2 1  3 1 2  4
    1  2 1  2 0 0  5
    1  2 1 14 1 1  6
    1  3 2  2 0 0 10
    1  3 2  3 1 2 11
    1  3 2 14 0 0 12
    1  4 2  2 0 0 13
    1  4 2  3 1 1 14
    1  4 2 14 0 0 15
    2  1 1  2 0 0  1
    2  1 1 14 0 0  2
    2  1 1  3 0 0  3
    2  2 1 14 1 1  4
    2  2 1  3 0 0  5
    2  2 1  2 0 0  6
    2  3 2 14 0 0 10
    2  3 2  2 0 0 11
    2  3 2  3 0 0 12
    2  4 2  2 0 0 13
    2  4 2 14 0 0 14
    2  4 2  3 0 0 15
    2  5 3  2 0 0 19
    2  5 3 14 0 0 20
    2  5 3  3 0 0 21
    2  6 3  2 0 0 22
    2  6 3  3 0 0 23
    2  6 3 14 0 0 24
    2  7 4  2 0 0 28
    2  7 4 14 0 0 29
    2  7 4  3 0 0 30
    2  8 4 14 0 0 31
    2  8 4  3 0 0 32
    2  8 4  2 0 0 33
    3  1 1  2 0 0  1
    3  1 1 14 0 0  2
    3  1 1  3 1 1  3
    3  2 1  3 1 1  4
    3  2 1 14 0 0  5
    3  2 1  2 0 0  6
    3  3 1  3 1 1  7
    3  3 1  2 0 0  8
    3  3 1 14 0 0  9
    3  4 2  3 1 1 10
    3  4 2 14 0 0 11
    3  4 2  2 0 0 12
    3  5 2  3 0 0 13
    3  5 2 14 0 0 14
    3  5 2  2 0 0 15
    3  6 2  2 0 0 16
    3  6 2 14 0 0 17
    3  6 2  3 0 0 18
    3  8 3 14 0 0 19
    3  8 3  3 0 0 20
    3  8 3  2 0 0 21
    3  9 3  3 0 0 22
    3  9 3  2 0 0 23
    3  9 3 14 0 0 24
    3 10 4  2 0 0 28
    3 10 4 14 0 0 29
    3 10 4  3 0 0 30
    3 11 4 14 0 0 31
    3 11 4  2 0 0 32
    3 11 4  3 0 0 33
    3 12 4  3 0 0 34
    3 12 4 14 0 0 35
    3 12 4  2 0 0 36
    end
    Dataset 2
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double(TRIALNO TIMEPOIN CYCLENO) long CYCDT double(TRT SAE)
     1 1  1 17666 1 2
     1 1  2 17687 1 1
     1 2  3 17708 1 2
     1 2  4 17736 1 2
     2 1  1 17707 1 2
     2 1  2 17727 1 2
     2 2  3 17749 1 2
     2 2  4 17770 1 2
     2 3  5 17791 1 2
     2 3  6 17812 1 2
     2 4  7 17833 1 2
     2 4  8 17854 1 2
     3 1  1 17684 2 1
     3 1  2 17699 2 1
     3 1  3 17713 2 1
     3 2  4 17757 2 2
     3 2  5 17771 2 2
     3 2  6 17792 2 2
     3 3  7 17806 2 2
     3 3  8 17820 2 2
     3 3  9 17834 2 2
     3 4 10 17848 2 2
     3 4 11 17862 2 2
     3 4 12 17876 2 1
    end
    format %dD_m_Y CYCDT

    Thanks
    Last edited by Grace Babey; 10 Aug 2023, 08:01.

  • #2
    I had no problem using joinby to join the data (file2 into file1) by TRIALNO TIMEPOIN CYCLEMO.

    Your CYCLENO variable has a different name in file1, so need to fix that for a clean join.

    Code:
    use file1, clear
    ren CYCNO CYCLENO
    joinby TRIALNO TIMEPOIN CYCLENO using file2, unmatched(both)
    tab _merge

    Comment


    • #3
      George Ford Many thanks. Files merged successfully.

      Comment

      Working...
      X