New submission from Guo <guoyanling_2...@yahoo.de>:

from statsmodels.tsa.stattools import adfuller
adf = adfuller(x, regression=‘c’, autolag=‘t-stat’)

Sometimes comes error message:
UnboundLocalError: local variable ‘bestlag’ referenced before assignment 

I found the reason: when using t-stat, bestlag is only assigned, when the last 
lag becomes significant the first time, so if no lag has a significant t-value, 
then bestlag is never assigned

I fixed this bug this way: open the file stattools.py and find the lines:
elif method == “t-stat”:
  #stop = stats.norm.ppf(.95)
  stop = 1.6448536269514722
Then add here following two lines:
  bestlag = startlag
  icbest = np.abs(results[startlag].tvalues[-1])

This way, the code won’t crash again and t-stat simply uses no lag when there 
is no significant value

----------
components: Library (Lib)
messages: 380446
nosy: gyllila
priority: normal
severity: normal
status: open
title: Bug in adfuller test and a suggested fix
type: enhancement
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42276>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to