Hello,

I have two data sets which I want to merge. In the first dataset A ,I do have the following variables: id, year, month (and further variables which are not of interest in this case.)
In the second dataset B, I have the variables: id, year, month, costs.

My problem is the following: The costs in dataset B refer to the average costs over the last 12 months and are reported for each id only once a year, but at different months. For one id they are reported yearly in september, for another id they are reported yearly in december etc.

If I now match the datasets using the following code
Code:
merge m:m id year using "B"
the costs are matched on a yearly basis. Meaning costs reported in September2018 for a given id are merged with each month in 2018. But I want every value for costs from dataset B to be merged with the respective last 12 months in dataset A. In this case that means that costs reported in September 2018 are matched with the months October 2017-September2018.

I did search in the forum but did not find any solutions.

Does anyone have an idea how to solve this?

Thank you for your help

Tim Wolf