Issue with robust covariance matrix in IV2SLS

73 views
Skip to first unread message

Sylvain Delalay

unread,
Jul 26, 2017, 5:56:41 PM7/26/17
to pystatsmodels
Hello,

I get an error when retrieving the robust covariance matrix of an IV regression. The model fits fine and the summary method works well.

Here are the code and error:

IV = IV2SLS(y,X,Z).fit()

IV.get_robustcov_results('HC0')


Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/usr/local/lib/python2.7/dist-packages/statsmodels/regression/linear_model.py", line 1788, in get_robustcov_results

getattr(self, cov_type.upper() + '_se')

File "/usr/local/lib/python2.7/dist-packages/statsmodels/tools/decorators.py", line 94, in __get__

_cachedval = self.fget(obj)

File "/usr/local/lib/python2.7/dist-packages/statsmodels/regression/linear_model.py", line 1327, in HC0_se

return np.sqrt(np.diag(self.cov_HC0))

File "/usr/local/lib/python2.7/dist-packages/statsmodels/tools/decorators.py", line 94, in __get__

_cachedval = self.fget(obj)

File "/usr/local/lib/python2.7/dist-packages/statsmodels/regression/linear_model.py", line 1279, in cov_HC0

cov_HC0 = self._HCCM(self.het_scale)

File "/usr/local/lib/python2.7/dist-packages/statsmodels/regression/linear_model.py", line 1267, in _HCCM

H = np.dot(self.model.pinv_wexog,

AttributeError: 'IV2SLS' object has no attribute 'pinv_wexog'



Thanks

Sylvain

josef...@gmail.com

unread,
Jul 26, 2017, 6:28:56 PM7/26/17
to pystatsmodels
I don't remember the theory or details right now.

IV2SLS was never checked for robust covariance, and mostly written before cov_type options. The get_robustcov_results is inherited but doesn't have the 2SLS specific code.

The robust cov methods are supposed to be covered by GMM, IVGMM which allows heteroscedasticity or correlation in the weight matrix and in the covariance sandwich of the parameter estimate.

(I don't remember right now, but something like iter=0 or iter=1, weights = Z'Z  and covtype HC should correspond to IV2SLS with robust cov_params.)

Josef

Sylvain Delalay

unread,
Jul 26, 2017, 7:46:23 PM7/26/17
to pystatsmodels

Kevin Sheppard

unread,
Jul 27, 2017, 2:12:53 AM7/27/17
to pystatsmodels
There is a working IV2SLS in linearmodels, https://github.com/bashtage/linearmodels .

Sylvain Delalay

unread,
Jul 27, 2017, 5:26:12 PM7/27/17
to pystat...@googlegroups.com
I didn't know about your package, it looks interesting. I'll install Python 3.5 to try it out.

Thanks! 
Sylvain
Reply all
Reply to author
Forward
0 new messages