On Sun, 15 Apr 2018, Sven Schreiber wrote:
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?
Yes. It's now in git.
matrix X = mnormal(100, 5)
matrix V = lrcovar(X)
print V
The experimental lrcovar() takes just one argument but I've left a
couple of "empty slots" that could be used for additional arguments
to inflect its behaviour. As things stand, the details depend on the
"set" variables hac_lag, hac_kernel and hac_prewhiten.
Allin