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

Search Data Services

Meta Search
search across all the following databases:

Data Catalog
Data and documentation

KnowledgeBase
Common questions and answers.

Resources
Entire collection of data resources.


Latest Data News

RSS Feed icon

Political Science: A self-inflicted wound?

Sage Stats and CQ Political Stats Trial

Breaking News: Protect the 2020 Census

The Fastest Growing US Cities Are Mostly In the West

Another rule from NIH: Demographers might get to ignore this one

Data Services Knowledge Base

Q:  

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?

A:  

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: