Announcement

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

  • Merging two datasets: multiple rows to one row

    I have two datasets that I want to merge into one dataset.
    The master dataset consists of individual survey data where each interviewed individual has one row (including a country variable).
    Dataset two consists of event data which is structured as follows: for each unique event date there is one row (including the country the event takes place), one country can have multiple events taking place, hence, for one country there are multiple rows.

    Now, I want to merge dataset one with dataset two using the country as the unique identifier such that I get for each individual one row:
    ID x1 x2 x3 country event1 y11 y21 y31 event 2 y12 y22 y32

    One way to achieve this is to use:
    Code:
    joinby country using ...
    and then to
    Code:
    reshape ..., i(id) j(event)
    .

    Is there an easier way to do it, e.g. with a merge command?
    Last edited by Penelope Smart; 25 Nov 2021, 12:09.

  • #2
    I would first reshape wide dataset two such that each row represents a country, and then merge dataset one with two (m:1 merge).

    Comment

    Working...
    X