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!).
- From within Stata open the data file natturnout.dta,
- Have a look at the data:
list
- Now, sort the data by the macro-unit identifier 'country':
sort country
- 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.
- 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
- 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.
- You should see a new variable _merge appear in your
variable list
- Check that this always takes the value 3 to see that the merge has worked properly.
tabulate _m
- If the merge has worked properly you probably want to drop the _merge variable with the following command.
drop _merge
- You can also browse and explore your data in other ways to see what's happened.