join_lagged_col: Merge a Lagged Column into a Single Column

View source: R/data_preparation.R

join_lagged_colR Documentation

Merge a Lagged Column into a Single Column

Description

Turns data in which a quantity is stored twice, once in levels and once lagged in time, into the single-column form the rest of the package expects.

Usage

join_lagged_col(
  df,
  col,
  col_lagged,
  timestamp_col,
  entity_col,
  timestep = NULL
)

Arguments

df

Data frame with a column holding lagged values

col

Column with quantity not lagged

col_lagged

Column with the same quantity as col, but the values are lagged in time

timestamp_col

Column with timestamps (e.g. years)

entity_col

Column with entities (e.g. countries)

timestep

Difference between timestamps (e.g. 10)

Details

Some panel data sets ship the dependent variable in two columns, the value at time t and the value at time t-1, held side by side in the same row. The functions in badp build the lags themselves from the panel structure, so they need the quantity only once. This function performs that reduction: the two columns are merged into one and the rows are re-indexed so that no observation is lost.

The step is conditional. Data that already store the quantity once, as economic_growth and migration_data do, pass straight to feature_standardization and do not need this function at all.

Value

A data frame with two columns merged, i.e. just one column with the desired quantity is left.

See Also

feature_standardization

Examples

df <- data.frame(
  year = c(2000, 2001, 2002, 2003, 2004),
  country = c("A", "A", "B", "B", "C"),
  gdp = c(1, 2, 3, 4, 5),
  gdp_lagged = c(NA, 1, 2, 3, 4)
)

join_lagged_col(df, gdp, gdp_lagged, year, country, 1)


badp documentation built on Sept. 15, 2026, 1:08 a.m.