make_balanced_panel: Balance a Panel Data Set

View source: R/BMisc.R

make_balanced_panelR Documentation

Balance a Panel Data Set

Description

This function drops observations from data.frame that are not part of balanced panel data set. 'data' is copied before dropping any rows, so the object passed in is left unmodified; see set_balanced_panel for an in-place alternative that avoids copying large inputs.

Usage

make_balanced_panel(data, idname, tname)

Arguments

data

data.frame (or data.table) used in function

idname

unique id

tname

time period name

Value

a balanced panel, with the same class ('data.frame' or 'data.table') as 'data'

Examples

id <- rep(seq(1, 100), each = 2) # individual ids for setting up a two period panel
t <- rep(seq(1, 2), 100) # time periods
y <- rnorm(200) # outcomes
dta <- data.frame(id = id, t = t, y = y) # make into data frame
dta <- dta[-7, ] # drop the 7th row from the dataset (which creates an unbalanced panel)
dta <- make_balanced_panel(dta, idname = "id", tname = "t")


BMisc documentation built on Aug. 22, 2026, 5:07 p.m.