On Mon, 16 Apr 2018, Sven Schreiber wrote:
Am 16.04.2018 um 05:48 schrieb Allin Cottrell:
> On Sun, 15 Apr 2018, Sven Schreiber wrote:
>> However, jack's longrunvar() function has an additional factor 1/T in the
>> result, and it seems to me this is correct (thus, missing in lrcovar as of
>> now).
>
> Yes, I was thinking the magnitude looked off, and 1/T would be the
> difference. It seems that gets applied at a later stage (than HAC_XOX) in
> the process of constructing a HAC covariance matrix in libgretl.
Yes, it's a bit complex to track this down (at least for me). I'm looking at
qr_make_vcv and it seems that (only) the diagonal is multiplied with
pmod->sigma. My best guess so far is that that's where the factor 1/T (or its
square root) comes in and that actually only the diagonal of that matrix is
really usable.
If you're computing a HAC vcv manually you don't want the "XOX" matrix
divided by T, since that is handled by the sandwiching with inv(X'X).
(And you don't need demeaning if X and u are supposed to be
orthogonal.) In current git lrcovar divides by T and assumes demeaning
is needed by default, so here's how one would replicate the built-in
calculation.
<hansl>
set verbose off
open data9-7
list L = 0 2 3
# plain vcv for reference
ols 1 L --simple
eval $vcv
# built-in HAC vcv -- correct!
ols 1 L --robust --simple
V1 = $vcv
print V1
# manual version
matrix u = $uhat
matrix X = {L}
set hac_lag 2 # to emulate the above
matrix XOX = $T * lrcovar(X .* u, 1)
V2 = qform(inv(X'X), XOX)
print V2
</hansl>
Allin