On Mon, 11 Dec 2017, Filipe Rodrigues da Costa wrote:
Ok, here it goes:
-------------------------------------------
open data9-13.gdt
list returns = *ret
# set some parameters for the rolling regression
scalar step = 1 # regression step
scalar size = 12 # regression size
scalar rolls = floor(($nobs - size + 1) / step) #number of rolls
scalar firstobs = $t1
# generate empty beta series
loop foreach i returns
series beta$i = NA
endloop
# set the initial sample
smpl firstobs firstobs+size-1
loop r = 1 .. rolls
loop foreach i returns
if sum(missing(returns.$i)) == 0
lad returns.$i const sp500
series beta$i[$t2] = $coeff[2]
endif
endloop
if r<rolls
smpl +step +step
endif
endloop
smpl --full
---------------------------------------------------------
In the example both OLS and LAD seem to work well. The problem is that
with my large data files, LAD doesn't work.
I tried modifying your example above, replacing
open data9-13.gdt
list returns = *ret
with
nulldata 1000
list returns
loop i=1..50
returns += genseries(sprintf("x%dret", i), normal())
endloop
series sp500 = normal()
but leaving the rest unchanged. So that's 1000 observations on 50
returns and the script still ran OK. Roughly what are the actual
dimensions of your data?
Additional thought: you might try replacing
lad y const x
with
quantreg 0.5 y const x
That should probably be faster for large data.
Allin