On Sat, 14 Apr 2018, Sven Schreiber wrote:
[moving this to the devel list]
Am 13.04.2018 um 21:50 schrieb Sven Schreiber:
> Am 13.04.2018 um 18:24 schrieb Sven Schreiber:
>> I'm wondering how to achieve something that would be the multivariate
>> generalization of the lrvar function (long-run variance of a series).
> Duh, dummy me -- it's in my own package CommonTrendsTest.
I'm reproducing the two private functions autocovar() and longrunvar() from
the package below. The question is whether it might make sense to add these
to the extra package, or whether it could be considered to generalize the
built-in lrvar() to multivariate (like it seems to be the case in R, for
example).
What do you think?
(I'm also open for suggestions to increase efficiency, but that's not very
pressing right now. I think I read about fast algorithms that use the FFT for
example.)
The following implementation looks reasonably efficient to me.
<hansl>
function matrix longrunvar (matrix X, bool demeaned[0],
int lagtrunc[0::4])
scalar N = cols(X)
scalar T = rows(X)
if !demeaned
matrix X = cdemean(X)
endif
matrix result = X'X
if lagtrunc
A = X'mlag(X, seq(1,lagtrunc))
ini = 1
fin = N
loop tau = 1..lagtrunc --quiet
matrix Gamma = A[,ini:fin]
result += (1 - tau / (lagtrunc + 1)) * (Gamma + Gamma')
ini = fin+1
fin += N
endloop
endif
return result ./ T
end function
</hansl>
-------------------------------------------------------
Riccardo (Jack) Lucchetti
Dipartimento di Scienze Economiche e Sociali (DiSES)
Università Politecnica delle Marche
(formerly known as Università di Ancona)
r.lucchetti(a)univpm.it
http://www2.econ.univpm.it/servizi/hpp/lucchetti
-------------------------------------------------------