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

done:<br />

tab1 _merge<br />

Note that there are 87 cases with no value in the calorie<br />

variable. How would you check to see which products<br />

have no calorie value?<br />

We can now compute total calories produced.<br />

1. Select Create or change variables from the<br />

Data menu<br />

2. Select Create new variable<br />

The Generate – Create a new variable dialog box<br />

opens. We have used this dialog box earlier.<br />

To clear the contents, click on the “Reset”<br />

icon in the lower left corner of the dialog<br />

box.<br />

3. Under the Main tab, change the Variable type<br />

to “double”.<br />

4. Type the name of the new variable in the<br />

Variable name box: cprod_tt<br />

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

qprod_tt * calories<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<br />

you have done.<br />

The Stata command is:<br />

generate double cprod_tt= qprod_tt * calories<br />

Note that missing values were generated <strong>for</strong> 131 cases.<br />

Assign variable labels The two new variables do not yet have variable labels.<br />

To assign a variable label:<br />

1. Click on Data, then Data utilities, then Label<br />

utilities, then Label variable.<br />

2. In the Variable: box, select the name of the first<br />

variable: qprod_tt<br />

3. In the New variable label (may be up to 80<br />

characters) box, type<br />

Total production in kgs<br />

4. 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 the Submit button.<br />

Clicking on the “submit” button leaves the<br />

dialog box open so we can then define the<br />

label <strong>for</strong> the cprod_tt variable without having<br />

62

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

Saved successfully!

Ooh no, something went wrong!