Dear Statalist,
For my research, I need to link accounting data with stock price data (both from WRDS) for a period of more than 50 years. I have used the merged (CCM) Compustat database for this and have retrieved the variables I need for my accounting data and the variables for my stock price data.
However, the accounting data is quarterly data while the stock price data is monthly data. I would like to link these 2 data sets given that they have several unique identifiers (GVKEY, LPERMNO, LPERMCO).
Note: GVKEY is basically an identifier for a firm (so Apple would have GVKEY: 1 and Microsoft would have GVKEY: 2 and Oracle would have GVKEY: 3 etc.), the same thing goes for LPERMCO.
Now I have used the -merge- commands (1:1, 1:m, m:1) for this but it keeps giving me errors: variables gvkey/lpermco do not uniquely identify the observations.
So if I use:
It will give me the above error.
What I would like to do is merge these 2 datasets and afterwards have 1 datasets with monthly data only. I would assign the quarterly data to the appropriate quarters in which they belong in their respective fiscal year. So in case of variable "X" I would end up with:
Here is an example from my quarterly (accounting) dataset, here "atq" = Total Assets:
And here is an example from my monthly (stock price) dataset:
For my research, I need to link accounting data with stock price data (both from WRDS) for a period of more than 50 years. I have used the merged (CCM) Compustat database for this and have retrieved the variables I need for my accounting data and the variables for my stock price data.
However, the accounting data is quarterly data while the stock price data is monthly data. I would like to link these 2 data sets given that they have several unique identifiers (GVKEY, LPERMNO, LPERMCO).
Note: GVKEY is basically an identifier for a firm (so Apple would have GVKEY: 1 and Microsoft would have GVKEY: 2 and Oracle would have GVKEY: 3 etc.), the same thing goes for LPERMCO.
Now I have used the -merge- commands (1:1, 1:m, m:1) for this but it keeps giving me errors: variables gvkey/lpermco do not uniquely identify the observations.
So if I use:
merge 1:1 (or m:1 or 1:m) gvkey using CRSP.dta
What I would like to do is merge these 2 datasets and afterwards have 1 datasets with monthly data only. I would assign the quarterly data to the appropriate quarters in which they belong in their respective fiscal year. So in case of variable "X" I would end up with:
GVKEY | Year | Month | X | |
1 | 1990 | 4 | 67 | |
1 | 1990 | 5 | 67 | |
1 | 1990 | 6 | 67 | |
2 | 1990 | 5 | 30 |
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 gvkey double lpermco long datadate str58 conm str10 cusip double atq "001118" 25563 8125 "ADAMS DRUG INC" "006203103" 85.812 "001118" 25563 8216 "ADAMS DRUG INC" "006203103" 87.108 "001118" 25563 8308 "ADAMS DRUG INC" "006203103" 91.059 "001118" 25563 8400 "ADAMS DRUG INC" "006203103" 100.637 "001118" 25563 8490 "ADAMS DRUG INC" "006203103" 99.764 "001118" 25563 8581 "ADAMS DRUG INC" "006203103" 98.414 "001118" 25563 8673 "ADAMS DRUG INC" "006203103" 103.948 "001118" 25563 8765 "ADAMS DRUG INC" "006203103" 104.944 "001118" 25563 8856 "ADAMS DRUG INC" "006203103" 102.939 "001118" 25563 8947 "ADAMS DRUG INC" "006203103" 106.404 "001119" 20023 8125 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8216 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8308 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8400 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8490 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8581 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8673 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8765 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8856 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 8947 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . "001119" 20023 9039 "ADAMS DIVERSIFIED EQUITY FD" "006212104" . end format %d datadate
And here is an example from my monthly (stock price) dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 gvkey double lpermco long datadate str58 conm str10 cusip double prccm "001118" 25563 8796 "ADAMS DRUG INC" "006203103" 13.375 "001118" 25563 8825 "ADAMS DRUG INC" "006203103" 14.625 "001118" 25563 8856 "ADAMS DRUG INC" "006203103" 14.25 "001118" 25563 8886 "ADAMS DRUG INC" "006203103" 14.25 "001118" 25563 8917 "ADAMS DRUG INC" "006203103" 12.25 "001118" 25563 8947 "ADAMS DRUG INC" "006203103" 13 "001118" 25563 8978 "ADAMS DRUG INC" "006203103" 14.5 "001118" 25563 9009 "ADAMS DRUG INC" "006203103" 16.25 "001118" 25563 9039 "ADAMS DRUG INC" "006203103" 18.25 "001118" 25563 9070 "ADAMS DRUG INC" "006203103" 24.25 "001118" 25563 9100 "ADAMS DRUG INC" "006203103" 24.125 "001119" 20023 8066 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 13.25 "001119" 20023 8094 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 13.5 "001119" 20023 8125 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 13.875 "001119" 20023 8155 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 14.5 "001119" 20023 8186 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 13.625 "001119" 20023 8216 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 12.625 "001119" 20023 8247 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 12.875 "001119" 20023 8278 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 14.25 "001119" 20023 8308 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 14.5 "001119" 20023 8339 "ADAMS DIVERSIFIED EQUITY FD" "006212104" 15.375 end format %d datadate
Comment