About this Resource

Having prepared the data, linking is usually straightforward. All you need to be clear about is which files you are linking and which variable is the macro identifier. In Stata linking two datasets is done with the merge command. Suppose you wish to merge two files microdata.dta and macrodata.dta, both including the macrounit identifier but with no other variable in common, then you can use the following steps.

Example 1: Merging micro and macro data files in Stata
  1. Save both files in the same folder.
  2. Open the macro data and sort it by macrounit and save it with the commands

    sort macrounit

    save macrodata, replace

  3. Open the micro data and sort it by macrounit

    use microdata

    sort macrounit

  4. Use the following command to link/merge the two files.

    merge macrounit using macrodata

In fact these commands work just as well if you swap the order in which you work on the files, i.e. replace 'macrodata' with 'microdata' and vice versa in the commands.

If there are other variables in common between the two files other than macrounit, you can still merge the files but you will need to specify with the options to the merge command (see the Stata Help system or manuals) whether you want values of the variables to be updated (in the case of missing data in one file) or replaced (in the case of having one more authoritative file) or left unchanged.

The following is an example of linking macro and micro data in Stata. You will need to down load the following .dta file on to your computer:

natturnout.dta

The University of Manchester; Mimas; ESRC; RDI

Countries and Citizens: Unit 4 Combining macro and micro data by Steve Fisher, University of Oxford is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.0 UK: England & Wales Licence.