Joining Data with Stata

Stata offers several commands for joining datasets.


Full Join

If the left and right datasets may overlap, use -merge- to ensure that duplicates are not created.

use "left.dta"
merge 1:1 KEYVARS using "right.dta"

If they are known to not overlap, consider using -append- instead.

use "cohort1.dta"
append using "cohort2.dta"

See also -frlink-.


Left, Right, or Inner Joins

Use -merge- as above and select cases based on the automatically created _merge variable.

use "left.dta"
merge 1:1 KEYVARS using "right.dta"
keep if _merge==1 | _merge==3       // left join
keep if _merge==2 | _merge==3       // right join
keep if _merge==3                   // inner join


CategoryRicottone

Stata/JoiningData (last edited 2025-10-24 16:34:25 by DominicRicottone)