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.
- Save both files in the same folder.
- Open the macro data and sort it by macrounit and save it with the commands
sort macrounit
save macrodata, replace
- Open the micro data and sort it by macrounit
use microdata
sort macrounit
- 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: