We propose a nonparametric method for automatically selecting the numb
er of autocovariances to use in computing a heteroskedasticity and aut
ocorrelation consistent covariance matrix. For a given kernel for weig
hting the autocovariances, we prove that our procedure is asymptotical
ly equivalent to one that is optimal under a mean-squared error loss f
unction. Monte Carlo simulations suggest that our procedure performs t
olerably well, although it does result in size distortions.