Skip to content

docs: add panel data example to frolladapt.Rd#7776

Open
LeonidasZhak wants to merge 1 commit into
Rdatatable:masterfrom
LeonidasZhak:docs/frolladapt-panel-example
Open

docs: add panel data example to frolladapt.Rd#7776
LeonidasZhak wants to merge 1 commit into
Rdatatable:masterfrom
LeonidasZhak:docs/frolladapt-panel-example

Conversation

@LeonidasZhak
Copy link
Copy Markdown

Summary

Adds a panel data example to showing how to compute rolling means within groups using + with by=. This is the data.table equivalent of Stata's rangestat with by() for time-aware rolling windows.

Stata equivalent:

rangestat (mean) rollmean3 = sales, int(date -2 0) by(firm)

data.table equivalent (new example):

dt = data.table(
  firm = rep(c("A", "B"), each = 4),
  date = as.Date(c("2020-01-01", "2020-01-02", "2020-01-05", "2020-01-06",
                    "2020-01-01", "2020-01-03", "2020-01-04", "2020-01-07")),
  sales = c(10, 12, 15, 13, 20, 22, 18, 25)
)
setorder(dt, firm, date)
dt[, rollmean3 := frollmean(sales, frolladapt(date, n=3L, partial=TRUE),
                            adaptive=TRUE), by = firm]

Rationale

The frolladapt.Rd page had only single-entity examples despite frolladapt being the key function for time-aware rolling windows in data.table. Panel data rolling operations (e.g., rangestat ... by(firm) in Stata) are the most common migration pattern where users need rolling calculations within groups respecting irregular time gaps.

The existing froll.Rd note (line 72) warns that rolling functions operate on physical order, but frolladapt.Rd didn't show the grouped usage pattern that makes this practical for panel data.

Validation

  • tools::checkRd('man/frolladapt.Rd') passes (no output = no errors)
  • All example code runs successfully in R
  • 1 file changed, 13 lines added

Files Changed

File Lines Added Lines Removed Type
man/frolladapt.Rd 13 0 Documentation (Rd)

Duplicate Check

Add a grouped rolling mean example showing frolladapt + frollmean with
by= for panel data. This is the data.table equivalent of Stata's
rangestat (mean) ..., int(date -2 0) by(firm) for time-aware rolling
windows within groups respecting irregular date gaps.
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