Dear Statalist members,
For my thesis, I need to merge CRSP daily and Compustat annual to calculate annual average bid-ask spread. I know that this topic about merging compustat annual and crsp daily has been dealt with in the past, but I have tried several ways but till now I haven't been able to come up with the results. Hopefully can somebody help me?
I need to calculate annual average bid-ask spread in CRSP per firm on a fiscal-year basis. My sample starts from 1/1/2003 to 31/12/2015. In the end, I want my results to look something like this:
The problem is CRSP shows closing bid and closing ask on a calendar-day basis running almost everyday from 1/1/2003 till 31/12/2015 while Compustat shows data on a yearly-basis.The firms in Compustat also have different year-end date like 31/12 or 31/3.
1---I tried to generate the year by gen fyr=year(datadate) to just get the year and then merge compustat with crsp by cusip and fyr. However, it only works on company with fiscal year running from 1/1 to 31/12.
2---Then, I tried to generate the beginning of the year and the end of the year so that the individual dates of crsp daily will be trapped in the beginning date and the end date. Thus, I have followed several posts, including Sarah Edgington's post (http://www.stata.com/statalist/archi.../msg00242.html) as follows:
*generate the beginning date of fiscal year
gen beginning=mdy(month(datadate-364),1,year(datadate-364))
*use joinby to create pairwise combination between two datasets
use crsp.dta
joinby cusip8 using compustat.dta, unmatched(master)
keep if date>=beginning & date<=datadate
(with 'date' here is the individual date of the closing bid and closing ask)
I tried to run the commands like this on a smaller trial dataset, and it works beautifully. However, for my too large datasets, it does not work, and I also run into the memory issues.
I also run the codes provided by Phil, which follows Sarah's posts, but I don't know why it does not work. Stata says 'variables not defined' or 'too much [' or something like that.
There is also a very similar post by Fabian Schneider (http://www.statalist.org/forums/foru...year-end-dates) , but then it is directed to another post by Rochelle Zhang, but I won't calculate any standard deviation by using the data from another year, so i don't think it will help me.
Can you help me please? Otherwise I will have to drop all the firms with fiscal year ending other than 31/12, which is very bad for me.
Kind regards,
An
For my thesis, I need to merge CRSP daily and Compustat annual to calculate annual average bid-ask spread. I know that this topic about merging compustat annual and crsp daily has been dealt with in the past, but I have tried several ways but till now I haven't been able to come up with the results. Hopefully can somebody help me?
I need to calculate annual average bid-ask spread in CRSP per firm on a fiscal-year basis. My sample starts from 1/1/2003 to 31/12/2015. In the end, I want my results to look something like this:
cusip8 | datadate | annual_spread | other compustat data |
12345678 | 31/12/2003 | 0.01 | ... |
12345678 | ... | ... | ... |
12345678 | 31/12/2015 | ... | ... |
98765432 | 31/3/2003 | 0.02 | ... |
98765432 | ... | ... | ... |
98765432 | 31/3/2015 | ... | ... |
1---I tried to generate the year by gen fyr=year(datadate) to just get the year and then merge compustat with crsp by cusip and fyr. However, it only works on company with fiscal year running from 1/1 to 31/12.
2---Then, I tried to generate the beginning of the year and the end of the year so that the individual dates of crsp daily will be trapped in the beginning date and the end date. Thus, I have followed several posts, including Sarah Edgington's post (http://www.stata.com/statalist/archi.../msg00242.html) as follows:
*generate the beginning date of fiscal year
gen beginning=mdy(month(datadate-364),1,year(datadate-364))
*use joinby to create pairwise combination between two datasets
use crsp.dta
joinby cusip8 using compustat.dta, unmatched(master)
keep if date>=beginning & date<=datadate
(with 'date' here is the individual date of the closing bid and closing ask)
I tried to run the commands like this on a smaller trial dataset, and it works beautifully. However, for my too large datasets, it does not work, and I also run into the memory issues.
I also run the codes provided by Phil, which follows Sarah's posts, but I don't know why it does not work. Stata says 'variables not defined' or 'too much [' or something like that.
There is also a very similar post by Fabian Schneider (http://www.statalist.org/forums/foru...year-end-dates) , but then it is directed to another post by Rochelle Zhang, but I won't calculate any standard deviation by using the data from another year, so i don't think it will help me.
Can you help me please? Otherwise I will have to drop all the firms with fiscal year ending other than 31/12, which is very bad for me.
Kind regards,
An
Comment