Am 14.04.2018 um 22:32 schrieb Allin Cottrell:
On Sat, 14 Apr 2018, Sven Schreiber wrote:
> Am 14.04.2018 um 15:08 schrieb Riccardo (Jack) Lucchetti:
>> And, by the way, lends itself quite nicely to also
implementing VAR
>> prewhitening à la Andrews:
>
> Thanks; and speaking about VARs, it is possible to ask gretl for HAC
> cov-estimation there, too. (See also section 19.3 of the guide.) The
> HAC errors internally use an estimate of the long-run variance of the
> residuals, I would expect, right? That would mean that the necessary
> code is already in gretl (in C), it's just not accessible at the hansl
> level - is that correct?
I think so. You could browse lib/src/qr_estimate.c, which contains most
of the HAC-related code. The relevant section starts with the function
wtw() and continues through qr_make_hac().
Thanks Allin. Indeed, it very much looks like (almost) all is needed is
the C function HAC_XOX. The only difference is that this function
expects regressors X and residuals u to calculate the long-run
(co)variance of X'u. While for the general case the function would need
to accept H = X as a single matrix directly without any u.
So HAC_XOX could be called leaving the *uhat argument as NULL, and then
in the newey_west_H function change the line:
gretl_matrix_set(H, t, j, xtj * u->val[t]);
to something like this:
if (u != NULL) {
gretl_matrix_set(H, t, j, xtj * u->val[t]);
}else{
gretl_matrix_set(H, t, j, xtj);
}
Plus then expose the HAC_XOX apparatus to a new hansl function
lrcovar(). Does that sound OK?
(Or extend lrvar to this thing whenever its argument is a 2-dim matrix
or a list. Don't know if the latter is feasible/easy, since currently it
only returns a scalar.)
This would be very nice mainly in terms of speed of course. That the
same thing is feasible in pure hansl is already clear.
cheers,
sven