1#!/usr/bin/env python2"""Step 07b — Model D robustness: dealer x day-of-week fixed effects (repricing calendars) and3day-of-week FE; also competitor-cut COUNT instead of indicator."""4import json5import numpy as np, pandas as pd, polars as pl6from ucml import competition as cp7from ucml import config as C8df = cp.load("25")9df["dow"] = (df["t"] + 2) % 7 # day 0 = 2026-08-12 (Wednesday) -> 0..6 arbitrary labels10df["dealer_dow"] = pd.factorize(df["dealer_id"].astype(str) + "|" + df["dow"].astype(str))[0]11res = {}12res["dow_fe"] = cp.fit(df, fe="mkt_week + mmy_week + dow", name="dow_fe")13res["dealer_dow_fe"] = cp.fit(df, fe="mkt_week + mmy_week + dealer_dow", name="dealer_dow_fe")14res["dealer_dow_fe_firstcut"] = cp.fit(df[df["in_first_cut_risk"]], y="first_cut", fe="mkt_week + mmy_week + dealer_dow", name="dealer_dow_fe_firstcut")15json.dump(res, open(cp.OUT / "summary_dow.json", "w"), indent=2, default=float)16for k, v in res.items():17 print(k, "leads p=%.3g sum=%.4f | lags p=%.3g sum=%.4f | lag0-7 sum=%.4f" % (v["leads_joint"]["p"], v["leads_joint"]["sum"], v["lags_joint"]["p"], v["lags_joint"]["sum"], v["lag0_7_sum"]["sum"]))18 print({kk: round(vv["b"]*100, 3) for kk, vv in v["coef"].items()})19