PoC: move regression tables to modelsummary (msummary_r helper + ch13 Table 13.2)#147
Open
gbekes wants to merge 1 commit into
Open
PoC: move regression tables to modelsummary (msummary_r helper + ch13 Table 13.2)#147gbekes wants to merge 1 commit into
gbekes wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Proof of concept for standardizing the repo's R regression tables on
modelsummaryinstead ofstargazer/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
msummary_r()inch00-tech-prep/da_helper_functions.R— a modelsummary-based counterpart tostargazer_r(), same interface:se = 'robust'(HC1) /'traditional'/'newey-west'(max_lag)gof =which fit stats to keep (mirrorskeep.stat); defaultn+rsqfmt/stars/output/title/...pass through tomodelsummary()multireg1, linear models 1–4) now built withmsummary_r().Why the numbers are safe
Robust SE =
vcovHC(type="HC1")— exactly whatstargazer_r()/calculate_se()already compute, and the same asfixestvcov='hetero'. I verifiedmsummary_r's HC1 SEs against the oldstargazer_rSEs:Table reproduces N = 281 and R² 0.847 → 0.898 → 0.913 → 0.919.
Two things to decide for the book build
.texrenders via modelsummary's default tinytable backend, which needs atabularraypreamble. If the book's build expectsbooktabs/longtable(as stargazer emitted), switch theoutputto the kableExtra backend. This is the one house-style call before a full migration..txtis now a grid/markdown table rather than stargazer's plain ASCII (cosmetic).Scope notes
stargazer/kable— modelsummary isn't the right tool for those.datasummary(modelsummary family), so the remaining work for a universal R move is mainly the regression tables.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 tomasterautomatically.🤖 Generated with Claude Code