lag_by_group: Generate lags in grouped data

View source: R/helpers-difference-in-differences.R

lag_by_groupR Documentation

Generate lags in grouped data

Description

See https://book.declaredesign.org/observational-causal.html#difference-in-differences

Usage

lag_by_group(x, groups, n = 1, order_by, default = NA)

Arguments

x

Vector of values

groups

Grouping variable

n

Positive integer of length 1, giving the number of positions to lead or lag by

order_by

Ordering variable withing group (e.g., time)

default

Value used for non-existent rows. Defaults to NA.

Value

vector of lagged values


rdss documentation built on Oct. 11, 2024, 1:08 a.m.