This macro is used to count the number of analysts who followed a specific firm. Although this is a commonly used measure in literature, prior studies often give a vague description on what they do. The question is—what does “analysts following a firm” really mean?
First, it is only meaningful to count the number at a specified date.
Second, how to define “an analyst is actually following a firm”? I use the following definition: if an analyst issued any forecast (EPS or stock price or sales, anything) within a certain window (e.g., 180 days) before the specified date, then the analyst will be counted in. This definition ensures that the analyst is “actively” following the firm.
That is why my macro requires two arguments: DATE and WINDOW. This macro is used to answer such question—at a specified date, how many analysts are actively following Firm A, B, …?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
%MACRO ANALYST_COUNT(INFILE=, TICKER=, DATE=, WINDOW=, OUTFILE=); /* This macro is used to count the number of analysts who followed a */ /* specific firm at a specified date (DATE). Any analyst who issued any */ /* forecast during the window (WINDOW) before the specified date (DATE) */ /* will be counted in. */ /* This macro use both Detailed History Unadjusted (EPS for US Region) */ /* and Unadjusted (Non-EPS for US Region). INFILE should contain IBES */ /* Ticker (TICKER) and DATE. */ options mprint; /* Stack Detailed History Unadjusted (EPS for US Region) and */ /* Unadjusted (Non-EPS for US Region). */ data detu; set ibes.detu_epsus ibes.detu_xepsus; run; /* Merge analysts who issued a forecast during the window. */ proc sql; create table ibes1 as select a.*, b.estimator, b.analys, b.anndats from (select distinct &TICKER, &DATE from &INFILE) a, detu b where not missing(a.&TICKER) and a.&TICKER=b.ticker and not missing(a.&DATE) and a.&DATE-&WINDOW+1<=b.anndats<=a.&DATE and not missing(b.value); quit; /* Retain the most recent forecast from a specific analyst. */ proc sort data=ibes1; by &TICKER &DATE estimator analys descending anndats; run; proc sort data=ibes1 out=ibes2 nodupkey; by &TICKER &DATE estimator analys; run; /* Count the number of analysts who issued a forecast during the window. */ proc sql; create table ibes3 as select distinct &TICKER, &DATE, count(anndats) as analyst_count from ibes2 group by &TICKER, &DATE; quit; /* Merge INFILE with number of analysts */ proc sql; create table &OUTFILE as select a.*, b.analyst_count from &INFILE a left join ibes3 b on a.&TICKER=b.&TICKER and a.&DATE=b.&DATE; quit; proc sql; drop table detu, ibes1, ibes2; quit; %MEND; |
Dear Kai Chen
Thank you so much for your sharing, that’s really helpful.
I wonder if it is possible for you to share the code that calculates analyst past three forecast accuracy. I could not find any resources and not sure whether I did wrong.
I would be grateful if you could share this.
Thank you so much
Sincerely
Ruohan
Hi,
Thanks for sharing this. I am relatively new to SAS. I am wondering how to use this code to calculate analyst following for multiple(10-20) dates for a specific firm?
Hi Kai,
I do really appreciate your work here. Thank you very much
Hi Kai,
have a quick question.
Is it okay not to kick out estimates from analysts who have stopped covering or been excluded? I saw some codes to kick out those estimates, because their esimates are not updated.