SPB Git

Repository Public Research preview

04_baseline.py 1.9 KB 50 lines python

1"""Baseline tests of H1, H2 and H5 on the daily panel (pre-specified in experiments/PRE_ANALYSIS_PLAN.md)."""2import json34import numpy as np5import pandas as pd67from config import RES8from panel import fe_ols, randomisation_p, stars9from sample import CONTROLS, add_interactions, daily_panel, winsor1011OUT = ["d_cr25", "d_cr10", "d_skew25", "d_bf10", "d_atm"]121314def run(p, y, shocks, chars=("F",), controls=CONTROLS):15    X = add_interactions(p, shocks, chars, controls)16    return fe_ols(p, y, X), X171819def main():20    p = winsor(daily_panel("1M"), OUT)21    rows, store = [], {}22    specs = {23        "pol": ["u_pol"], "pol+phy": ["u_pol", "u_phy"], "agg": ["u_agg"],24        "bua": ["bua_tri", "bua_pri"], "pol+epu": ["u_pol", "u_epu"],25    }26    for y in OUT:27        for name, sh in specs.items():28            for ctl_name, ctl in (("controls", CONTROLS), ("none", [])):29                f, X = run(p, y, sh, ("F",), ctl)30                for j, s in enumerate(sh):31                    rows.append(dict(y=y, spec=name, controls=ctl_name, shock=s, b=f.b[j],32                                     se_2way=f.se()[j], t_2way=f.t()[j], t_dk=f.t("dk")[j],33                                     t_unit=f.t("unit")[j], t_time=f.t("time")[j], n=f.n, N=f.ni, T=f.nt))34    res = pd.DataFrame(rows)35    res.to_csv(RES / "baseline_daily.csv", index=False)36    print(res[res.controls == "controls"].round(4).to_string())37    # H2: butterfly on absolute exposure gap38    r2 = []39    for y in ["d_bf10", "d_bf25", "d_atm"]:40        if y not in p:41            continue42        f, X = run(p, y, ["u_pol", "u_phy"], ("absF",))43        r2.append(dict(y=y, b_pol=f.b[0], t_pol=f.t()[0], b_phy=f.b[1], t_phy=f.t()[1], n=f.n))44    pd.DataFrame(r2).to_csv(RES / "h2_butterfly.csv", index=False)45    print(pd.DataFrame(r2).round(4))46    # randomisation inference is done by the C++ programs in src/cpp (see 09-11)4748if __name__ == "__main__":49    main()50
Files main
Menu

Theme