10.04.2013 Views

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 ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Stata <strong>11</strong> Sample Session Section 2 – Restructuring Data Files – Table Lookup & Aggregation<br />

The drop command<br />

(see the previous merge), so we don't need to sort it again.<br />

Stata will reuse the _merge variable again with the next<br />

join we do, so we should drop this variable first since we<br />

no longer need it. The command to delete a variable is<br />

called drop<br />

The Stata command is:<br />

drop _merge<br />

Now we are ready <strong>for</strong> the next join:<br />

1. From the Data menu select Combine datasets,<br />

then select Form all pairwise combinations<br />

within groups<br />

The joinby - <strong>for</strong>m all pairwise combinations within<br />

groups dialog box opens.<br />

2. To fill in the box labeled Filename of dataset<br />

on disk: click on the Browse button, Select the<br />

filename calories.dta and click on Open.<br />

3. In the box labeled Join observations by<br />

groups <strong>for</strong>med from specific variables, select<br />

prod only<br />

4. Click on the “Options” tab.<br />

5. Under “Unmatched Observations”, select<br />

Include from data in memory<br />

This option will keep cases in the original<br />

data set that do not have a match in the<br />

lookup data set.<br />

6. Click on the copy button, switch to the do-file<br />

editor, paste the command, delete the directory<br />

reference, switch back to the dialog box and<br />

click on Ok<br />

7. Add comments to the do-file.<br />

The Stata command is:<br />

joinby prod using "calories.dta", unmatched ( master )<br />

_merge(_merge)<br />

The new working data file produced by the merge now<br />

contains the needed calorie variable, calories, but check<br />

to make sure. Maize grain (PROD=47) should have 3590<br />

calories per kilogram in the calories variable. We can<br />

browse the data and/or we can use the list command<br />

again.<br />

The Stata command is:<br />

list prod calories if prod==47<br />

Also check the _merge variable to see how the merge was<br />

61

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!