Skip to content
svgunit-effects

Unit effects

How far apart are the units once the regressors are held fixed, and how precisely is each one known?

Demo data · seed 20261101 · 14 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read each row as one unit's level once the regressors are held fixed.
  2. Rows are sorted, with the mean effect marked.
  3. Compare intervals: which units sit well apart from the mean?

Watch out

  • With few observations per unit these estimates are noisy, and the extremes are the likeliest to be exaggerated.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • α̂ᵢ = ȳᵢ − x̄ᵢ'b̂, with SE √(s²/Tᵢ + x̄ᵢ'V̂x̄ᵢ) from the classical covariance, as plm's fixef.
  • With short panels each α̂ᵢ rests on few rows and is noisy (the incidental parameters problem): read the spread, not any one unit's rank.
# Unit effects — Codesplash Chart Lab (recipe "unit-effects")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("unit-effects-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["region"] = pd.Categorical(df["region"].astype("string"), categories=["region 1", "region 2", "region 3", "region 4", "region 5", "region 6", "region 7", "region 8", "region 9", "region 10", "region 11", "region 12", "region 13", "region 14"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
LABEL = "region"
EFFECT = "fixed effect"
LOW, HIGH = "lower", "upper"
REFERENCE = None
d = df.dropna(subset=[EFFECT]).sort_values(EFFECT, ascending=False, kind="mergesort")  # largest first
reference = REFERENCE if REFERENCE else d[EFFECT].mean()
pos = np.arange(len(d))
fig, ax = plt.subplots(figsize=(7, max(3, 0.28 * len(d))))
if LOW and HIGH:
    ax.hlines(pos, d[LOW], d[HIGH], color=PALETTE[0], alpha=0.55)
ax.scatter(d[EFFECT], pos, s=28, color=PALETTE[0], zorder=3)
ax.axvline(reference, color=REF, linestyle="--", label=f"mean {reference:.3g}")
ax.set_yticks(pos, d[LABEL].astype(str))
ax.invert_yaxis()
ax.set_xlabel(EFFECT)
ax.set_title("Unit effects")
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads unit-effects-demo.csv · app theme from the optional codesplash helper