linearmodels icon indicating copy to clipboard operation
linearmodels copied to clipboard

ENH: Improve exception when estimation of kappa is preventing fitting an IV2SLS model

Open roy1312 opened this issue 3 years ago • 2 comments

Hi!

I was trying to fit an IV2SLS model, but a LinAlgError: Eigenvalues did not converge was raised. The error happens when _estimate_kappa is called. More precisely, it happens because the first eigenvalue of ez.T @ ez matrix is -6.98956008e-15. Therefore a problem of taking sqrt of negative number arises when inv_sqrth is called inside the _estimate_kappa function.

But I don't think an estimation of kappa is needed in this case, because 2SLS model assumes kappa = 1. And I succeeded in estimating the parameters by calling function estimate_parameters directly. Is there any way to fit the model without calling _estimate_kappa? Thanks a lot!

roy1312 avatar Jun 15 '22 08:06 roy1312

I saw you closed. Presumable this means that Z is not full rank which will cause problems later. This said, it would be good to provide a better error when this happens.

bashtage avatar Jun 15 '22 09:06 bashtage

Thanks for the reply! It turns out that I made a mistake in putting the same variable as both the endogenous variable and the instrument. The problem disappears once I correct it. Yes, a better error message that tells me this kind of obvious mistake would save a lot confusion!

roy1312 avatar Jun 15 '22 09:06 roy1312