Hi All

I am a beginner with Stata and am working with analyst data downloaded from IBES. I am using Stata to compute the dispersion of forecasts made by analysts over a certain period. The formula that I need to calculate is as follows:
Std Dev of earnings forecasts issued by individual analysts in year t/ Stock price of year t-1

I have used the following Stata code to do the above computation:

gen fyear=year(fpedats)

gen fmonth=month(fpedats)

gen year_actual=year(anndats_act)

gen month_actual=month(anndats_act)

sort ticker fyear analys fpedats

gen date=anndats_act-anndats

sort ticker fyear analys fpedats date

by ticker fyear analys fpedats: gen n=_n

keep if n==1 (deleting multiple forecasts from one analyst in a year)

sort ticker fyear (fpedats)

by ticker fyear: gen analyst_num=_N

sort ticker fyear (fpedats)

by ticker fyear: egen std_forecast_full=sd(value)

With the above code, I hope to compute the 1st part of my formula, that is std dev of forecasts issued by individual analysts. However, the mean of this final column (std_forecast_full) is very high like 1234.56 etc. I think this is not right.
Can someone please point what is wrong with above code? Can someone also tell what would be the code to divide this column with stock price from last year?

Thank you so much for the help! Please let me know shall further information be required.