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 | X |
1 | 1990 | 4 | 67 | 67 |
1 | 1990 | 5 | 67 | 67 |
1 | 1990 | 6 | 67 | 67 |
2 | 1990 | 5 | 30 | 30 |
Here is an example from my quarterly (accounting) dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str6 gvkey double(lpermno lpermco) long datadate double(fqtr fyearq) str58 conm str10 cusip double atq(Total Assets) "012994" 10001 7953 12691 1 1995 "GAS NATURAL INC" "367204104" 30.938 "012994" 10001 7953 15065 3 2001 "GAS NATURAL INC" "367204104" 68.008 "012994" 10001 7953 14791 4 2000 "GAS NATURAL INC" "367204104" 50.553 "012994" 10001 7953 17074 1 2007 "GAS NATURAL INC" "367204104" 59.815 "012994" 10001 7953 11322 2 1991 "GAS NATURAL INC" "367204104" 21.71 "012994" 10001 7953 15521 4 2002 "GAS NATURAL INC" "367204104" 56.855 "012994" 10001 7953 18443 2 2010 "GAS NATURAL INC" "367204104" 117.984 "012994" 10001 7953 16070 2 2004 "GAS NATURAL INC" "367204104" 68.046 "012994" 10001 7953 17347 4 2007 "GAS NATURAL INC" "367204104" 50.52 "012994" 10001 7953 21000 2 2017 "GAS NATURAL INC" "367204104" 183.84 "012994" 10001 7953 10500 1 1989 "GAS NATURAL INC" "367204104" 12.126 "012994" 10001 7953 10865 1 1990 "GAS NATURAL INC" "367204104" 18.088 "012994" 10001 7953 15430 3 2002 "GAS NATURAL INC" "367204104" 60.603 "012994" 10001 7953 19813 1 2014 "GAS NATURAL INC" "367204104" 212.147 "012994" 10001 7953 13787 1 1998 "GAS NATURAL INC" "367204104" 45.408 "019049" 10002 7954 13879 4 1997 "BANCTRUST FINANCIAL GRP INC" "05978R107" 369.595 "019049" 10002 7954 11778 1 1992 "BANCTRUST FINANCIAL GRP INC" "05978R107" . "019049" 10002 7954 12234 2 1993 "BANCTRUST FINANCIAL GRP INC" "05978R107" . "019049" 10002 7954 15978 3 2003 "BANCTRUST FINANCIAL GRP INC" "05978R107" 681.627 "019049" 10002 7954 17439 3 2007 "BANCTRUST FINANCIAL GRP INC" "05978R107" 1331.299 "019049" 10002 7954 16801 4 2005 "BANCTRUST FINANCIAL GRP INC" "05978R107" 1305.497 "019049" 10002 7954 13330 2 1996 "BANCTRUST FINANCIAL GRP INC" "05978R107" 241.518 "019049" 10002 7954 13239 1 1996 "BANCTRUST FINANCIAL GRP INC" "05978R107" 240.782 "019049" 10002 7954 14334 1 1999 "BANCTRUST FINANCIAL GRP INC" "05978R107" 503.982 "019049" 10002 7954 10592 4 1988 "BANCTRUST FINANCIAL GRP INC" "05978R107" . "019049" 10002 7954 16617 2 2005 "BANCTRUST FINANCIAL GRP INC" "05978R107" 1320.542 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(lpermno lpermco) long datadate str58 conm str10 cusip double(prccm cshoq) "012994" 10001 7953 20727 "GAS NATURAL INC" "367204104" 7.67 10.516 "012994" 10001 7953 20758 "GAS NATURAL INC" "367204104" 12.35 . "012994" 10001 7953 20788 "GAS NATURAL INC" "367204104" 12.5 . "012994" 10001 7953 20819 "GAS NATURAL INC" "367204104" 12.55 10.52 "012994" 10001 7953 20850 "GAS NATURAL INC" "367204104" 12.65 . "012994" 10001 7953 20878 "GAS NATURAL INC" "367204104" 12.65 . "012994" 10001 7953 20909 "GAS NATURAL INC" "367204104" 12.7 10.52 "012994" 10001 7953 20939 "GAS NATURAL INC" "367204104" 12.5 . "012994" 10001 7953 20970 "GAS NATURAL INC" "367204104" 12.7 . "012994" 10001 7953 21000 "GAS NATURAL INC" "367204104" 12.925 10.52 "012994" 10001 7953 21031 "GAS NATURAL INC" "367204104" 12.95 . "012994" 10001 7953 21062 "GAS NATURAL INC" "367204104" 13.1 . "019049" 10002 7954 9527 "BANCTRUST FINANCIAL GRP INC" "05978R107" 11.5 . "019049" 10002 7954 9555 "BANCTRUST FINANCIAL GRP INC" "05978R107" 13.125 . "019049" 10002 7954 9586 "BANCTRUST FINANCIAL GRP INC" "05978R107" 14 . "019049" 10002 7954 9616 "BANCTRUST FINANCIAL GRP INC" "05978R107" 14.75 . "019049" 10002 7954 9647 "BANCTRUST FINANCIAL GRP INC" "05978R107" 14.5 . "019049" 10002 7954 9677 "BANCTRUST FINANCIAL GRP INC" "05978R107" 12.625 1.4 "019049" 10002 7954 9708 "BANCTRUST FINANCIAL GRP INC" "05978R107" 13.125 . "019049" 10002 7954 9739 "BANCTRUST FINANCIAL GRP INC" "05978R107" 13.125 . "019049" 10002 7954 9769 "BANCTRUST FINANCIAL GRP INC" "05978R107" 14 1.4 "019049" 10002 7954 9800 "BANCTRUST FINANCIAL GRP INC" "05978R107" 13.25 . "019049" 10002 7954 9830 "BANCTRUST FINANCIAL GRP INC" "05978R107" 13.25 . "019049" 10002 7954 9861 "BANCTRUST FINANCIAL GRP INC" "05978R107" 12.25 1.4 "019049" 10002 7954 9892 "BANCTRUST FINANCIAL GRP INC" "05978R107" 13.375 . "019049" 10002 7954 9920 "BANCTRUST FINANCIAL GRP INC" "05978R107" 13.25 . end format %d datadate
0 Response to Matching data with different time intervals
Post a Comment