Learn R Programming

PanelMatch (version 3.0.0)

Matching Methods for Causal Inference with Time-Series Cross-Sectional Data

Description

Implements a set of methodological tools that enable researchers to apply matching methods to time-series cross-sectional data. Imai, Kim, and Wang (2023) proposes a nonparametric generalization of the difference-in-differences estimator, which does not rely on the linearity assumption as often done in practice. Researchers first select a method of matching each treated observation for a given unit in a particular time period with control observations from other units in the same time period that have a similar treatment and covariate history. These methods include standard matching methods based on propensity score and Mahalanobis distance, as well as weighting methods. Once matching and refinement is done, treatment effects can be estimated with standard errors. The package also offers diagnostics for researchers to assess the quality of their results.

Copy Link

Version

Install

install.packages('PanelMatch')

Monthly Downloads

680

Version

3.0.0

License

GPL (>= 3)

Maintainer

In Kim

Last Published

March 3rd, 2025

Functions in PanelMatch (3.0.0)

distances

Get distances See distances.matched.set method
enforce_lead_restrictions

enforce_lead_restrictions check treatment and control units for treatment reversion in the lead window. Treated units must stay treated and control units must stay in control (according to the specified qoi)
extract.PanelMatch

Extract matched.set objects from PanelMatch results
distances.matched.set

Extract the distances of matched control units
dem

Country-year level democratization data
check_time_data

check_time_data
clean_leads

clean_leads Function to check the lead windows in treated and control units for missing outcome data. If data is missing, remove those units from matched sets.
findBinaryTreated

findBinaryTreated
get_unrefined_balance.PanelBalance

Extract unrefined covariate balance results, if they exist
get_set_treatment_effects

Calculate matched set level treatment effects
get.matchedsets

get.matchedsets
getDits

getDits returns a vector of Dit values, as defined in the paper. They should be in the same order as the data frame containing the original problem data.
get_covariate_balance

Calculate covariate balance measures for refined and unrefined matched sets
getWits

getWits returns a vector of Wits, as defined in the paper (equation 25 or equation 23). They should be in the same order as the data frame containing the original problem data. The pts, pcs, and getWits functions act for a specific lead. So, for instance if our lead window is 0,1,2,3,4, these function must be called for each of those -- so for 0, then for 1, etc.
handle_bootstrap_placebo_parallel

handle_bootstrap_placebo_parallel
handle_conditional_se

handle_conditional_se Calculates conditional standard errors analytically, as defined in Imai et al. (2023). See PanelEstimate() for a more complete description of the standard error types.
handle_mahalanobis_calculations

handle_mahalanobis_calculations Returns a matched.set object with weights for control units, along with some other metadata
merge_formula

merge_formula
matched_set

A constructor for the matched.set class.
handle_missing_data

handle_missing_data
parse_and_prep

parse_and_prep
extract

Extract matched.set objects from PanelMatch results
handle_bootstrap_placebo

handle_bootstrap_placebo
find_ps

find_ps
pcs

Prepare Control Units pcs and pts create data frames with the time/id combinations--that need to be found so that they can be easily looked up in the data frame via a hash table. The data frame also contains information about the weight of that unit at particular times, so we use the hash table to look up where to put this data so that we can easily assign the appropriate weights in the original data frame containing the problem data. pcs does this for all control units in a matched set. pts does this for all treated units.
extract_differences

extract_differences This function calculates the differences from t-1 to 1 for treated and control units in the treatment variable. While functionality is somewhat trivial for current implementation of package, it will be needed for continuous treatment version of the package.
lwd_units

lwd_units helper function that actually subsets sets down to contain units with complete data
handle_ps_match

handle_ps_match Returns a matched.set object with weights for control units, along with some other metadata
handle_moderating_variable

handle_moderating_variable
handle_bootstrap_parallel

handle_bootstrap_parallel
handle_ps_weighted

handle_ps_weighted
get_unrefined_balance

Extract just the unrefined covariate balance results, if they exist
plot.PanelData

Create basic plots of PanelData objects
plot_matched_set

Helper function for plotting the distribution of matched set sizes
handle_bootstrap

handle_bootstrap
handle_unconditional_se

handle_conditional_se Calculates conditional standard errors analytically, as defined in Imai et al. (2023). See PanelEstimate() for a more complete description of the standard error types.
plot.PanelBalance

Plot covariate balance results Create figures displaying covariate balance results for one or more PanelMatch configurations. Users can customize these visualizations.
placebo_test

Conduct a placebo test
plot.PanelEstimate

Plot point estimates and standard errors from a PanelEstimate calculation.
summary.PanelData

Summarize the number of unique units and time periods in a PanelData object
perform_refinement

perform_refinement Performs refinement of matched sets, ultimately returning sets of treated observations and controls with weights. This function mostly acts as an intermediary between PanelMatch and lower level functions that do the dirty work of refinement. The function takes a lot of the same arguments as PanelMatch()
prepare_data

prepare_data The calculation of point estimates and standard errors first requires the calculation of a variety of different weights, parameters, and indicator variables. This function prepares the data within PanelEstimate() such that the estimates can be calculated easily. In practical terms, the function calls the lower level helpers to calculate W_its and D_its as described in Imai et al. (2023) and merges those results together with the original data to facilitate calculations.
summary.PanelBalance

Summarize covariate balance over time
plot.PanelMatch

Plot the distribution of the sizes of matched sets.
summary.PanelEstimate

Get summaries of PanelEstimate objects and calculations
print.PanelEstimate

Print point estimates and standard errors
print.PanelMatch

Print PanelMatch objects.
plot.matched.set

Plot the distribution of control unit weights
weights

Get weights of matched control units See weights.matched.set method
print.matched.set

Print matched.set objects.
lwd_refinement

lwd_refinement master function that performs refinement with listwise deletion = TRUE
identifyDirectionalChanges

identifyDirectionalChanges Identifies changes in treatment variable for treated and control observations
weights.matched.set

Extract the weights of matched control units
summary.matched.set

Summarize information about a matched.set object and the matched sets contained within them.
summary.PanelMatch

Summarize information about a PanelMatch object and the matched sets contained within them.
set_lwd_refinement

set_lwd_refinement Performs the set-level operations for refinement with listwise deletion. See documentation for lwd_refinement for descriptions of most parameters.
print.PanelBalance

Print basic information about PanelBalance objects
[.matched.set

Subset matched.set object
[.PanelBalance

Subset PanelBalance objects
print.PanelData

Print PanelData objects and basic metadata
perunitSum

perunitSum This is a low level function that is used to calculate a value associated with each unit. This value is a weighted summation of the dependent variable, based on the Wit values discussed in Imai et al. (2023)
perunitSum_Dit

perunitSum_Dit Similar to perunitSum, this is a low level helper function for calculating specific values defined in Imai et al. (2023). This focuses on Dit rather than Wit
build_ps_data

build_ps_data
PanelEstimate

Estimate a causal quantity of interest
PanelData

Pre-process and balance panel data
PanelMatch

Create and refine sets of matched treated and control observations
DisplayTreatment

Visualize the treatment distribution across units and time in a panel data set
expand_treated_ts

expand_treated_ts Builds a list that contains all times in a lag window that correspond to a particular treated unit. This is structured as a list of vectors. Each vector is lag + 1 units long. The overall list will be the same length as the number of matched sets
calculate_point_estimates

calculate_point_estimates Helper function that calculates the point estimates for the specified QOI
calculate_placebo_estimates

calculate_placebo_estimates
PanelMatch-package

Matching Methods for Causal Inference with Time-Series Cross-Sectional Data
calculate_estimates

calculate_estimates
build_maha_mats

build_maha_mats Builds the matrices that we will then use to calculate the mahalanobis distances for each matched set
equality_four

equality_four Small helper function implementing estimation function from Imai, Kim, and Wang (2023)
equality_four_placebo

equality_four_placebo