STATA 11 for Windows SAMPLE SESSION - Food Security Group ...
STATA 11 for Windows SAMPLE SESSION - Food Security Group ...
STATA 11 for Windows SAMPLE SESSION - Food Security Group ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Stata <strong>11</strong> Sample Session Section 2 – Restructuring Data Files – Table Lookup & Aggregation<br />
We noted earlier that key variables are required <strong>for</strong> any<br />
merge. When you're joining two files which are at the<br />
same data level, as we're about to do, it may not seem<br />
important to include key variables, but it is. The key<br />
variables determine which observations are to be<br />
combined.<br />
Note: You should never use Combine datasets without<br />
Key Variables because without them you have no<br />
guarantee that the program will combine the cases in the<br />
manner that you wish.<br />
The command will execute without any warnings or error<br />
messages, but the results may be incorrect.<br />
At this point, if you have not closed Stata, hh-file2.dta is<br />
still the working file.<br />
A very important point: Stata cannot merge two<br />
datasets unless they are both sorted in the order of the key<br />
variables. One way to check to see if Stata knows the file<br />
is sorted is to use the Describe command. In the Results<br />
window you can see at the end of the list of variables, the<br />
words “sorted by” and the list of variables that the file is<br />
sorted by. Because we created hh-file1.dta by collapsing<br />
the file, it is already sorted by district, vil and hh. hhfile2.dta<br />
was also created by collapsing the file so it is<br />
also sorted by district, vil and hh. We are ready to merge<br />
the two files.<br />
1. Select Data then Combine datasets then Merge<br />
Two datasets<br />
The Merge - Merge dataset in memory with dataset on<br />
disk dialog box will appear. The default type of merge is<br />
one-to-one on key variables – this is the merge we want<br />
to do.<br />
2. We are doing a one to one on key variables – type<br />
of merge, the default selection. For the Filename of<br />
dataset on disk box, click on the Browse button.<br />
Select the file hh-file1.dta and click on Open<br />
3. In the Key variables (match variables) box,<br />
select<br />
district vil hh<br />
These are the Key Variables<br />
4. Click on the Options tab. Under this tab, you see<br />
the box labeled Specify new name of variable to<br />
mark result of merge The default name is<br />
_merge. This variable received a code of 1 or 2 or<br />
3 to describe what type of merge occurred. The<br />
code definition is:<br />
73