Dear Statalist members,
I need to merge daily security data to Fundamentals annual data. I have tried several ways to merge , but I could not come up with the results until now.
I am using a dataset form the WRDS database. I have annual data for my firm (gvkey). I want to calculate the market to book Ratio. Unfortunately, the annual dataset has no variable to calculate the market value of a firm. So I have to take the daily closing Prices (prccd). In order to get the variable prccd into my annual dataset, I have to merge these datasets.
Then, I used the following code to merge the datasets:
*Merge*
use fundamental , clear
keep if fic =="UK"
gen month = month(datadate)
gen year = year(datadate)
save"UK/fundamental ", replace
********************************
use security_file,clear
keep if fic =="UK"
gen month = month(datadate)
gen year = year(datadate)
save"UK/security_file", replace
********************************
use "UK/fundamental ",clear
merge 1:1 gvkey datadate using "UK/security_file"
drop if _merge==2
drop _merge
save "UK/combined",replace
doing this, I always receive the following error code:
variables gvkey year month do not uniquely identify observations in the using data
r(459);
Can somebody help?
Thanky you in advance
I need to merge daily security data to Fundamentals annual data. I have tried several ways to merge , but I could not come up with the results until now.
I am using a dataset form the WRDS database. I have annual data for my firm (gvkey). I want to calculate the market to book Ratio. Unfortunately, the annual dataset has no variable to calculate the market value of a firm. So I have to take the daily closing Prices (prccd). In order to get the variable prccd into my annual dataset, I have to merge these datasets.
Then, I used the following code to merge the datasets:
*Merge*
use fundamental , clear
keep if fic =="UK"
gen month = month(datadate)
gen year = year(datadate)
save"UK/fundamental ", replace
********************************
use security_file,clear
keep if fic =="UK"
gen month = month(datadate)
gen year = year(datadate)
save"UK/security_file", replace
********************************
use "UK/fundamental ",clear
merge 1:1 gvkey datadate using "UK/security_file"
drop if _merge==2
drop _merge
save "UK/combined",replace
doing this, I always receive the following error code:
variables gvkey year month do not uniquely identify observations in the using data
r(459);
Can somebody help?
Thanky you in advance
Comment