# Ceteris Lab downloadable Python script
# Course: Fundamentals of Python for Financial Econometrics

import pandas as pd, statsmodels.formula.api as smf
rows=[]
for g in [0,1]:
  for t in range(8):
    for i in range(40): rows.append((g,t,10+.5*t+g+(3 if (g==1 and t>=4) else 0)))
df=pd.DataFrame(rows,columns=['treated','time','y']); df['post']=(df.time>=4).astype(int)
fit=smf.ols('y ~ treated * post + C(time)',data=df).fit()
print('DID',fit.params['treated:post'])
