SPB Git forge

spb/wp17_uqo

Public
2commits 1branches 1releases
19.9 MBsize
maindefault branch
57 min agolast push
TeX 74.5% Python 25.4%
6.7 KB · 111 lines python
Raw Blame History
1"""09_make_tables_ext.py -- LaTeX fragments for the extended tables (correlation, placebo,2event study, double sort, robustness, DiD)."""3import json, pandas as pd, numpy as np4T="results/tables"; R="paper/tables"5R2=json.load(open(f"{T}/results2.json")); EV=json.load(open(f"{T}/results_event.json"))6def w(n,b): open(f"{R}/{n}.tex","w").write(b)78# --- correlation matrix ---9c=pd.read_csv(f"{T}/t1b_correlations.csv",index_col=0)10lbl={"z_AI_ADOPT":"(1) AI adoption","z_AI_INFRA":"(2) AI infrastructure","z_AI_RISK":"(3) AI disruption risk",11     "z_size":"(4) Size","z_mom":"(5) Momentum","fwd_ret":"(6) Forward return"}12c=c.rename(index=lbl,columns={k:f"({i+1})" for i,k in enumerate(c.columns)})13rows="".join(f"{idx} & "+" & ".join(f"{c.loc[idx,col]:.2f}" for col in c.columns)+" \\\\\n" for idx in c.index)14w("tab_corr", r"""\begin{table}[H]\centering\small15\caption{Pearson correlations among standardized signals, controls, and the forward return.}\label{tab:corr}16\begin{tabular}{l"""+"r"*len(c.columns)+r"""}\toprule17& """+" & ".join(c.columns)+r""" \\\midrule18"""+rows+r"""\bottomrule19\end{tabular}\end{table}""")2021# --- placebo ---22pb=R2["placebo"]23rows=""24for n,v in pb.items():25    star="$^{\\dagger}$" if v["is_ai"] else ""26    rows+=(f"{n}{star} & {v['pre'][0]*100:+.1f} \\tstat{{{v['pre'][1]:.2f}}} & {v['post'][0]*100:+.1f} \\tstat{{{v['post'][1]:.2f}}} "27           f"& {v['interaction']:+.4f} \\tstat{{{v['interaction_t']:.2f}}} \\\\\n")28w("tab_placebo", r"""\begin{table}[H]\centering\small29\caption{Placebo test across all eight semantic factors. For each factor we report the Q5$-$Q1 forward-return spread (\%%/yr) in each sub-period and the coefficient on factor\,$z$\,$\times$\,Post-2022 (size/momentum controls, year-clustered SE). The post-ChatGPT jump is concentrated in AI-related factors ($\dagger$); ESG and climate go the other way.}\label{tab:placebo}30\begin{tabular}{lccc}\toprule31& \multicolumn{2}{c}{Q5$-$Q1 spread (\%%/yr)} & Interaction \\\cmidrule(lr){2-3}32Semantic factor & Pre (2010--21) & Post (2022--24) & $z\times$Post \\\midrule33%s\bottomrule34\end{tabular}\end{table}""" % rows)3536# --- event study ---37rows=""38hzlab={"car_60d":"+60 trading days","car_6m":"+6 months","car_1y":"+1 year","car_18m":"+18 months"}39for hz in ["car_60d","car_6m","car_1y","car_18m"]:40    e=EV[hz]41    rows+=f"{hzlab[hz]} & {e['High']:+.2f} & {e['Mid']:+.2f} & {e['Low']:+.2f} & {e['H_minus_L']:+.2f} & {e['t']:.2f} & {e['p']:.3f} \\\\\n"42xr=EV["xsec_reg_1y"]; xrs=EV["xsec_reg_1y_sectfe"]43w("tab_event", r"""\begin{table}[H]\centering\small44\caption{ChatGPT event study (event date 30 Nov 2022; market-model abnormal returns estimated over Jan--Oct 2022). Mean cumulative abnormal return (CAR, \%%) by pre-event AI-disclosure tercile (from the FY2021 10-K), and the High$-$Low difference with a Welch \textit{t}-test.}\label{tab:event}45\begin{tabular}{lrrrrrr}\toprule46Horizon & High & Mid & Low & High$-$Low & \textit{t} & \textit{p} \\\midrule47%s\midrule48\multicolumn{7}{l}{\footnotesize Cross-sectional regression, CAR(+1y) on pre-event AI exposure (per SD):}\\49\multicolumn{7}{l}{\footnotesize\quad No sector FE: $%+.2f$\%% \tstat{%.2f}, $n=%d$, $R^2=%.3f$ \quad50With sector FE: $%+.2f$\%% \tstat{%.2f}}\\51\bottomrule52\end{tabular}\end{table}""" % (rows, xr["ai_pre_coef"],xr["ai_pre_t"],xr["n"],xr["r2"],xrs["ai_pre_coef"],xrs["ai_pre_t"]))5354# --- double sort ---55dpre=pd.read_csv(f"{T}/t6_double_sort_pre.csv",index_col=0)56dpost=pd.read_csv(f"{T}/t6_double_sort_post.csv",index_col=0)57def dsrows(dd):58    out=""59    for sz in ["Small","Large"]:60        out+=f"{sz} & {dd.loc[sz,'Lo']:.1f} & {dd.loc[sz,'Mid']:.1f} & {dd.loc[sz,'Hi']:.1f} & {dd.loc[sz,'Hi']-dd.loc[sz,'Lo']:+.1f} \\\\\n"61    return out62w("tab_doublesort", r"""\begin{table}[H]\centering\small63\caption{AI~disclosure $\times$ size double sort: mean forward 12-month return (\%%). Within each size half, firms are split into AI terciles.}\label{tab:doublesort}64\begin{tabular}{lcccc}\toprule65& Low AI & Mid AI & High AI & Hi$-$Lo \\\midrule66\multicolumn{5}{l}{\textit{Panel A. Pre-ChatGPT (2010--2021)}}\\67%s\midrule68\multicolumn{5}{l}{\textit{Panel B. Post-ChatGPT (2022--2024)}}\\69%s\bottomrule70\end{tabular}\end{table}""" % (dsrows(dpre),dsrows(dpost)))7172# --- robustness combined ---73mg=R2["mag7"]; sg=R2["alt_signal"]; hr=R2["alt_horizon"]; sn=R2["sector_neutral"]; pca=R2["pca"]74def cellv(pair):75    v,t=pair[0]*100,pair[1]76    return f"{v:+.1f}"+(f" \\tstat{{{t:.2f}}}" if t==t else "")77def line(label,pre,post):78    return f"{label} & {cellv(pre)} & {cellv(post)} \\\\\n"79body =r"\multicolumn{3}{l}{\textit{Panel A. Alternative signal definition (composite)}}\\"+"\n"80for k in ["wmean(base)","mean","top5pct"]:81    body+=line({"wmean(base)":"Section-weighted (base)","mean":"Simple mean","top5pct":"Top-5\\% tail"}[k], sg[k]["pre"],sg[k]["post"])82body+=r"\midrule\multicolumn{3}{l}{\textit{Panel B. Alternative holding horizon}}\\"+"\n"83body+=line("6-month forward return",hr["6m"]["pre"],hr["6m"]["post"])84body+=line("24-month forward return",hr["24m"]["pre"],hr["24m"]["post"])85body+=r"\midrule\multicolumn{3}{l}{\textit{Panel C. Construction / universe}}\\"+"\n"86body+=line("Sector-neutral composite",sn["pre"],sn["post"])87body+=line("First principal component",pca["pre"],pca["post"])88body+=f"Excl.\\ Magnificent-7 & {mg['ex_mag7_pre'][0]*100:+.1f} \\tstat{{{mg['ex_mag7_pre'][1]:.2f}}} & {mg['ex_mag7_post'][0]*100:+.1f} \\tstat{{{mg['ex_mag7_post'][1]:.2f}}} \\\\\n"89body+=f"Excl.\\ top-10 by market cap & --- & {mg['ex_top10_post'][0]*100:+.1f} \\tstat{{{mg['ex_top10_post'][1]:.2f}}} \\\\\n"90w("tab_robust", r"""\begin{table}[H]\centering\small91\caption{Robustness of the AI return spread (composite Q5$-$Q1, \%%/yr, Newey--West \textit{t}). The post-ChatGPT spread is stable across signal definitions, horizons, sector-neutralization, dimension reduction, and the exclusion of mega-cap winners.}\label{tab:robust}92\begin{tabular}{lcc}\toprule93& Pre (2010--21) & Post (2022--24) \\\midrule94%s\bottomrule95\end{tabular}\end{table}""" % body)9697# --- DiD ---98did=R2["did"]99w("tab_did", r"""\begin{table}[H]\centering\small100\caption{Difference-in-differences around ChatGPT. Dependent variable is the winsorized forward 12-month return; firm and year fixed effects; SE double-clustered by firm and year. Treatment is fixed at the firm's pre-event (2019--2021) AI exposure.}\label{tab:did}101\begin{tabular}{lcc}\toprule102& Treated$\times$Post & Exposure$\times$Post \\103& (binary) & (continuous, per SD) \\\midrule104Coefficient & %.4f & %.4f \\105\textit{t}-statistic & (%.2f) & (%.2f) \\106N (firm-years) & %d & %d \\107Firm \& Year FE & Yes & Yes \\\bottomrule108\end{tabular}\end{table}""" % (did["binary"]["coef"],did["continuous"]["coef"],did["binary"]["t"],did["continuous"]["t"],did["binary"]["n"],did["continuous"]["n"]))109110print("extended LaTeX tables written")111