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

Calculate the total calories<br />

produced per adult equivalent per<br />

household <strong>for</strong> the year<br />

1 = observation is from file in memory<br />

2 = observation is from file on disk<br />

3 = observations are from both files<br />

It is very important to look at the values in this<br />

variable after you have run the merge.<br />

5. 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 click<br />

on Ok.<br />

6. In the do-file insert comments to remind you what<br />

you’ve done.<br />

The Stata command is:<br />

Merge 1:1 district vil hh using "hh-file1.dta"<br />

In the results window, you see a summary of the number<br />

of observations not matched and matched.<br />

Now that you have run the merge, run a tabulate on the<br />

_merge variable. You can abbreviate the name to “_m”,<br />

e.g. tabulate _m. You should see only the value of “3"<br />

<strong>for</strong> 343 observations. That means that there was an<br />

observation <strong>for</strong> each “district - vil - hh” combination in<br />

each of the two files.<br />

Merge Files created a new working data file. The two<br />

variables you need to compute calories produced per<br />

adult equivalent are now in the working file. Total<br />

calories produced (cprod_tt) per household <strong>for</strong> the year<br />

divided by total adult equivalents per household (ae)<br />

divided by 365 days per year gives us calories produced<br />

per adult equivalent per day (cprod_ae).<br />

1. Select Data then Create or change variables then<br />

from Create new variable<br />

The generate - Create a new variable dialog box<br />

opens.<br />

2. If you see in<strong>for</strong>mation in the dialog box, click on<br />

the Reset icon to clear the contents.<br />

3. Under the Main tab, type the name of the new<br />

variable in the Generate Variable box:<br />

cprod_ae<br />

4. Change the Variable type to “double”.<br />

5. For the Contents of new variable box, type in<br />

cprod_tt/ae/365<br />

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

editor, paste the command, switch back to the<br />

dialog box and click on Ok.<br />

7. Add a comment in the do-file to explain what you<br />

have done.<br />

74

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

Saved successfully!

Ooh no, something went wrong!