Title: | 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 (2018) <http://web.mit.edu/insong/www/pdf/tscs.pdf> 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 is done, both short-term and long-term average treatment effects for the treated can be estimated with standard errors. The package also offers a visualization technique that allows researchers to assess the quality of matches by examining the resulting covariate balance. |
Authors: | In Song Kim [aut, cre], Adam Rauh [aut], Erik Wang [aut], Kosuke Imai [aut] |
Maintainer: | In Song Kim <[email protected]> |
License: | GPL(>= 3) |
Version: | 1.0.1 |
Built: | 2024-11-08 03:59:10 UTC |
Source: | https://github.com/insongkim/panelmatch |
Implements a set of methodological tools that enable researchers to apply matching methods to time-series cross-sectional data. Imai, Kim, and Wang (2018) 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 is done, both short-term and long-term average treatment effects for the treated can be estimated with standard errors. The package also offers a visualization technique that allows researchers to assess the quality of matches by examining the resulting covariate balance.
Package: | PanelMatch |
Type: | Package |
Version: | 0.0.1- |
Date: | 2018-03-01 |
License: | GPL (>= 3) |
In Song Kim <[email protected]>, Erik Wang <[email protected]>, Adam Rauh <[email protected]>, and Kosuke Imai <[email protected]>
Maintainer: In Song Kim [email protected]
Imai, Kosuke, In Song Kim and Erik Wang. (2018)
Visualizing the standardized mean differences for covariates via a scatter plot.
balance_scatter( non_refined_set, refined_list, xlim = c(0, 0.8), ylim = c(0, 0.8), main = "Standardized Mean Difference of Covariates", pchs = c(2, 3), covariates, data, x.axis.label = "Before refinement", y.axis.label = "After refinement", ... )
balance_scatter( non_refined_set, refined_list, xlim = c(0, 0.8), ylim = c(0, 0.8), main = "Standardized Mean Difference of Covariates", pchs = c(2, 3), covariates, data, x.axis.label = "Before refinement", y.axis.label = "After refinement", ... )
non_refined_set |
a |
refined_list |
a list of one or two |
xlim |
xlim of the scatter plot. This is the same as the |
ylim |
ylim of the scatter plot. This is the same as the |
main |
title of the scatter plot. This is the same as the |
pchs |
one or two pch indicators for the symbols on the scatter plot. See |
covariates |
variables for which balance is displayed |
data |
the same time series cross sectional data set used to create the matched sets. |
x.axis.label |
x axis label |
y.axis.label |
y axis label |
... |
optional arguments to be passed to |
balance_scatter
visualizes the standardized mean differences for each covariate.
Although users can use the scatter plot in a variety of ways, it is recommended that
the x-axis refers to balance for covariates before refinement, and y-axis
refers to balance after refinement. Users can utilize parameters powered by plot
in base R to further customize the figure.
In Song Kim <[email protected]>, Erik Wang <[email protected]>, Adam Rauh <[email protected]>, and Kosuke Imai <[email protected]>
# get a matched set without refinement sets0 <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "none", data = dem, match.missing = FALSE, covs.formula = ~ I(lag(y, 1:4)) + I(lag(tradewb, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # get a matched set with refinement using CBPS.match, setting the # size of matched set to 5 sets1 <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = FALSE, covs.formula = ~ I(lag(y, 1:4)) + I(lag(tradewb, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # get another matched set with refinement using CBPS.weight sets2 <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "ps.weight", data = dem, match.missing = FALSE, covs.formula = ~ I(lag(y, 1:4)) + I(lag(tradewb, 1:4)), size.match = 10, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # use the function to produce the scatter plot balance_scatter(non_refined_set = sets0$att, refined_list = list(sets1$att, sets2$att), data = dem, covariates = c("y", "tradewb")) # add legend legend(x = 0, y = 0.8, legend = c("mahalanobis", "PS weighting"), y.intersp = 0.65, x.intersp = 0.3, xjust = 0, pch = c(1, 3), pt.cex = 1, bty = "n", ncol = 1, cex = 1, bg = "white")
# get a matched set without refinement sets0 <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "none", data = dem, match.missing = FALSE, covs.formula = ~ I(lag(y, 1:4)) + I(lag(tradewb, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # get a matched set with refinement using CBPS.match, setting the # size of matched set to 5 sets1 <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = FALSE, covs.formula = ~ I(lag(y, 1:4)) + I(lag(tradewb, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # get another matched set with refinement using CBPS.weight sets2 <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "ps.weight", data = dem, match.missing = FALSE, covs.formula = ~ I(lag(y, 1:4)) + I(lag(tradewb, 1:4)), size.match = 10, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # use the function to produce the scatter plot balance_scatter(non_refined_set = sets0$att, refined_list = list(sets1$att, sets2$att), data = dem, covariates = c("y", "tradewb")) # add legend legend(x = 0, y = 0.8, legend = c("mahalanobis", "PS weighting"), y.intersp = 0.65, x.intersp = 0.3, xjust = 0, pch = c(1, 3), pt.cex = 1, bty = "n", ncol = 1, cex = 1, bg = "white")
A dataset containing the democracy indicator for 184 countries from 1960 to 2010
A dataframe containing 9384 rows and 3 variables
wbcode2. World Bank country ID
year. year (1960–2010)
dem. binary indicator of democracy as defined in Acemoglu et al.
y log of GDP per capita in 2000 constant dollars (multiplied by 100)
tradewb Exports plus Imports as a share of GDP from World Bank
Acemoglu, Daron, Suresh Naidu, Pascual Restrepo, and James A Robinson. “Democracy does cause growth.” Journal of Political Economy.
DisplayTreatment
visualizes the treatment distribution
across units and time in a panel dataset
DisplayTreatment( unit.id, time.id, treatment, data, color.of.treated = "red", color.of.untreated = "blue", title = "Treatment Distribution \n Across Units and Time", xlab = "Time", ylab = "Unit", x.size = 10, y.size = 5, legend.position = "none", x.angle = 45, y.angle = NULL, legend.labels = c("not treated", "treated"), decreasing = FALSE, matched.set = NULL, show.set.only = FALSE, hide.x.axis.label = FALSE, hide.y.axis.label = FALSE, gradient.weights = FALSE, dense.plot = FALSE )
DisplayTreatment( unit.id, time.id, treatment, data, color.of.treated = "red", color.of.untreated = "blue", title = "Treatment Distribution \n Across Units and Time", xlab = "Time", ylab = "Unit", x.size = 10, y.size = 5, legend.position = "none", x.angle = 45, y.angle = NULL, legend.labels = c("not treated", "treated"), decreasing = FALSE, matched.set = NULL, show.set.only = FALSE, hide.x.axis.label = FALSE, hide.y.axis.label = FALSE, gradient.weights = FALSE, dense.plot = FALSE )
unit.id |
Name of the unit identifier variable as a character string |
time.id |
Name of the time identifier variable as a character string |
treatment |
Name of the treatment variable as a character string |
data |
data.frame that contains the time series cross sectional data used for matching and estimation. Unit and time data must be integers. Time data must also be formatted as sequential integers that increase by one. |
color.of.treated |
Color of the treated observations provided as a character string (this includes hex values). Default is red. |
color.of.untreated |
Color of the untreated observations provided as a character string (this includes hex values). Default is blue. |
title |
Title of the plot provided as character string |
xlab |
Character label of the x-axis |
ylab |
Character label of the y-axis |
x.size |
Numeric size of the text for xlab or x axis label. Default is 10. Assign x.size = NULL to use built in ggplot2 method of determining label size. When the length of the time period is long, consider setting to NULL and adjusting size and ratio of the plot. |
y.size |
Numeric size of the text for ylab or y axis label. Default is 5. Assign y.size = NULL to use built in ggplot2 method of determining label size. When the number of units is large, consider setting to NULL and adjusting size and ratio of the plot. |
legend.position |
Position of the legend. Provide this according to ggplot2 standards. |
x.angle |
Angle (in degrees) of the tick labels for x-axis |
y.angle |
Angle (in degrees) of the tick labels for y-axis |
legend.labels |
Character vector of length two describing the labels of the legend to be shown in the plot. ggplot2 standards are used. |
decreasing |
Logical. Determines if display order should be increasing or decreasing by the amount of treatment received. Default is |
matched.set |
a matched.set object (optional) containing a single treated unit and a set of matched controls. If provided, this set will be highlighted on the resulting plot. |
show.set.only |
logical. If TRUE, only the treated unit and control units contained in the provided |
hide.x.axis.label |
logical. If TRUE, x axis labels are not shown. Default is FALSE. |
hide.y.axis.label |
logical. If TRUE, y axis labels are not shown. Default is FALSE. |
gradient.weights |
logical. If TRUE, the "darkness"/shade of units in the provided |
dense.plot |
logical. if TRUE, lines between tiles are removed on resulting plot. This is useful for producing more readable plots in situations where the number of units and/or time periods is very high. |
DisplayTreatment
returns a treatment variation plot (using ggplot2),
which visualizes the variation of treatment across unit and time.
In Song Kim <[email protected]>, Erik Wang <[email protected]>, Adam Rauh <[email protected]>, and Kosuke Imai <[email protected]>
DisplayTreatment(unit.id = "wbcode2", time.id = "year", legend.position = "none", xlab = "year", ylab = "Country Code", treatment = "dem", data = dem)
DisplayTreatment(unit.id = "wbcode2", time.id = "year", legend.position = "none", xlab = "year", ylab = "Country Code", treatment = "dem", data = dem)
Calculate covariate balance for user specified covariates across matched sets. Balance is assessed by taking the average of the difference between the values of the specified covariates for the treated unit(s) and the weighted average of the control units across all matched sets. Results are standardized and are expressed in standard deviations. Balance is calculated for each period in the specified lag window.
get_covariate_balance( matched.sets, data, covariates, use.equal.weights = FALSE, verbose = TRUE, plot = FALSE, reference.line = TRUE, legend = TRUE, ylab = "SD", ... )
get_covariate_balance( matched.sets, data, covariates, use.equal.weights = FALSE, verbose = TRUE, plot = FALSE, reference.line = TRUE, legend = TRUE, ylab = "SD", ... )
matched.sets |
A |
data |
The time series cross sectional data set (as a |
covariates |
a character vector, specifying the names of the covariates for which the user is interested in calculating balance. |
use.equal.weights |
logical. If set to TRUE, then equal weights will be assigned to control units, rather than using whatever calculated weights have been assigned. This is helpful for assessing the improvement in covariate balance as a result of refining the matched sets. |
verbose |
logical. When TRUE, the function will return more information about the calculations/results. When FALSE, a more compact version of the results/calculations are returned. |
plot |
logical. When TRUE, a plot showing the covariate balance calculation results will be shown. When FALSE, no plot is made, but the results of the calculations are returned. default is FALSE |
reference.line |
logical indicating whether or not a horizontal line should be present on the plot at y = 0. Default is TRUE. |
legend |
logical indicating whether or not a legend identifying the variables should be included on the plot. Default is TRUE. |
ylab |
Label for y axis. Default is "SD". This is the same as the ylab argument to |
... |
Additional graphical parameters to be passed to the |
#add some additional data to data set for demonstration purposes dem$rdata <- runif(runif(nrow(dem))) pm.obj <- PanelMatch(lead = 0:3, lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", outcome.var ="y", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ tradewb + rdata + I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att") get_covariate_balance(pm.obj$att, dem, covariates = c("tradewb", "rdata"), ylim = c(-2,2)) get_covariate_balance(pm.obj$att, dem, covariates = c("tradewb", "rdata"), plot = TRUE, ylim = c(-2,2))
#add some additional data to data set for demonstration purposes dem$rdata <- runif(runif(nrow(dem))) pm.obj <- PanelMatch(lead = 0:3, lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", outcome.var ="y", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ tradewb + rdata + I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att") get_covariate_balance(pm.obj$att, dem, covariates = c("tradewb", "rdata"), ylim = c(-2,2)) get_covariate_balance(pm.obj$att, dem, covariates = c("tradewb", "rdata"), plot = TRUE, ylim = c(-2,2))
matched_set
is a constructor for the matched.set
class.
matched_set(matchedsets, id, t, L, t.var, id.var, treatment.var)
matched_set(matchedsets, id, t, L, t.var, id.var, treatment.var)
matchedsets |
a list of treated units and matched control units. Each element in the list should be a vector of control unit ids. |
id |
A vector containing the ids of treated units |
t |
A vector containing the times of treatment for treated units. |
L |
integer specifying the length of the lag window used in matching |
t.var |
string specifying the time variable |
id.var |
string specifying the unit id variable |
treatment.var |
string specifying the treatment variable. The constructor function returns a |
Users should never need to use this function by itself. See below for more about matched.set
objects.
matched.set
objects have additional attributes. These reflect the specified parameters when using the PanelMatch
function:
lag |
an integer value indicating the length of treatment history to be used for matching. Treated and control units are matched based on whether or not they have exactly matching treatment histories in the lag window. |
t.var |
time variable name, represented as a character/string |
id.var |
unit id variable name, represented as a character/string |
treatment.var |
treatment variable name, represented as a character/string |
class |
class of the object: should always be "matched.set" |
refinement.method |
method used to refine and/or weight the control units in each set. |
covs.formula |
One sided formula indicating which variables should be used for matching and refinement |
match.missing |
Logical variable indicating whether or not units should be matched on the patterns of missingness in their treatment histories |
max.match.size |
Maximum size of the matched sets after refinement. This argument only affects results when using a matching method |
Adam Rauh <[email protected]>, In Song Kim <[email protected]>, Erik Wang <[email protected]>, and Kosuke Imai <[email protected]>
PanelEstimate
estimates a causal quantity of interest, including the average treatment effect for
treated or control units (att and atc, respectively), or average treatment effect (ate), as specified in PanelMatch
.
This is done by estimating the counterfactual outcomes for each treated unit using
matched sets. Users will provide matched sets that were obtained by the
PanelMatch
function and obtain point estimates via a
weighted average computation with weighted bootstrap standard errors. Point estimates and standard errors will be
produced for each period in the lead window specified by the lead
argument from PanelMatch
.
Users may run multiple estimations by providing lists of each argument to the function.
However, in this format, every argument must be explicitly specified in each configuration
and must adhere to the same data types/structures outlined below. See the included code examples for more about
how this functionality works.
PanelEstimate( sets, number.iterations = 1000, df.adjustment = FALSE, confidence.level = 0.95, moderator = NULL, data )
PanelEstimate( sets, number.iterations = 1000, df.adjustment = FALSE, confidence.level = 0.95, moderator = NULL, data )
sets |
A |
number.iterations |
An integer value indicating the number of bootstrap iterations. The default is 1000. |
df.adjustment |
A logical value indicating whether or not a
degree-of-freedom adjustment should be performed for the standard error
calculation. The default is |
confidence.level |
A numerical value specifying the confidence level and range of interval estimates for statistical inference. The default is .95. |
moderator |
The name of a moderating variable, provided as a character string. If a moderating variable is provided
the returned object will be a list of |
data |
The same time series cross sectional data set provided to the PanelMatch function used to produce the matched sets |
PanelEstimate
returns a list of class
‘PanelEstimate’ containing the following components:
estimates |
the point estimates of the quantity of interest for the lead periods specified |
bootstrapped.estimates |
the bootstrapped point estimate values |
bootstrap.iterations |
the number of iterations used in bootstrapping |
method |
refinement method used to create the matched sets from which the estimates were calculated |
lag |
See PanelMatch argument |
lead |
The lead window sequence for which |
confidence.level |
the confidence level |
qoi |
the quantity of interest |
matched.sets |
the refined matched sets used to produce the estimations |
standard.error |
the standard error(s) of the point estimates |
In Song Kim <[email protected]>, Erik Wang <[email protected]>, Adam Rauh <[email protected]>, and Kosuke Imai <[email protected]>
Imai, Kosuke, In Song Kim, and Erik Wang (2018)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = TRUE) PE.results <- PanelEstimate(sets = PM.results, data = dem, number.iterations = 100)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = TRUE) PE.results <- PanelEstimate(sets = PM.results, data = dem, number.iterations = 100)
Create refined/weighted sets of treated and control units
PanelMatch( lag, time.id, unit.id, treatment, refinement.method, size.match = 10, data, match.missing = TRUE, covs.formula = NULL, verbose = FALSE, qoi, lead = 0, outcome.var, exact.match.variables = NULL, forbid.treatment.reversal = FALSE, matching = TRUE, listwise.delete = FALSE, use.diagonal.variance.matrix = FALSE )
PanelMatch( lag, time.id, unit.id, treatment, refinement.method, size.match = 10, data, match.missing = TRUE, covs.formula = NULL, verbose = FALSE, qoi, lead = 0, outcome.var, exact.match.variables = NULL, forbid.treatment.reversal = FALSE, matching = TRUE, listwise.delete = FALSE, use.diagonal.variance.matrix = FALSE )
lag |
An integer value indicating the length of treatment history periods to be matched on |
time.id |
A character string indicating the name of the time
variable in the |
unit.id |
A character string indicating the name of unit identifier in the data. This data must be integer. |
treatment |
A character string indicating the name of the treatment variable in the |
refinement.method |
A character string specifying the matching or weighting method to be used for refining the matched sets. The user can choose "mahalanobis", "ps.match", "CBPS.match", "ps.weight", "CBPS.weight", "ps.msm.weight", "CBPS.msm.weight", or "none". The first three methods will use the |
size.match |
An integer dictating the number of permitted closest control units in a matched set after refinement.
This argument only affects results when using a matching method ("mahalanobis" or any of the refinement methods that end in ".match").
This argument is not needed and will have no impact if included when a weighting method is specified (any |
data |
A |
match.missing |
Logical variable indicating whether or not units should be matched on the patterns of missingness in their treatment histories. Default is TRUE. When FALSE, neither treated nor control units are allowed to have missing treatment data in the lag window. |
covs.formula |
One sided formula object indicating which variables should be used for matching and refinement.
Argument is not needed if |
verbose |
option to include more information about the |
qoi |
quantity of interest: |
lead |
integer sequence specifying the lead window, for which qoi point estimates (and standard errors) will ultimately be produced. Default is 0 (which corresponds to contemporaneous treatment effect). |
outcome.var |
A character string identifying the outcome variable. |
exact.match.variables |
character vector giving the names of variables to be exactly matched on. These should be time invariant variables. Exact matching for time varying covariates is not currently supported. |
forbid.treatment.reversal |
Logical indicating whether or not it is permissible for treatment to reverse in the specified lead window. This must be set to TRUE for MSM methods. When set to TRUE, only matched sets for treated units where treatment is applied continuously in the lead window are included in the results. Default is FALSE. |
matching |
logical indicating whether or not any matching on treatment history should be performed. This is primarily used for diagnostic purposes, and most users will never need to set this to FALSE. Default is TRUE. |
listwise.delete |
TRUE/FALSE indicating whether or not missing data should be handled using listwise deletion or the package's default missing data handling procedures. Default is FALSE. |
use.diagonal.variance.matrix |
TRUE/FALSE indicating whether or not a regular covariance matrix should be used in
mahalanobis distance calculations during refinement,
or if a diagonal matrix with only covariate variances should be used instead.
In many cases, setting this to TRUE can lead to better covariate balance, especially when there is
high correlation between variables. Default is FALSE. This argument is only necessary when
|
PanelMatch
identifies a matched set for each treated
observation. Specifically, for a given treated unit, the matched
set consists of control observations that have an identical
treatment history up to a number of lag
time periods. Researchers must specify lag
. A further refinement of
the matched set may be performed by setting a maximum size of each matched
set, size.match
(the maximum number of control units that can be matched to a treated unit). Users can
also specify covariates that should be used to identify
similar control units and a method for defining similarity/distance between units. This is done
via the covs.formula
and refinement.method
arguments, respectively, which are explained in more detail below.
PanelMatch
returns an object of class "PanelMatch". This is a list that contains a few specific elements:
First, a matched.set
object(s) that has the same name as the provided qoi if the qoi is "att" or "atc".
If qoi = "ate" then two matched.set
objects will be attached, named "att" and "atc." Please consult the documentation for
matched_set
to read more about the structure and usage of matched.set
objects. Also, see the wiki page for
more information about these objects: https://github.com/insongkim/PanelMatch/wiki/Matched-Set-Objects.
The PanelMatch
object also has some additional attributes:
qoi |
The qoi specified in the original function call |
lead |
the lead window specified in the original function call |
forbid.treatment.reversal |
logial value matching the forbid.treatment.reversal parameter provided in the function call. |
outcome.var |
character string matching the outcome variable provided in the original function call. |
Adam Rauh <[email protected]>, In Song Kim <[email protected]>, Erik Wang <[email protected]>, and Kosuke Imai <[email protected]>
Imai, Kosuke, In Song Kim, and Erik Wang (2018)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) #not including any lagged variables PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ tradewb, size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # Running multiple configurations at once list.of.results = PanelMatch(lag = list(4,3), time.id = list("year", "year"), unit.id = list("wbcode2", "wbcode2"), treatment = list("dem", "dem"), refinement.method = list("mahalanobis", "ps.weight"), data = dem, match.missing = list(TRUE, TRUE), covs.formula = list(~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4))), size.match = list(5,5), qoi = list("att", "att"), outcome.var = list("y", "y"), lead = list(0:4, 0:3), forbid.treatment.reversal = list(FALSE, FALSE), verbose = list(FALSE, FALSE), listwise.delete = list(FALSE,FALSE), use.diagonal.variance.matrix = list(TRUE, NULL), exact.match.variables = list(NULL, NULL), matching = list(TRUE, TRUE))
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) #not including any lagged variables PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ tradewb, size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) # Running multiple configurations at once list.of.results = PanelMatch(lag = list(4,3), time.id = list("year", "year"), unit.id = list("wbcode2", "wbcode2"), treatment = list("dem", "dem"), refinement.method = list("mahalanobis", "ps.weight"), data = dem, match.missing = list(TRUE, TRUE), covs.formula = list(~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4))), size.match = list(5,5), qoi = list("att", "att"), outcome.var = list("y", "y"), lead = list(0:4, 0:3), forbid.treatment.reversal = list(FALSE, FALSE), verbose = list(FALSE, FALSE), listwise.delete = list(FALSE,FALSE), use.diagonal.variance.matrix = list(TRUE, NULL), exact.match.variables = list(NULL, NULL), matching = list(TRUE, TRUE))
A plot method for creating a histogram of the distribution of the sizes of matched sets.
This method accepts all standard optional hist
arguments via the ...
argument.
By default, empty matched sets (treated units that could not be
matched with any control units) are noted as a vertical bar at x = 0 and not included in the
regular histogram. See the include.empty.sets
argument for more information about this.
## S3 method for class 'matched.set' plot( x, ..., border = NA, col = "grey", ylab = "Frequency of Size", xlab = "Matched Set Size", lwd = NULL, main = "Distribution of Matched Set Sizes", freq = TRUE, include.empty.sets = FALSE )
## S3 method for class 'matched.set' plot( x, ..., border = NA, col = "grey", ylab = "Frequency of Size", xlab = "Matched Set Size", lwd = NULL, main = "Distribution of Matched Set Sizes", freq = TRUE, include.empty.sets = FALSE )
x |
a |
... |
optional arguments to be passed to |
border |
default is NA. This is the same argument as the standard argument for |
col |
default is "grey". This is the same argument as the standard argument for |
ylab |
default is "Frequency of Size". This is the same argument as the standard argument for |
xlab |
default is "Matched Set Size". This is the same argument as the standard argument for |
lwd |
default is NULL. This is the same argument as the standard argument for |
main |
default is "Distribution of Matched Set Sizes". This is the same argument as the standard argument for |
freq |
default is TRUE. See |
include.empty.sets |
logical value indicating whether or not empty sets should be included in the histogram. default is FALSE. If FALSE, then empty sets will be noted as a separate vertical bar at x = 0. If TRUE, empty sets will be included as normal sets. |
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) plot(PM.results$att) plot(PM.results$att, include.empty.sets = TRUE)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) plot(PM.results$att) plot(PM.results$att, include.empty.sets = TRUE)
The plot.PanelEstimate
method takes an object returned by the PanelEstimate
function and plots the calculated
point estimates and standard errors over the specified lead
time period.
The only mandatory argument is an object of the PanelEstimate
class.
## S3 method for class 'PanelEstimate' plot( x, ylab = "Estimated Effect of Treatment", xlab = "Time", main = "Estimated Effects of Treatment Over Time", ylim = NULL, ... )
## S3 method for class 'PanelEstimate' plot( x, ylab = "Estimated Effect of Treatment", xlab = "Time", main = "Estimated Effects of Treatment Over Time", ylim = NULL, ... )
x |
a |
ylab |
default is "Estimated Effect of Treatment. This is the same argument as the standard argument for |
xlab |
default is "Time". This is the same argument as the standard argument for |
main |
default is "Estimated Effects of Treatment Over Time". This is the same argument as the standard argument for |
ylim |
default is NULL. This is the same argument as the standard argument for |
... |
Additional optional arguments to be passed to |
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) PE.results <- PanelEstimate(sets = PM.results, data = dem, number.iterations = 100) plot(PE.results)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) PE.results <- PanelEstimate(sets = PM.results, data = dem, number.iterations = 100) plot(PE.results)
matched.set
objects.Print matched.set
objects.
## S3 method for class 'matched.set' print(x, ..., verbose = FALSE)
## S3 method for class 'matched.set' print(x, ..., verbose = FALSE)
x |
a |
... |
additional arguments to be passed to |
verbose |
logical indicating whether or not output should be printed in expanded/raw list form. The verbose form is not recommended unless the data set is small. Default is FALSE |
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) print(PM.results$att)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) print(PM.results$att)
matched.set
object and the matched sets contained within them.A method for viewing summary data about the sizes of matched sets and metadata about how they were created. This method
accepts all standard summary
arguments.
## S3 method for class 'matched.set' summary(object, ..., verbose = TRUE)
## S3 method for class 'matched.set' summary(object, ..., verbose = TRUE)
object |
a |
... |
Optional additional arguments to be passed to the |
verbose |
Logical value specifying whether or not a longer, more verbose summary should be calculated and returned. Default is
|
list object with either 5 or 1 element(s), depending on whether or not verbose
is set to TRUE
or not.
overview |
A |
set.size.summary |
a |
number.of.treated.units |
The number of unit, time pairs that are considered to be "treated" units |
num.units.empty.set |
The number of units treated at a particular time that were not able to be matched to any control units |
lag |
The size of the lag window used for matching on treatment history. This affects which treated and control units are matched. |
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) summary(PM.results$att)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "mahalanobis", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) summary(PM.results$att)
summary.PanelEstimate
takes an object returned by
PanelEstimate
, and returns a summary table of point
estimates and confidence intervals
## S3 method for class 'PanelEstimate' summary(object, verbose = TRUE, bias.corrected = FALSE, ...)
## S3 method for class 'PanelEstimate' summary(object, verbose = TRUE, bias.corrected = FALSE, ...)
object |
A PanelEstimate object |
verbose |
logical indicating whether or not output should be printed in an expanded form. Default is TRUE |
bias.corrected |
logical indicating whether or not bias corrected estimates should be provided. Default is FALSE |
... |
optional additional arguments. Currently, no additional arguments are supported. |
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "none", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) PE.results <- PanelEstimate(sets = PM.results, data = dem, number.iterations = 100) summary(PE.results)
PM.results <- PanelMatch(lag = 4, time.id = "year", unit.id = "wbcode2", treatment = "dem", refinement.method = "none", data = dem, match.missing = TRUE, covs.formula = ~ I(lag(tradewb, 1:4)) + I(lag(y, 1:4)), size.match = 5, qoi = "att", outcome.var = "y", lead = 0:4, forbid.treatment.reversal = FALSE) PE.results <- PanelEstimate(sets = PM.results, data = dem, number.iterations = 100) summary(PE.results)