Hi everyone,
I've been using the user-written command Rangerun to accelerate the execution of my code.
More specifically, I've been calculating the variables industry munificence and industry dynamism. Even though the calculations are in fact correct, they take ages to run (this is on a single-core version of STATA that runs on 8th gen Intel chip that does ~4.2GHz single core turbo).
The data is from COMPUSTAT but it's rather large so there's no sense inn uploading it. The first step is to assign specific industries and my code assigns I believe 28 industries.
Then, I execute the following code:

Code:
*moving regression 5y industry sales
program drop _all
program doit
  regress ind_sale trend, vce(robust)
  gen obs1 = e(N)
  gen saletrend = _b[trend]
  gen salesse = _se[trend]
end
rangerun doit, interval(trend -4 0) by(sic2)

*calculate average and divide SE for sale
rangestat (mean) ind_sale, interval (fiscalyear -4 0) by(sic2)
gen envivol1 = salesse/ind_sale_mean
gen envimun1 = saletrend/ind_sale_mean

*moving regression 5y industry assets
program drop _all
program doit2
  regress ind_at trend, vce(robust)
  gen obs2 = e(N)
  gen attrend = _b[trend]
  gen atse = _se[trend]
end
rangerun doit2, interval(trend -4 0) by(sic2)

*calculate average and divide SE for at
rangestat (mean) ind_at, interval (fiscalyear -4 0) by(sic2)
gen envivol2 = atse/ind_at_mean
gen envimun2 = attrend/ind_at_mean

*moving regression 5y industry capex
program drop _all
program doit
  regress ind_capx trend, vce(robust)
  gen obs3 = e(N)
  gen capxtrend = _b[trend]
  gen capxse = _se[trend]
end
rangerun doit, interval(trend -4 0) by(sic2)

*calculate average and divide SE for sale
rangestat (mean) ind_capx, interval (fiscalyear -4 0) by(sic2)
gen envivol3 = capxse/ind_capx_mean
gen envimun3 = capxtrend/ind_capx_mean


/* environmental test2 */
gen industrydynamism=(envivol1+envivol2_envivol3)/3
sum industrydynamism

gen industrymun=(envimun1+envimun2+envimun3)/3
sum industrymun
The sic2 is the industry value. Basically, the code does a 5-year rolling regression per-industry and then stores the values of the slope and standard error and then the final values are calculted. This is usually done on ~150k total obs, but there are only 28 industries.
Again, the calculations are correct, but this takes ages to run (over 1 hour usually). Am I doing something wrong or is this the fastest way to do this?
Thank you!