Stata Merge
The merge command joins an external dataset to the active dataset.
Contents
Usage
1:1
merge 1:1 ID using "external_dataset.dta"
Many-to-One
To merge a lookup table with the active dataset, try:
merge m:1 GROUPVAR using "lookup_table.dta"
Result Variable
The merge command creates a _merge variable specifying the result of the merge on a case-by-case basis. This variable can be renamed by specifying the generate(varname) option.
The result groups are:
- Case is sourced only from the active dataset
- Case is sourced only from the external dataset
- Case matched between datasets, and the external values were set for any variables found only in the external dataset
As with 3, except if possible missing values are updated with any non-missing values from the external dataset
As with 3, except external values overwrite the active dataset wherever possible (i.e. missing values cannot overwrite non-missing values)
4 is only possible if the update option is specified. 5 is only possible if the replace option is specified.