import numpy as np
import statsmodels.api as sm
data = np.array(
[ 849.27, 807.59, 803.59, 849.7 , 852.19, 845.06, 833.77,
788.46, 800.32, 814.66, 829.21, 799.49, 812.24, 772.62,
782.13, 779.66, 752.86, 758.39, 738.47, 721.11, 642.04,
718.72, 743.47, 709.57, 704.48, 673.51])
nobs = len(data)
trend = np.arange(nobs)
proc = (trend >= 18).astype(int)
x = np.column_stack((np.ones(nobs), trend, proc, (trend - 18)*proc))
res = sm.OLS(data, x).fit()
res.model.exog_names[:] = ['const', 'trend', 'const_diff', 'trend_new']
print(res.summary())
res2 = sm.OLS(data, x).fit()
res2.model.exog_names[:] = ['const', 'trend', 'const_diff']
print(res2.summary())
res4 = sm.OLS(np.log(data), x).fit()
res4.model.exog_names[:] = ['const', 'trend', 'const_diff']
print(res4.summary())
res3 = sm.Poisson(data, x).fit(cov_type='HC0', method='nm', maxiter=5000)
res3 = sm.Poisson(data, x).fit(start_params=res3.params, cov_type='HC0', method='bfgs')
res3.model.exog_names[:] = ['const', 'trend', 'const_diff']
print(res3.summary())
print(np.exp(res3.params))