This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gyllila
Recipients gyllila
Date 2020-11-06.12:44:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1604666660.35.0.85933411244.issue42276@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-11-06 12:44:20gyllilasetrecipients: + gyllila
2020-11-06 12:44:20gyllilasetmessageid: <1604666660.35.0.85933411244.issue42276@roundup.psfhosted.org>
2020-11-06 12:44:20gyllilalinkissue42276 messages
2020-11-06 12:44:20gyllilacreate