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

1. From the Data menu select Create or change<br />

variables then Other variable trans<strong>for</strong>mation<br />

commands then Make dataset of means,<br />

medians, etc.<br />

The collapse - Make dataset of means, medians, etc.<br />

dialog box will appear.<br />

2. On the Main tab in the Statistics: box <strong>for</strong> 1:<br />

change “mean” to “sum” by clicking on the dropdown<br />

arrow. In the Variables: box select ae .<br />

3. Click on the Options tab and in the <strong>Group</strong>ing<br />

variables box, select district vil hh in that order<br />

because those variables represent the identification<br />

of an individual household.<br />

The <strong>Group</strong>ing variable(s) is used to specify the variables to<br />

be used <strong>for</strong> combining cases in the collapsed file. Any cases<br />

from the original file that have identical values <strong>for</strong> all 3 of<br />

the grouping variables will be combined into a single case in<br />

the collapsed file. We want the collapsed file to have one<br />

case per household, so we use the variables that identify a<br />

household in our survey—district, vil, and hh.<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 Ok<br />

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

have done.<br />

The Stata command is<br />

collapse (sum) ae, by(district vil hh)<br />

Collapse creates a new working file. The new working<br />

data file is at the household level, with one case per<br />

household. The variable ae is the total adult equivalents<br />

<strong>for</strong> that household. Look at the resulting file (click on the<br />

Data Browser tool). You should see four variables with<br />

only one case per household. You can also look at the<br />

variable definitions using the describe command. The<br />

computed variable ae does not have a very descriptive<br />

label any more so we need to change the label to reflect<br />

what the variable is.<br />

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

utilities, then Label variable.<br />

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

variable: ae<br />

3. In the Attach label to variable (up to 80 characters)<br />

box, type<br />

Adult equivalents per household<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 Ok<br />

71

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

Saved successfully!

Ooh no, something went wrong!