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
Here is (I think) a far simpler and more efficient version of the previous person's stata.merge function. This assumes you don't have variables named "new1" or "new2" in your data frames. If this assumption is wrong, change the variable names in this function. This function takes 3 variables, the first data frame, the second data frame, and the value to enter into the "by =" part of the merge function.
stata.merge <- function(x,y, name){
x$new1 <- 1
y$new2 <- 2
df <- merge(x,y, by = name, all = TRUE)
df$stat.merge.variable <- rowSums(df[,c("new1", "new2")], na.rm=TRUE)
df$new1 <- NULL
df$new2<- NULL
df
}