Description Usage Arguments Examples
This function merges dataframes the same way it's done in Stata. As in Stata, the user must define which of the dataframes is unique on the merge variables. The default function returns the merged dataframe with a variable that indicates which of the original dataframes each observation appears in.
1 2 | stata_merge(master, using, by_vars, merge_type = "1:1", merge_var = "merge",
gen = TRUE, keep_cases = c(1, 2, 3))
|
master |
the primary dataframe |
using |
the dataframe being merged into the master dataframe |
by_vars |
a vector of variables on which the merge is being conducted |
merge_type |
the type of Stata merge you want to run. Options that parse are "1:1", "m:1", and "1:m" where the choice for the master dataframe appears before the colon, the choice for the using dataframe appears after the colon, "1" means that dataframe is unique on the merging variables, and "m" means that dataframe is not unique on the merging variables. |
merge_var |
a name for the merge indicator that is added to the new dataframe. Defaults to "merge". |
gen |
controls whether new dataframe contains the merge indicator. Defaults to TRUE. |
keep_cases |
a vector that contains the types of observations to keep in the new dataframe. 1 captures those only in master, 2 captures those only in using, 3 captures those observations found in both dataframes. |
1 2 3 | data1 <- data.frame(a=1:10, b=rnorm())
data2 <- data.frame(a=1:10, c=rnorm())
stata_merge(data1, data2, "a")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.