Hi,

I am running a Moran’s test of residual correlation with nearby residuals.
I know that Moran runs on regress but if i run it after ivreg2 doesn't work
this is a snipped of my code:


foreach y of numlist 2013 2018 {
sum vote_fdi`y'
*** 2SLS
ivreg2 vote_fdi`y' (opp_rate = iv_jmeansent), robust
ivreg2 vote_fdi`y' (opp_rate = iv_jmeansent) $covars, robust
}


spmatrix create contiguity W, replace
estat moran, errorlag(W)


After running the test I get this error:
estat moran not valid
r(321);

How can I solve this?
Thanks everyone