docs: add ordering note to shift.Rd, character example to nafill.Rd#7774
Open
LeonidasZhak wants to merge 2 commits into
Open
docs: add ordering note to shift.Rd, character example to nafill.Rd#7774LeonidasZhak wants to merge 2 commits into
LeonidasZhak wants to merge 2 commits into
Conversation
- shift.Rd: Add note explaining that shift operates on row position, not time order. Critical gotcha for Stata migrants who expect L.var behavior (automatic time-ordering after xtset). Add explicit example showing the WRONG vs RIGHT approach with unsorted data. - nafill.Rd: Add character vector example (locf + const fill). Character was listed as supported type but had no example.
Add a panel data example showing the correct pattern for lagging within groups respecting time order. This is the most common use case for Stata users migrating to R, where they would use: xtset firm year gen lag_sales = L.sales The example demonstrates the equivalent data.table pattern: DT[order(firm, year), lag_sales := shift(sales, 1L), by = firm] This complements the existing WRONG/RIGHT single-entity example by showing the multi-entity panel data case with by=.
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.
Changes
shift.Rd — ordering note for time-series/panel users
Added a paragraph in the Details section explaining that
shiftoperates on row position, not time order. This is a critical gotcha for users migrating from Stata, whereL.var(afterxtset) automatically respects time order within panels.Added an explicit example showing the WRONG (unsorted) vs RIGHT (sorted) approach:
nafill.Rd — character example
Added a character vector example demonstrating
locfandconstfill types. Character was listed as a supported type in the Details section but had no example (only numeric and factor examples existed).Validation
tools::checkRd()passes on both modified Rd filesStata connection
The
shiftordering note directly addresses the most common Stata-to-R migration pitfall with lag/lead operations: Stata'sxtset+L.varhandles panel ordering automatically, while data.table'sshiftrequires explicitDT[order(timevar), ...]