program define volfc, rclass
version 7.0
syntax varname(numeric) ,Vol(string) [Win(integer 12) AR(integer 4)]
quietly tsset
if `win' < `ar' {
   dis "You must have a longer window than AR length!"
   error 198
   }
quietly gen `vol'=.
local start = `win'+`ar'
quietly summ `varlist', meanonly
local last = r(N)
dis _n "`vol': volatility forecast for `varlist' with window=`win', AR(`ar')"
forv i=`start'/`last' {
     local first = `i'-`win'+1
     quietly regress `varlist' L(1/`ar').`varlist' in `first'/`i'
     quietly replace `vol' = e(rmse) in `i'/`i'
     }
exit
end