Skip to content

docs: add panel data example to lag_run.Rd for Stata migrants#110

Closed
LeonidasZhak wants to merge 1 commit into
gogonzo:mainfrom
LeonidasZhak:docs/lag-run-panel-example
Closed

docs: add panel data example to lag_run.Rd for Stata migrants#110
LeonidasZhak wants to merge 1 commit into
gogonzo:mainfrom
LeonidasZhak:docs/lag-run-panel-example

Conversation

@LeonidasZhak

Copy link
Copy Markdown
Contributor

Summary

Adds a panel data example to lag_run.Rd showing the correct pattern for lagging within groups — the most common use case for Stata users migrating to R.

Stata equivalent:

xtset firm year
gen lag_sales = L.sales

runner equivalent (new example):

df <- data.frame(
  firm = rep(c(A, B), each = 3),
  year = rep(2010:2012, 2),
  sales = c(100, 110, 125, 200, 215, 230)
)
library(dplyr)
df <- df %>%
  arrange(firm, year) %>%
  group_by(firm) %>%
  mutate(lag_sales = lag_run(sales, lag = 1)) %>%
  ungroup()

Also adds irregular time index examples demonstrating the idx and nearest parameters.

Rationale

The existing lag_run.Rd had only 3 basic vector examples with no guidance on panel data usage. Panel data lagging is the single most common migration scenario from Stata, where L.var after xtset automatically handles group boundaries and time ordering.

Validation

  • tools::checkRd('man/lag_run.Rd') passes
  • All example code runs successfully
  • All 1043 tinytest tests pass
  • 3 files changed, 57 lines added

Add a grouped lag example using dplyr showing the equivalent of
Stata's 'xtset firm year; gen lag_sales = L.sales'. Also add
irregular time index examples demonstrating idx and nearest parameters.

The existing lag_run.Rd had only 3 basic vector examples with no
guidance on panel data usage, which is the most common migration
scenario from Stata.
@LeonidasZhak

Copy link
Copy Markdown
Contributor Author

Withdrawing this small automated PR while I consolidate an oversized batch of contributions and reduce maintainer review burden. Sorry for the noise, and thank you for maintaining the project.

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