Hi Folks,
I am new to the forum and I am now working on my thesis regarding equity analyst forecast errors on companies based on the data from I/B/E/S.
The following codes are a small clip of my data sorted by company id(CUSIP), analyst (ANALYS), quarter of the year (YEAR_Q) and forecast errors (FE).
Basically what I want to calculate now is the average of an analyst's forecast errors on the other companies he/she followed in the previous quarter.
For example, for analyst #380 who covered company 1416 in 2021q3, I want to generate a variable that captures his/her average forecast errors on company 494 and 2234 (not including company 1416) in 2021q2.
So the answer in this case would be -0.003 i.e. (-0.006+0)/2
If I am looking for the analyst's average forecast errors on other companies he/she covers in the current quarter, I could do it like the following discussion proposed:
https://www.stata.com/statalist/arch.../msg00462.html
However I am trying to do this for the previous quarter and codes I tried like the following didn't work (sorry I am pretty new to stata - errors I made may look silly)
bysort ANALYS YEAR_Q CUSIP: gen sum_FE_own_prev = sum(FE_own[_n-1])
or
bysort ANALYS YEAR_Q CUSIP: gen sum_FE_own_prev = sum(L1.FE_own)
I know I might need tsset for that but my YEAR_Q are not unique so errors of repeated time values in sample would occur.
Any help much appreciated!
P.S. using stata 17
Thank you very much!
Best,
Serena
I am new to the forum and I am now working on my thesis regarding equity analyst forecast errors on companies based on the data from I/B/E/S.
The following codes are a small clip of my data sorted by company id(CUSIP), analyst (ANALYS), quarter of the year (YEAR_Q) and forecast errors (FE).
Basically what I want to calculate now is the average of an analyst's forecast errors on the other companies he/she followed in the previous quarter.
For example, for analyst #380 who covered company 1416 in 2021q3, I want to generate a variable that captures his/her average forecast errors on company 494 and 2234 (not including company 1416) in 2021q2.
So the answer in this case would be -0.003 i.e. (-0.006+0)/2
If I am looking for the analyst's average forecast errors on other companies he/she covers in the current quarter, I could do it like the following discussion proposed:
https://www.stata.com/statalist/arch.../msg00462.html
However I am trying to do this for the previous quarter and codes I tried like the following didn't work (sorry I am pretty new to stata - errors I made may look silly)
bysort ANALYS YEAR_Q CUSIP: gen sum_FE_own_prev = sum(FE_own[_n-1])
or
bysort ANALYS YEAR_Q CUSIP: gen sum_FE_own_prev = sum(L1.FE_own)
I know I might need tsset for that but my YEAR_Q are not unique so errors of repeated time values in sample would occur.
Any help much appreciated!
P.S. using stata 17
Code:
input float a_CUSIP double ANALYS float(YEAR_Q FE_own) 1174 70 2021q2 -.0004757255 32 70 2021q3 -.001127759 512 70 2021q3 0 1565 70 2021q3 .00011461318 2245 70 2021q3 -.014095536 427 70 2022q2 -.0015798463 1089 70 2022q2 -.001376351 1565 70 2022q2 -.0003412652 2245 70 2022q2 .0004115791 2366 70 2022q2 -.0006048471 1565 70 2022q4 -.00007655502 486 380 2020q2 -.006934307 662 380 2020q2 -.004965243 1629 380 2020q2 -.006343568 2621 380 2020q2 -.00754976 497 380 2020q2 -.002758794 976 380 2020q3 -.001270971 494 380 2021q2 -.006 1416 380 2021q2 -.005897698 2234 380 2021q2 0 1416 380 2021q3 -.003161797 2234 380 2021q3 -.0015360983 2302 380 2021q4 .03836735 976 380 2022q2 -.0007688365
Thank you very much!
Best,
Serena

Comment