I'm a 3rd year Business Administration student working on a finance project about analyst forecast accuracy. My supervisor requires me to work with Stata which I never used before and haven't gotten any instructions whatsoever on how to work with this program. He has made it clear that I have to figure it out myself or with help from outside, so that's why I came to this forum for some help.
I am using the IBES database from WRDS which lists the following data:
Ticker (abbreviated firm name)
Activation date (date of forecast)
Year (derived from Activation date)
Estimated value (EPS forecast)
Actual value (EPS)
Absolute error (derived from Actual - Estimated)
I've got two problems at hand: 1. Mean absolute forecast error for a specific firm.
I have the individual absolute forecast error of a specific analyst for a specific firm in a given year, but I also need a column right next to it that will show the mean absolute forecast error for the firm in a given year, this is to compute the measure for the dependent variable 'forecast accuracy'.
>> What I tried is "mean abserror, over(ticker year)" but it returned me the 'no observations r(2000);' error?
a. Counting number of years for which a analyst i made a forecast through year t.
b. Counting number of years for which a analyst i made a forecast through year t for firm j.
c. Counting number of firms for which a analyst i made a forecast through year t.
What I tried is using the 'count observations using satisfying condition' in the menu which gave me the following commands:
"by analys year, sort : count if abserror>=0" for a.
"by analys year ticker, sort : count if abserror>=0" for b. and c.
This helped me a lot because it actually showed me the results I needed.
The only downside is I don't know how I make a variable out of it.
>> For example I tried putting "gen countyears=" in front of the command but it didn't work.
Also I need to find a way to separate b. and c. from each other as they both use the same kind of command. One counts number of years for a firm, the other counts number of firms for a year.
1. egen meanabserror = mean(abserror), by(ticker year)
2a. egen absgt0 = total(abserror>=0 & abserror<.), by(analys year)
See -help egen- for more information
You need the -abserror<.- because missing values in Stata are considered to be higher than any number. Therefore a missing value for abserror would be >=0 and would get counted, which is probably not what you want.