Hi everyone,

I have to merge two datasets: "Monthly data" and "Fundamentals quarterly".

The first one contains monthly returns for certain stocks; the main variables are gvkey (identifier), datadate (date) and trt1m (monthly total return) and it looks like this:

Code:
input long(gvkey datadate) float trt1m
clear
1257 19730731     62.5
1257 19730831 -11.5385
1257 19730930  -6.5217
1257 19731031        0
1257 19731130  -27.907
1257 19731231  -7.0968
1257 19740131  60.7143
1257 19740228  -4.4444
1257 19740331  25.5814
1257 19740430  -5.5556
end
The second one contains quarterly accounting data for those stocks; the main variables are gvkey (identifier), datadate (date) and then all the accounting metrics. It looks like the previous one but with quarterly data.

Objective. My goal is to create an unique dataset with monthly data whereby each stock for each date has the corresponding accounting data, and for the months in which no accounting data are availalbe (because they are on a quarterly basis) the dataset should have the data from the previous available quarter. For instance, if we have the accounting data for January and April, the final dataset will have the accounting data from January also in February and March.

I have tried this:

Code:
merge m:1 gvkey datadate using filename
but I get this error message: variables gvkey datadate do not uniquely identify observations in the using data

Does anyone here have a better idea? Thank you!