View source: R/balance_panel.R
| balance_panel | R Documentation |
This function makes implicit missing values explicit by adding rows with NA values for entity-wave combinations that are not present in the data.
balance_panel(data, ...)
data |
A |
... |
Optional fill values specified as |
Panel data often has implicit gaps where certain entities are not observed in certain waves. This function makes these gaps explicit by adding rows filled with NA values (or custom values if specified).
This is the inverse operation of removing incomplete cases. It can be useful for:
Visualizing the pattern of missing data
Using functions that require complete (balanced) panels
Explicit handling of missing waves in models
A panel_data frame with all entity-wave combinations present.
has_gaps(), scan_gaps(), complete_data()
data("WageData")
wages <- panel_data(WageData, id = id, wave = t)
# Create data with gaps
wages_gaps <- wages[!(wages$t == 3 & wages$id == wages$id[1]), ]
nrow(wages_gaps) # Missing one row
# Balance the panel (add NA row)
wages_balanced <- balance_panel(wages_gaps)
nrow(wages_balanced) # Back to full size
# Balance with custom fill values
wages_balanced <- balance_panel(wages_gaps, wks = 0, union = 0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.