Skip to content

PoC: move regression tables to modelsummary (msummary_r helper + ch13 Table 13.2)#147

Open
gbekes wants to merge 1 commit into
fix-ch13-fct-explicit-nafrom
poc-ch13-modelsummary
Open

PoC: move regression tables to modelsummary (msummary_r helper + ch13 Table 13.2)#147
gbekes wants to merge 1 commit into
fix-ch13-fct-explicit-nafrom
poc-ch13-modelsummary

Conversation

@gbekes

@gbekes gbekes commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Goal

Proof of concept for standardizing the repo's R regression tables on modelsummary instead of stargazer/stargazer_r. Scoped to one chapter (ch13) plus a reusable helper, so the numbers and ergonomics can be reviewed before a full sweep.

What's here

  1. msummary_r() in ch00-tech-prep/da_helper_functions.R — a modelsummary-based counterpart to stargazer_r(), same interface:
    • se = 'robust' (HC1) / 'traditional' / 'newey-west' (max_lag)
    • gof = which fit stats to keep (mirrors keep.stat); default n + rsq
    • fmt / stars / output / title / ... pass through to modelsummary()
  2. ch13 Table 13.2 (multireg1, linear models 1–4) now built with msummary_r().

Why the numbers are safe

Robust SE = vcovHC(type="HC1") — exactly what stargazer_r() / calculate_se() already compute, and the same as fixest vcov='hetero'. I verified msummary_r's HC1 SEs against the old stargazer_r SEs:

model 1:  3 coefs, max diff = 0.0e+00
model 2:  4 coefs, max diff = 0.0e+00
model 3:  9 coefs, max diff = 0.0e+00
model 4: 13 coefs, max diff = 0.0e+00

Table reproduces N = 281 and R² 0.847 → 0.898 → 0.913 → 0.919.

Two things to decide for the book build

  • LaTeX backend. .tex renders via modelsummary's default tinytable backend, which needs a tabularray preamble. If the book's build expects booktabs/longtable (as stargazer emitted), switch the output to the kableExtra backend. This is the one house-style call before a full migration.
  • Text output. .txt is now a grid/markdown table rather than stargazer's plain ASCII (cosmetic).

Scope notes

  • Deliberately one chapter. Non-model frames (the CV matrix and prediction summaries in ch13) are left on stargazer/kable — modelsummary isn't the right tool for those.
  • Descriptive tables across the repo already use datasummary (modelsummary family), so the remaining work for a universal R move is mainly the regression tables.
  • Stacked on fix-ch13-fct-explicit-na (PR Fix deprecated fct_explicit_na() in ch13 used-cars script #146) so ch13 runs end to end. Merge that first, or this PR will retarget to master automatically.

🤖 Generated with Claude Code

Adds msummary_r() to da_helper_functions.R as a modelsummary-based
counterpart to stargazer_r(), and converts ch13's Table 13.2
(multireg1, linear models 1-4) to use it. Proof of concept for moving
the repo's regression tables off stargazer onto modelsummary.

msummary_r() mirrors the stargazer_r() interface:
  - se = 'robust' (HC1), 'traditional', or 'newey-west' (max_lag)
  - gof = which fit stats to keep (mirrors keep.stat); default n + rsq
  - fmt/stars/output/title/... pass through to modelsummary()

Robust SEs use HC1 = vcovHC(type="HC1"), which is exactly what
stargazer_r()/calculate_se() already compute and what fixest's
vcov='hetero' uses. Verified the HC1 SEs from msummary_r match the
old stargazer_r SEs to machine precision (max abs diff 0.0e+00)
across all four ch13 models. Table reproduces N=281 and
R-squared 0.847 -> 0.898 -> 0.913 -> 0.919.

Notes for review:
  - .tex now renders via modelsummary's default tinytable backend,
    which needs a tabularray preamble; if the book build expects
    booktabs/longtable, set output via the kableExtra backend instead.
  - the .txt is now a grid/markdown table rather than stargazer's
    plain ASCII (cosmetic).
  - scope is deliberately one chapter; non-model frames (CV matrix,
    prediction summary) are left on stargazer/kable on purpose.

Stacked on the fct_explicit_na fix branch so ch13 runs end to end.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant