About this Resource

The following commands are an example of linking macro and micro data in Stata. The macro file, nattturnout.dta, includes ESS survey-estimates of national-level turnout but they aren't accurate or official (this is just an exercise!).

  1. From within Stata open the data file natturnout.dta,
  2. Have a look at the data:
    list
  3. Now, sort the data by the macro-unit identifier 'country':
    sort country
  4. To save the macro data in the route directory, use the following command.
    save natturnout
    Note that if you don't have write access to your current root directory, specify the complete path in the save command.
  5. Open the micro data ESSsubset.dta, use the command:
    http://www.mimas.ac.uk/limmd/materials/LIMMD-unit5/data/ESSsubset.dta
    and sort it by the macro-unit identifier:
    sort country
  6. Now, you can merge in the macro data. Merge country using natturnout If you saved the natturnout file somewhere other than the root directory, you will have to specify the full path.
  7. You should see a new variable _merge appear in your variable list
  8. Check that this always takes the value 3 to see that the merge has worked properly. tabulate _m
  9. If the merge has worked properly you probably want to drop the _merge variable with the following command.
    drop _merge
  10. You can also browse and explore your data in other ways to see what's happened.

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.