Home > Data Services > Catalog . Restricted Data . Census . ACS

Search Data Services

Meta Search
search across all the following databases:

Data Catalog
Data and documentation

Common questions and answers.

Entire collection of data resources.

Latest Data News

RSS Feed icon

More census/citizenship articles

Deja vu: Citizenship question or not?

Data Visualization: Intro with Data

Data & Tools to study Global Inequality

Archiving Social Media Data

Data Services Knowledge Base


I have duplicate variable names in two data sets that I would like to merge using stata. Do I have to go through and change variable names?


By default, stata keeps the values of the "master" file when a merge involves variables with the same name in both files.

The merge command includes an update option to override this default. However, it is best to rename your variables so that the master and using files have unique variable names.

One way to rename variables is to use the renpfix command. This command allows you to add a prefix to variable names. Thus, all variables in your hospital file could have an h_ appended to them. Unfortunately, this requires:

renpfix a* h_      
renpfix b* h_  

etc., unless you can figure out how to use the foreach command.

You have lots of variables, so typing in the renpfix command 26 times is less tedious than renaming each item one by one.

Annotated Resources:

Direct Links:

Related Question Groups: