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

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

Step 1: Generate a household<br />

level file containing the<br />

number of calories produced<br />

per household.<br />

In executing this step, we must keep three things firmly in<br />

mind.<br />

First, all production is currently measured in nonstandard<br />

units. Each unit can have a different weight <strong>for</strong><br />

each of the products. Thus, we must first convert all<br />

production into kilograms.<br />

Second, we want to know many calories are produced by<br />

each household, not kilograms. Thus, after converting all<br />

production to kilograms, we must convert kilograms to<br />

calories.<br />

Third, an examination of the file shows that we have data<br />

<strong>for</strong> each product produced by the household. But we<br />

want to know the total calories produced by the<br />

household <strong>for</strong> specific food products, not the total<br />

calories from each separate product. After we convert all<br />

production to calories, we must sum the calories within<br />

each household to arrive at the household total.<br />

Let's begin by creating a new do-file. Open the Do-File<br />

Editor. Start by including comments about the purpose<br />

of the do-file, your name as the creator of the do-file and<br />

the date. Other items to include are the Stata version, the<br />

set memory command if you have not changed the startup<br />

memory, the “cd” command to switch to the directory<br />

where you want to work, the log command to record the<br />

session. Example:<br />

version <strong>11</strong><br />

set memory 30m<br />

cd "C:\Documents and Settings\aec_user\My Documents\data"<br />

log using log_session2, append<br />

We are now ready to open c-q4.dta, the production file.<br />

1. Select File / Open...<br />

2. Select the file name c-q4.dta<br />

3. Click on Open to run the command.<br />

4. Copy the command to open this file from the<br />

Results window, switch to the Do-File Editor<br />

( or click on the button on the task bar)<br />

and paste the command into the do-file. Delete<br />

the reference to the directory.<br />

5. Save the do-file to the name session2.do<br />

We must convert all production of the crops into<br />

kilograms. To find the conversion factor appropriate <strong>for</strong><br />

56

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

Saved successfully!

Ooh no, something went wrong!