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 ...
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 />
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 identifycation<br />
of an individual household.<br />
The <strong>Group</strong>ing variable(s) is used to specify the<br />
variables to be used <strong>for</strong> combining cases in<br />
the collapsed file. Any cases from the<br />
original file that have identical values <strong>for</strong><br />
all 3 of the grouping variables will be<br />
combined into a single case in the collapsed<br />
file. We want the collapsed file to have one<br />
case per household, so we use the variables<br />
that identify a household in our survey—<br />
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 to explain what you have done.<br />
The Stata command is<br />
collapse (sum) cprod_tt, by(district vil hh)<br />
In the Variables Window you should see only 4<br />
variables. Look at the resulting file (click on the Data<br />
Browser tool). You should see only one case per<br />
household. The collapse command created a new<br />
variable cprod_tt, which we calculated by summing<br />
cprod_tt, total calories produced, across all cases (all<br />
the different food crops) <strong>for</strong> each household. The only<br />
variables which are contained in a collapsed file are the<br />
grouping variables and any new collapsed computed<br />
variables created (e.g. cprod_tt). Remember to close<br />
the browser be<strong>for</strong>e you continue. Stata automatically<br />
added a variable label which is the function and variable<br />
used to create the resulting new variable.<br />
You can look at the variable definitions using the<br />
describe command. The computed variable cprod_tt<br />
does not have a very descriptive label any more so we<br />
need to change the label to reflect what the variable is.<br />
1. Click on Data, then Data utilities, then Label<br />
utilities, then Label variable.<br />
2. In the Variable: box cprod_tt should be<br />
selected<br />
3. In the New variable label (may be up to 80<br />
characters) box, type<br />
Calories Produced in Staple <strong>Food</strong>s<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 Ok button.<br />
65