Announcement

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

  • Condensing scattered data from same ID across multiple lines to one line with all data

    Hi all - I need help condensing scattered data from same ID across multiple lines to one line with all data. Here is an example of what I'm looking at:
    ID v1 v2
    1 3 .
    1 . 7
    2 1 .
    2 . 4
    3 5 .
    3 . 2
    Thanks!

  • #2
    Code:
    clear
    input ID    v1    v2
    1    3    .
    1    .    7
    2    1    .
    2    .    4
    3    5    .
    3    .    2
    end 
    
    collapse v1 v2, by(ID)
    
    list 
    
         +--------------+
         | ID   v1   v2 |
         |--------------|
      1. |  1    3    7 |
      2. |  2    1    4 |
      3. |  3    5    2 |
         +--------------+
    works for your example, as taking the mean over a single non-missing value yields just that value. But whether your real data are more complicated cannot be clear.

    Comment


    • #3
      tabstat v1 v2, by(ID)

      Comment

      Working...
      X