TypeError: list indices must be integers, not NoneType in sandbox.regression.gmm.IV2SLS results

24 views
Skip to first unread message

Diego Guerrero

unread,
Nov 18, 2017, 4:45:54 PM11/18/17
to pystatsmodels
Hi,

I've been using statsmodels for a while but it's my first time running IV2SLS. I'm running the following code:


from statsmodels.sandbox.regression.gmm import IV2SLS
resultIV = IV2SLS(endog=df['y'], exog=df[[x1', 'IV1']], instrument=wage2[['x1', IV1']]).fit()
print resultIV.summary()

The following Traceback results:


---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-95-6c03bb2930c9> in <module>()
----> 4 print resultIV.summary() c:\python27\lib\site-packages\statsmodels\sandbox\regression\gmm.pyc in summary(self, yname, xname, title, alpha)
325 top_right = [('R-squared:', ["%#8.3f" % self.rsquared]),
326 ('Adj. R-squared:', ["%#8.3f" % self.rsquared_adj]),
--> 327 ('F-statistic:', ["%#8.4g" % self.fvalue] ),
328 ('Prob (F-statistic):', ["%#6.3g" % self.f_pvalue]),
329 #('Log-Likelihood:', None), #["%#6.4g" % self.llf]), c:\python27\lib\site-packages\statsmodels\tools\decorators.pyc in __get__(self, obj, type)
95 if _cachedval is None:
96 # Call the "fget" function
---> 97 _cachedval = self.fget(obj)
98 # Set the attribute in obj
99 # print("Setting %s in cache to %s" % (name, _cachedval)) c:\python27\lib\site-packages\statsmodels\sandbox\regression\gmm.pyc in fvalue(self)
217 restriction = np.eye(k_vars)
218 idx_noconstant = lrange(k_vars)
--> 219 del idx_noconstant[self.model.data.const_idx]
220 fval = self.f_test(restriction[idx_noconstant]).fvalue # without constant
221 return fval TypeError: list indices must be integers, not NoneType

josef...@gmail.com

unread,
Nov 18, 2017, 8:06:05 PM11/18/17
to pystatsmodels
I think you should add a constant to your dataframe and include them in exog and in instrument.
The constant is not added by default.

The fix for the no-constant case is here
https://github.com/statsmodels/statsmodels/issues/3544

IIRC, a temporary workaround is to set fvalue in cache
resultIV._cache['fvalue'] = np.nan
before calling summary()

Josef

Reply all
Reply to author
Forward
0 new messages