I would like to calculate relative_all forecast accuracy and I intend to use the following code. However, it spends too much time (1 year/day). I am wondering is there any better/efficient way to do this? Thank you so much.

gen max_relative_fe_all =.
gen min_relative_fe_all =.

su fiscal_year
scalar a= r(min)
scalar b= r(max)
forvalues i= `=scalar(a)'/`=scalar(b)' {
vallist gvkey if fiscal_year ==`i'
local d=r(list)
foreach k in `d' {
vallist analys if fiscal_year ==`i' & gvkey==`k'
local c=r(list)
foreach j in `c' {
su absoluteFE if analys!=`j' & fiscal_year==`i' & gvkey==`k'
replace max_relative_fe_all=r(max) if analys==`j' & fiscal_year==`i' & gvkey==`k'
replace min_relative_fe_all=r(min) if analys==`j' & fiscal_year==`i' & gvkey==`k'
di `i'
di `j'
di `k'
}
}
}