Skip to content

docs: add grouped rolling mean example to runner.Rd#111

Merged
gogonzo merged 1 commit into
gogonzo:mainfrom
LeonidasZhak:docs/runner-grouped-example
Jun 6, 2026
Merged

docs: add grouped rolling mean example to runner.Rd#111
gogonzo merged 1 commit into
gogonzo:mainfrom
LeonidasZhak:docs/runner-grouped-example

Conversation

@LeonidasZhak

Copy link
Copy Markdown
Contributor

Summary

Added a panel data example to the runner.grouped_df method in runner.Rd showing how to compute rolling means within groups using dplyr.

Stata equivalent:

bysort firm (year): rolling mean_sales = r(mean), window(3) clear: summarize sales

runner equivalent (new example):

library(dplyr)
df <- data.frame(
  firm = rep(c(A, B), each = 5),
  year = rep(2010:2014, 2),
  sales = c(100, 110, 125, 130, 145, 200, 215, 230, 250, 270)
)
df %>%
  arrange(firm, year) %>%
  group_by(firm) %>%
  mutate(roll_mean = runner(sales, f = mean, k = 3)) %>%
  ungroup()

Rationale

The runner.grouped_df method had no examples. Rolling operations within groups (panel data) is the single most common migration scenario from Stata, where bysort + rolling automatically handles group boundaries. The runner() function with dplyr's group_by provides the equivalent functionality.

Validation

  • tools::checkRd('man/runner.Rd') passes (no output = no errors)
  • All 1043 tinytest tests pass
  • 2 files changed, 31 lines added

Add a panel data example to the runner.grouped_df method showing
how to compute rolling means within groups using dplyr. This is the
most common Stata migration pattern (bysort + rolling).

@gogonzo gogonzo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@gogonzo gogonzo merged commit 4697b70 into gogonzo:main Jun 6, 2026
3 checks passed
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.

2 participants