revised to make the code work across different statsmodels and python versions and to include a non-parallel run