Announcement

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

  • How to merge rows together in large datasets?



    input long(pat_key collection_day_number) str8 collection_time_of_day float(plt hemoglobin)
    494211883 2 "06:03:00" 0 0
    494211883 1 "16:24:00" 0 9.3
    494211883 2 "06:03:00" 0 8.1
    494211883 2 "06:03:00" 0 0
    494211883 4 "06:22:00" 0 8.1
    494211883 3 "05:35:00" 0 7.1
    end
    [/CODE]
    ------------------ copy up to and including the previous line ------------------

    Hey all, new Stata user here. I have a massive dataset that I am working with and really struggling with the next step in my coding. I am working with data on surgeries. Each surgical case has lab values collected posteroperatively each day. Each surgical case is identified by an ID number which in the case I posted is 494211883. I want to merge rows of the data together based on the day postoperatively the labs were collected. For instance I want all rows with a a collection time of day of "2" to be merged together, all with a collection time of 3 to be merged together and so on and so forth. How would I go about doing this?

  • #2
    collapse

    Comment


    • #3
      Thanks. I understand that I have use collapse but having a tough time formatting the exact code that I should use.

      Comment


      • #4
        For the 2 group, there are different results. Which do you want? Or do you want the mean?

        Comment


        • #5
          I would like the mean if possible

          Comment


          • #6
            collapse (mean) plt hemoglobin (first) collection_time_of_day, by(pat_key collection_day_number)

            Comment

            Working...
            X