Announcement

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

  • Sum data from two id's

    I have panel data and I want to join two id' into one by adding the data. There is other groups I dont want to join (so not just collapse the whole data to the t level). How to accomplish this?

    Here is an MWE. Say, I want to join id = 1 and id = 2 into one group with the values of x added together.

    Code:
    input id t x
    1 1 10
    1 2 0
    1 3 5
    2 1 10
    2 2 15
    2 3 0
    3 1 10
    3 2 15
    3 3 0
    end

  • #2

    Code:
    replace id = 1 if id == 2
    before a collapse.

    Comment


    • #3
      and then collapse at id and t level? Ah, thank you

      Comment


      • #4
        Indeed. Look at it this way: collapse can't tell what is considered as the same identifier unless it's told that somehow. In your real data there may be a systematic rule that lets you do this quickly.

        Comment

        Working...
        X