Announcement

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

  • Merge overlapping observations

    Hi All,

    I am trying to merge into a panel dataset containing data on inflation until December 2021, a dataset of expected data on inflation from August 2021 until December 2030. I am merging the two datasets using the dates. The code I use is:
    merge dates 1:1 using expected_inflation, keep (master match match_update) update

    The issue is that the code above drops all observation between August 2021 and December 2021, while I would like to keep the observations until December 2021 from the master datasets and merge the expected data from January 2022 onwards. The variable for inflation has the same name in both datasets and I would need to merge the two datasets into the same column.
    Can you help me to figure out why the master match and match_update drops the overlapping observations?

    Thanks All
    Last edited by Mike Russo; 17 Jan 2022, 13:09.

  • #2
    Your question really isn't clear without more detail, or at a minimum it is too difficult to guess at a good answer from what you have shared. Please help us help you. Show example data. Show your code. Show us what Stata told you. Tell us what precisely is wrong. The Statalist FAQ provides advice on effectively posing your questions, posting data, and sharing Stata output.

    It is particularly helpful to copy commands and output from your Stata Results window and paste them into your Statalist post using code delimiters [CODE] and [/CODE], and to use the dataex command to provide sample data, as described in section 12 of the FAQ.

    Given that you have panel data, I find it difficult to understand how merge 1:1 would have worked, since with panel data you would have observations from multiple panels on any given date, so I would have expected to see merge m:1.

    Comment


    • #3
      One possible reason is that the inflation rates in both data sets do not agree where the dates overlap. The option "match_update" only update missing values. If both data sets have values under the same variable name, and they are not identical, I believe they will be excluded. Try to use "match_conflict" instead of "match_update" and see if that is the case. It's probably better to rename the inflation in one the data sets, then then combine them appropriately after the merging. Or, you can try replace the version of the inflation rates between Aug-Dec, 2021 that you don't want into missing, then the "match_update" should fill that out with the desired one.

      Comment

      Working...
      X