Dear forum,
I'm currently working on a project regarding equity analyst forecasts from the IBES database. I encountered some issues when computing the consensus forecast and I hope I could get some help on it.
The consensus forecast calculation defined in my project is the mean of all forecasts (excluding the focal forecast) from the current and past quarters for each firm's forecast period ending dates and for the very first forecast issued for each firm in each forecast ending period date, the consensus forecast for it should be skipped as missing. Please see the example data below. Each observation is at the forecast level, and only the most recent forecast of each analyst is kept in each quarter for each company (i.e., no duplicated forecasts in each quarter). Each variable is defined as: "cusip" is the firm identifier; "analys" is the analyst identifier; "value" is the forecast estimate issued by each analyst; "fpedats" is the forecast period ending dates (i.e., the fiscal period ending dates for which the forecasts are issued); "anndats" is the analyst forecast announcement dates, which is used to sort the issuing time of forecasts; "yq" is the abbr. for year-quarter, used as the time variable; "firm_fpe" is generated using
as a unique identifier for firm and fpedats group; "rolling_avg" is the consensus forecast computed using
The issue I encountered is the incorrect results from the rolling_avg, even though I didn't see anywhere wrong using the rangestat command.
Basically, for the example below, the consensus forecast for the first observation should be missing because it is the very first forecast for the 66541 firm_fpe group. This is the first incorrect observation.
Then, for the second observation, its consensus forecast should be -3.7, which is the only forecast issued before it.
Then, for the third observation, its consensus forecast should be the mean of -3.7 and -5.3, which is -4.5, and this is correct.
Lastly, for the fourth observation, its consensus forecast should be -4.76 instead of -5.61. Honestly, I have no idea how this number is calculated on earth.
For the observation who -yq- is 182 (last observation), its consensus forecast should be the mean of forecasts from -yq- 181 (because we only consider the current the past quarter and exclude the focal forecast), which should be -6.25 instead of -5.36.
I couldn't figure out whether the incorrect calculation is due to my coding or my use of wrong command. Hopefully, I could use some help.
I hope the questions is clear and I would very much appreciate your help. Please let me know if you need any clarification. Thanks in advance!
I'm currently working on a project regarding equity analyst forecasts from the IBES database. I encountered some issues when computing the consensus forecast and I hope I could get some help on it.
The consensus forecast calculation defined in my project is the mean of all forecasts (excluding the focal forecast) from the current and past quarters for each firm's forecast period ending dates and for the very first forecast issued for each firm in each forecast ending period date, the consensus forecast for it should be skipped as missing. Please see the example data below. Each observation is at the forecast level, and only the most recent forecast of each analyst is kept in each quarter for each company (i.e., no duplicated forecasts in each quarter). Each variable is defined as: "cusip" is the firm identifier; "analys" is the analyst identifier; "value" is the forecast estimate issued by each analyst; "fpedats" is the forecast period ending dates (i.e., the fiscal period ending dates for which the forecasts are issued); "anndats" is the analyst forecast announcement dates, which is used to sort the issuing time of forecasts; "yq" is the abbr. for year-quarter, used as the time variable; "firm_fpe" is generated using
Code:
egen firm_fpe=group(cusip fpedats)
Code:
rangestat (mean) rolling_avg=value, interval(yq -1 0) by(firm_fpe) excludeself
Basically, for the example below, the consensus forecast for the first observation should be missing because it is the very first forecast for the 66541 firm_fpe group. This is the first incorrect observation.
Then, for the second observation, its consensus forecast should be -3.7, which is the only forecast issued before it.
Then, for the third observation, its consensus forecast should be the mean of -3.7 and -5.3, which is -4.5, and this is correct.
Lastly, for the fourth observation, its consensus forecast should be -4.76 instead of -5.61. Honestly, I have no idea how this number is calculated on earth.
For the observation who -yq- is 182 (last observation), its consensus forecast should be the mean of forecasts from -yq- 181 (because we only consider the current the past quarter and exclude the focal forecast), which should be -6.25 instead of -5.36.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str9 cusip long analys float value str10 fpedats float(anndats yq firm_fpe) double rolling_avg "92047K10" 25170 -3.7 "2006-01-31" 16524 180 66541 -5.300000190734863 "92047K10" 71346 -5.3 "2006-01-31" 16524 180 66541 -4.5000001192092896 "92047K10" 52780 -5.3 "2006-01-31" 16525 180 66541 -4.5000001192092896 "92047K10" 78488 -5.6 "2006-01-31" 16561 181 66541 -5.616666754086812 "92047K10" 25170 -5.3 "2006-01-31" 16561 181 66541 -5.666666706403096 "92047K10" 52780 -7 "2006-01-31" 16576 181 66541 -5.383333404858907 "92047K10" 71346 -7.1 "2006-01-31" 16576 181 66541 -5.366666754086812 "92047K10" 71346 -4.3 "2006-01-31" 16658 182 66541 -5.187499940395355 end format %d anndats
I hope the questions is clear and I would very much appreciate your help. Please let me know if you need any clarification. Thanks in advance!
Comment