R: Append matched datasets together

rbind.matchdata {MatchIt} | R Documentation

## Append matched datasets together

### Description

These functions are `rbind()` methods for objects resulting from calls to `match.data()` and `get_matches()`. They function nearly identically to `rbind.data.frame()`; see Details for how they differ.

### Usage

    ## S3 method for class 'matchdata'
    rbind(..., deparse.level = 1)

    ## S3 method for class 'getmatches'
    rbind(..., deparse.level = 1)

### Arguments

`...` | Two or more `matchdata` or `getmatches` objects the output of calls to `match.data()` and `get_matches()`, respectively. Supplied objects must either be all `matchdata` objects or all `getmatches` objects.
`deparse.level` | Passed to `rbind()`.

### Details

`rbind()` appends two or more datasets row-wise. This can be useful when matching was performed separately on subsets of the original data and they are to be combined into a single dataset for effect estimation. Using the regular `data.frame` method for `rbind()` would pose a problem, however; the `subclass` variable would have repeated names across different datasets, even though units only belong to the subclasses in their respective datasets. `rbind.matchdata()` renames the subclasses so that the correct subclass membership is maintained.

The supplied matched datasets must be generated from the same original dataset, that is, having the same variables in it. The added components (e.g., weights, subclass) can be named differently in different datasets but will be changed to have the same name in the output.

`rbind.getmatches()` and `rbind.matchdata()` are identical.

### Value

An object of the same class as those supplied to it (i.e., a `matchdata` object if `matchdata` objects are supplied and a `getmatches` object if `getmatches` objects are supplied). `rbind()` is called on the objects after adjusting the variables so that the appropriate method will be dispatched corresponding to the class of the original data object.

### Author(s)

Noah Greifer

### See Also

`match.data()`, `rbind()`

See `vignettes("estimating-effects")` for details on using `rbind()` for effect estimation after subsetting the data.

### Examples

    data("lalonde")

    # Matching based on race subsets
    m.out_b <- matchit(treat ~ age + educ + married +
                        nodegree + re74 + re75,
                      data = subset(lalonde, race == "black"))
    md_b <- match.data(m.out_b)

    m.out_h <- matchit(treat ~ age + educ + married +
                        nodegree + re74 + re75,
                      data = subset(lalonde, race == "hispan"))
    md_h <- match.data(m.out_h)

    m.out_w <- matchit(treat ~ age + educ + married +
                        nodegree + re74 + re75,
                      data = subset(lalonde, race == "white"))
    md_w <- match.data(m.out_w)

    #Bind the datasets together
    md_all <- rbind(md_b, md_h, md_w)

    #Subclass conflicts are avoided
    levels(md_all$subclass)

[Package MatchIt version 4.3.3 Index]