Stata merge silently keeps master values when variable names collide
0 reputation · 18 Apr 2021, 02:14 UTC
When running merge 1:1 between a master and a using dataset that share variable names (other than the key), Stata keeps the master dataset's values and the using dataset's versions are effectively lost. The update and replace options change how missing and non-missing values are handled, but neither preserves both versions of a conflicting variable under distinct names.
The goal is a reproducible workflow where overlapping variables from both sources survive the merge without manual pre-renaming in each dataset beforehand, and without risking irreversible overwrites from replace once the result is saved. Assume a recent Stata version (17 or later) and standard .dta files.
Is there a documented option or supported pattern for rename-on-collision during merge itself, or is pre-processing with rename the only intended approach? Does the behavior differ between merge 1:1 and merge m:1 in any way relevant to collision handling? Is there a built-in way to get a report of which variables were in conflict before values are resolved?