b = m3a.params
pred_a = {"Pequeña": b["Intercept"],
"Mediana": b["Intercept"] + b["C(tamano)[T.Mediana]"],
"Grande": b["Intercept"] + b["C(tamano)[T.Grande]"]}
rng = np.random.default_rng(7)
fig, ax = plt.subplots(figsize=(7.5, 4.8))
for i, g in enumerate(["Pequeña", "Mediana", "Grande"]):
y = df.loc[df["tamano"] == g, "roa"]
x = i + rng.uniform(-0.25, 0.25, len(y))
ax.scatter(x, y, s=10, alpha=0.35, color=COL[g], marker=MRK[g])
ax.hlines(pred_a[g], i - 0.35, i + 0.35, color="black", lw=2.5)
ax.text(i + 0.38, pred_a[g], f"{pred_a[g]:.3f}", va="center", fontsize=9,
bbox=dict(fc="white", ec="none", alpha=0.85))
# Flechas que muestran los coeficientes b1 y b2 como distancias al grupo base
ax.annotate("", xy=(1, pred_a["Mediana"]), xytext=(1, pred_a["Pequeña"]),
arrowprops=dict(arrowstyle="->", color="black", lw=1.2))
ax.text(1.05, (pred_a["Mediana"] + pred_a["Pequeña"])/2, "b1 = 0.208", fontsize=9,
bbox=dict(fc="white", ec="none", alpha=0.85))
ax.annotate("", xy=(2, pred_a["Grande"]), xytext=(2, pred_a["Pequeña"]),
arrowprops=dict(arrowstyle="->", color="black", lw=1.2))
ax.text(2.05, (pred_a["Grande"] + pred_a["Pequeña"])/2, "b2 = 0.325", fontsize=9,
bbox=dict(fc="white", ec="none", alpha=0.85))
ax.axhline(pred_a["Pequeña"], color="grey", ls=":", lw=1)
ax.set_xticks([0, 1, 2]); ax.set_xticklabels(["Pequeña", "Mediana", "Grande"])
ax.set_ylim(-1.3, 0.5)
ax.set_ylabel("ROA"); ax.set_xlabel("Tamaño de la empresa (terciles de valor de mercado)")
ax.set_title("Los coeficientes de las dummies son diferencias vs. el grupo base")
plt.tight_layout(); plt.show()