Stata automatically creates a variable called \"_merge\" indicating the matched variables in both datasets after merge. Is there a way to get such variable generated by R\'s
The possible values of _merge
in Stata
are (note merge
can also have values 4 and 5)
1 master observation appeared in master only
2 using observation appeared in using only
3 match observation appeared in both
In R
, you can do that by entering the argument as either all=TRUE
or all.x=TRUE
or all.y=TRUE
e.g.,
merge(x, y, by = intersect(names(x), names(y)),by.x = by, by.y = by, all = TRUE)
merge(x, y, by = intersect(names(x), names(y)),by.x = by, by.y = by, all.x = TRUE)
merge(x, y, by = intersect(names(x), names(y)),by.x = by, by.y = by, all.y = TRUE)