Announcement

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

  • Merging Datasets with Yearly and Monthly frequencies.

    Hello,

    i have two Datasets that i want to merge. Dataset A contains monthly stock returns for different firms. Among those variables in Dataset A are Stock Return, Date (DDMMYYYY), Year, Company-ID. Dataset B also contains the variables Year and Company-ID. Additionally Dataset B has the Variables Location and Industry which i ultimately want together in a Dataset with the variable Stock Return. E.g: Each observation should have the following information: (Company-ID, Year, Date, Stock Return, Loaction, Industry).

    When i want to merge both Datasets using the variables Year and Company-ID i get the message that the observations are not uniquely identifiable. This is for a 1:1, a 1:m and also for a m:1 merge.

    I am aware that for every a given Company-ID and Year there are 12 possible matches (one for each month). I am not sure what i am missing as i have seen this kind of "Problem" beeing solved in the same manner before.

    I would be glad for any feedback and or alternative approaches. If something is not clear, let me know and i will try to explain it better.

    Thank you for your help in advance!

    Best Regards

  • #2
    From your description, there should be no problem with
    Code:
    use DatasetA
    merge m:1 company_id year using DatasetB
    Therefore, I can only conclude that your data are not what you think they are. Please post examples from both data sets. Choose the examples so that there will be matches between the two examples. Also, test this m_1 merge on the examples to determine that the example exhibits the problem you are encountering. There are almost certainly some errors in one or both data sets that are causing this problem, or the data sets may simply not be quite as you describe them. But the only way anyone can help resolve this is to see and work with actual data that exhibits the problem.

    Please be sure to use the -dataex- command to show the examples. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment

    Working...
    X