Announcement

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

  • Merge with different number of observations

    Dear all,

    I wish to merge two data sets:

    Data set #1 contains information about individuals over a period of 12 years, hence for each individual-year pair there is one observation.

    Data set #2 contains additonal information for each individual if it participated in any course in a given year. Hence, it only contains observations for a year for an individual if it participated in any course. Moreover an individual can participate in different courses. Hence for some years there are multiple observations for an individuals and for some years none. The course variable specifies different values for different courses, meaning that there is only one course variable.

    The issue is that I want to merge the data sets in a way that I have observations for each year for each individual that has a missing value if an individual did not participate in any course in a year.

    I hope you understand the problem!

    Best

  • #2
    Since you didn't share a data example, I can only guess at the specifics of your problem based on your description. Here is some code which will do what I think you want:

    Code:
    use dataset1, clear
    merge 1:m individual year using dataset2
    fillin individual year
    If this code does not work, please help us help you by sharing a data example from both datasets using the command -dataex- and pasting the output into this forum.

    Comment

    Working...
    X