パネルデータ回帰の表
プールした OLS、ランダム効果、国の固定効果、二元固定効果を並べ、クラスター頑健標準誤差、固定効果の有無、ハウスマン検定を示します。

国・年データを使う応用経済学の定番の表です。同じ回帰を 4 通りに推定します。パネル構造を無視するプールした OLS、各国の水準をランダムな誤差として扱うランダム効果、各国の内部の変動だけを使う国の固定効果、そしてある年にすべての国に共通するショックも吸収する二元固定効果です。標準誤差は国でクラスター化し、表の末尾には各列が含む固定効果、使った観測数と国の数、群内 R² と全体 R² を示します。
列を比べることが要点です。ここでは制度の質が、別の恒久的な理由で FDI をより多く引きつける国で高いため、プールした OLS とランダム効果の係数は上方に偏ります。固定効果の列はその偏りを取り除きます。頑健なハウスマン検定はランダム効果を棄却し固定効果を支持します。これは Mundlak 版で、各説明変数の国平均をランダム効果モデルに加え、クラスター頑健共分散で同時に検定します(古典的なハウスマンの式は負になることがあり、クラスター化を無視します)。プーリングの F 検定はプールしたモデルを棄却します。fixest や Stata と同様に、固定効果が定数項を吸収する場合は定数項を示しません。
設定は Stojkov & Warin (2018, Journal of East-West Business) による、移行経済における EU 加盟と海外直接投資の研究です。データは説明のためのシミュレーションであり、論文のデータや結果ではありません。28 の経済を 18 年間観測し、FDI 流入は GDP 比(%)です。モデルは linearmodels(PooledOLS、RandomEffects、EntityEffects と TimeEffects を含む PanelOLS を cov_type="clustered" で推定し、Mundlak 検定には wald_test())で、表はこのファミリーの他の表と同じ学術誌の体裁で Great Tables を使って組みます。
コードおよび図中のテキストは英語です。
import numpy as np
import pandas as pd
from great_tables import GT, html, loc, style
from linearmodels.panel import PanelOLS, PooledOLS, RandomEffects
# Simulated data, set in the context of Stojkov & Warin (2018) [stojkov2018fdi]
# Data: 28 transition economies × 18 years; a permanent country "attractiveness" raises both
# FDI and institutional quality, so pooled estimates of the institutions effect are biased
rng = np.random.default_rng(2018)
n_c, n_t = 28, 18
country = np.repeat([f"C{i:02d}" for i in range(n_c)], n_t)
year = np.tile(np.arange(2000, 2000 + n_t), n_c)
appeal = np.repeat(rng.normal(0, 1.5, n_c), n_t) # unobserved country effect
shock = np.tile(rng.normal(0, 0.8, n_t) + np.linspace(-1, 1, n_t), n_c) # common year shocks
entry = np.repeat(rng.integers(2004, 2025, n_c), n_t) # some never join in-sample
df = pd.DataFrame({
"country": country, "year": year,
"eu_member": (year >= entry).astype(int),
"institutions": 0.6 * appeal + 0.04 * (year - 2000) + rng.normal(0, 0.6, n_c * n_t),
"openness": np.repeat(rng.normal(0, 1, n_c), n_t) + rng.normal(0, 0.5, n_c * n_t),
"log_gdp": np.repeat(rng.normal(3, 0.8, n_c), n_t) + 0.03 * (year - 2000) + rng.normal(0, 0.1, n_c * n_t),
"ulc": rng.normal(0, 1, n_c * n_t),
})
df["fdi"] = (2 + 0.5 * df.institutions + 0.6 * df.openness + 1.2 * df.log_gdp - 0.4 * df.ulc
+ 1.5 * df.eu_member + 1.8 * appeal + shock + rng.normal(0, 1.2, n_c * n_t))
panel = df.set_index(["country", "year"])
labels = {"institutions": "Institutional quality", "openness": "Trade openness",
"log_gdp": "Market size (log GDP)", "ulc": "Unit labour cost", "eu_member": "EU member (0/1)",
"Intercept": "Constant"}
rhs = " + ".join(list(labels)[:-1])
specs = {
"Pooled OLS": PooledOLS.from_formula(f"fdi ~ 1 + {rhs}", panel),
"Random effects": RandomEffects.from_formula(f"fdi ~ 1 + {rhs}", panel),
"Country FE": PanelOLS.from_formula(f"fdi ~ 1 + {rhs} + EntityEffects", panel),
"Two-way FE": PanelOLS.from_formula(f"fdi ~ 1 + {rhs} + EntityEffects + TimeEffects", panel),
}
fits = {k: m.fit(cov_type="clustered", cluster_entity=True) for k, m in specs.items()}
cols = [f"({k + 1})" for k in range(len(fits))]
# Robust Hausman test (Mundlak): add each regressor's country mean to the RE model and
# test that the means are jointly zero with the clustered covariance — FE vs. RE
xs = list(labels)[:-1]
means = panel[xs].groupby(level="country").transform("mean").add_prefix("mean_")
mundlak = RandomEffects.from_formula(f"fdi ~ 1 + {rhs} + " + " + ".join(means.columns),
panel.join(means)).fit(cov_type="clustered", cluster_entity=True)
hausman = mundlak.wald_test(formula=[f"{m} = 0" for m in means.columns])
f_pool = fits["Country FE"].f_pooled
fe_cols = {"(3)", "(4)"} # the constant is not reported with fixed effects
def stars(p):
return "***" if p < .01 else "**" if p < .05 else "*" if p < .1 else ""
def num(x, d=3): # typographic minus sign, as in print
return f"{x:.{d}f}".replace("-", "−")
def pval(p):
return "< 0.001" if p < .001 else f"{p:.3f}"
# Body: coefficient row and standard-error row per term, as in stargazer
rows = []
for term, name in labels.items():
keep = {c: term in r.params and not (term == "Intercept" and c in fe_cols)
for c, r in zip(cols, fits.values())}
coef = {c: num(r.params[term]) + stars(r.pvalues[term]) if keep[c] else ""
for c, r in zip(cols, fits.values())}
se = {c: f"({num(r.std_errors[term])})" if keep[c] else "" for c, r in zip(cols, fits.values())}
rows += [{"term": name, **coef}, {"term": "", **se}]
n_body = len(rows)
coef_rows, se_rows = list(range(0, n_body, 2)), list(range(1, n_body, 2))
# Foot: fixed effects, sample, fit and specification tests
yes_no = lambda flags: dict(zip(cols, ["Yes" if f else "No" for f in flags]))
rows += [
{"term": "Country fixed effects", **yes_no([0, 0, 1, 1])},
{"term": "Year fixed effects", **yes_no([0, 0, 0, 1])},
{"term": "Observations", **{c: f"{r.nobs:,}" for c, r in zip(cols, fits.values())}},
{"term": "Countries", **{c: f"{r.entity_info['total']:.0f}" for c, r in zip(cols, fits.values())}},
{"term": "R² (within)", **{c: num(r.rsquared_within) for c, r in zip(cols, fits.values())}},
{"term": "R² (overall)", **{c: num(r.rsquared_overall) for c, r in zip(cols, fits.values())}},
{"term": "F-test, no country effects", **dict(zip(cols, ["", "", f"{f_pool.stat:.1f} (p {pval(f_pool.pval)})", ""]))},
{"term": "Robust Hausman test, FE vs. RE",
**dict(zip(cols, ["", f"χ²({hausman.df}) = {hausman.stat:.1f} (p {pval(hausman.pval)})", "", ""]))},
]
tab = pd.DataFrame(rows)
n_foot_first = n_body # rule above the fixed-effect indicators
n_stats_first = n_body + 2 # thin rule above the sample statistics
table = (
GT(tab, rowname_col="term")
.tab_header(title="TABLE IV", subtitle="Institutions, EU membership and FDI: panel estimates")
.tab_spanner(label="Dependent variable: FDI inflows (% of GDP)", columns=cols, id="dep")
.cols_label(**{c: html(f"{c}<br>{name}") for c, name in zip(cols, fits)})
.cols_align("center", columns=cols)
.cols_width({"term": "210px", **{c: "185px" for c in cols}})
.tab_source_note(f"Notes: n = {n_c} economies × {n_t} years (simulated). Standard errors clustered by "
"country in parentheses. *p < 0.1; **p < 0.05; ***p < 0.01.")
.tab_source_note("Robust Hausman test: Mundlak regression, Wald test that the country means of the "
"regressors are zero. F-test of poolability for (3).")
# Same journal look as the other tables: serif type, small-caps title, horizontal rules only
.opt_table_font(font=["Latin Modern Roman", "Times New Roman", "Georgia", "serif"])
.tab_options(
table_width="960px", table_font_size="15px", table_font_color="#000",
heading_title_font_size="15px", heading_subtitle_font_size="15px", heading_padding="1px",
table_border_top_style="hidden", table_border_bottom_style="hidden",
heading_border_bottom_style="none",
column_labels_border_top_style="solid", column_labels_border_top_width="1.5px", # top rule
column_labels_border_top_color="#000",
column_labels_border_bottom_style="solid", column_labels_border_bottom_width="1px",
column_labels_border_bottom_color="#000",
table_body_border_top_style="solid", table_body_border_top_width="1px",
table_body_border_top_color="#000",
table_body_hlines_style="none", stub_border_style="none",
table_body_border_bottom_style="solid", table_body_border_bottom_width="1.5px",
table_body_border_bottom_color="#000",
data_row_padding="4px", source_notes_font_size="13px", source_notes_padding="1px",
)
.tab_style(style.css("font-variant: small-caps; padding-bottom: 8px;"), loc.subtitle())
.tab_style(style.text(style="italic"), loc.spanner_labels(ids=["dep"]))
# standard error tucked under its coefficient
.tab_style(style.css("padding-bottom: 0;"), [loc.body(rows=coef_rows), loc.stub(rows=coef_rows)])
.tab_style(style.css("padding-top: 0;"), [loc.body(rows=se_rows), loc.stub(rows=se_rows)])
# thin rules: above the fixed-effect indicators and above the sample statistics
.tab_style(style.borders(sides="top", style="solid", weight="1px", color="#000"),
[loc.body(rows=[n_foot_first, n_stats_first]), loc.stub(rows=[n_foot_first, n_stats_first])])
)
table.show()
図にはオプションの PyStatlas スタイル を使用しています。同じ見た目にするには plt.style.use("pystatlas.mplstyle") を追加してください。
データの出典
- Simulated data. Simulated data with a fixed random seed, created for this example.
No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work. - Stojkov & Warin (2018), EU membership and FDI. Stojkov, A., & Warin, T. (2018). EU membership and FDI: Is there an endogenous credibility effect? Journal of East-West Business, 24, 144–169. https://doi.org/10.1080/10669868.2018.1431579
The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not the paper's data or results.
これらの例は統計手法を説明するためのものです。項目に別の記載がない限り数値はシミュレーションであり、図のタイトルはこのシミュレーションデータで図が示す内容を述べたものです。引用した論文の知見でも、実質的な問いに対する著者の立場でもありません。結果、背景、データについては、ここに挙げた論文を参照してください。
引用方法
PyStatlas は Thierry Warin が作成・運営しています。研究や業務に役立った場合は、ぜひ引用してください。
Warin, T. (2026). Panel data regression table. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/academic-tables/panel-regression/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
version = {1.1.0},
howpublished = {\url{https://warin.ca/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}学術論文の表のその他のグラフ
stargazer 形式の回帰表
入れ子になった 3 つの OLS モデルを横に並べ、係数の下に標準誤差、末尾に適合度の統計量を置いて、学術誌の表のように組みます。
stargazer::stargazer(type = "html")記述統計の表
実証論文の「表 1」。変数ごとの N、平均、標準偏差、最小値、中央値、最大値をパネルに分けて示し、群ごとの平均とその差の検定を添えます。
modelsummary::datasummary_balance()機械学習モデルの比較表
繰り返し交差検証で 5 つの分類器を比較します。識別、分類、較正の指標を平均(標準偏差)で示し、最良値を太字にし、AUC の差を補正済み検定で調べます。
tidymodels::workflow_map() + collect_metrics()