Closed ALLemmens closed 1 year ago
It is generally suggested to use at least the linearly independent columns of X, WX, WWX.
Somewhat related.
There is an option in stslshac to set W2X=FALSE, but when specified, it generates an error:
Error in stslshac(spec2, data = df, listw = wq, HAC = FALSE, W2X = FALSE) : object 'wwx' not found
As it turns out, in the source code line 164 etc:
if (k > 1) { WX <- matrix(nrow = n, ncol = (k - (K - 1))) WWX <- matrix(nrow = n, ncol = (k - (K - 1))) for (i in K:k) { wx <- lag.listw(listw, x[, i], zero.policy = zero.policy) if(W2X) wwx<- lag.listw(listw, wx, zero.policy = zero.policy) <====== if (any(is.na(wx))) stop("NAs in lagged independent variable") WX[, (i - (K - 1))] <- wx WWX[, (i - (K - 1))] <- wwx <====== } }
it looks like wwx is only initialized if (W2X) is true, but then it seems to be used in all cases since WWX is assigned, but there is no wwx and no check for W2X False at that stage.
It is indeed good practice to use WX and WWX as instruments, but by no means always necessary. In fact, the additional multicollinearity may sometimes be problematic. So, in general, I think it is a good idea to include W2X=FALSE as an option, but it does not seem to work for stslshac.
L.
Thanks for spotting this Luc! It has been fixed now!
One more thing: for spreg, it will probably take longer since it allows for the Durbin model.
Dear dr. Piras,
Thank you so much for the implementation of sphet.
I was wondering, is it possible to use only WX as an instrument in spreg and in gstslshet?
In the hidden code at https://rdrr.io/cran/sphet/src/R/hidden_functions.R I saw that it always uses WX and WWX. However, with my dataset WX and WWX have perfect multicolinearity between certain columns. (I use dummies which have the same value for everyone in the same block of the W-matrix).
Why is it not possible for me to choose which power I want to use as an instrument? Is it because just using WX instead of WX and WWX would lead to inconsistent results? Or for another reason.
Kind regards, A.Lemmens