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 ...
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 />
conver.dta file or “using” data file, (using conver.dta as<br />
a table lookup) to add the conver variable to our<br />
working data file. We had renamed p1a to unit.<br />
Key variables are required in any procedure to merge two<br />
files when one of the files is being used as a keyed table.<br />
Our key variables specify how to merge the lookup file<br />
using product and unit (the grouping variables), because<br />
we have a different conversion factor <strong>for</strong> each productunit<br />
combination. If we had used only prod, Stata would<br />
expect each product to have only a single conversion<br />
factor, with the same value regardless of the unit of<br />
measurement used. For example, it would expect the<br />
same conversion factor <strong>for</strong> rice whether it was in a 100 kg<br />
bag or a 20 liter can. This would be incorrect.<br />
Check the resulting data file The new working file produced by the join contains the<br />
needed conversion factor variable, conver. For every<br />
product-unit combination, conver is equal to the number<br />
of kilograms in that unit. It is always important to verify<br />
if the join was successfully completed. Click on the Data<br />
Browser button to look at some cases to verify that the<br />
conversion factors match the products. We could also<br />
use the list command to see if a 20-liter can filled with<br />
maize grain has a conversion value of 18 kilograms (prod<br />
= 47 unit = 8).<br />
The Stata command is:<br />
list prod unit conver if prod==47 & unit ==8<br />
Note: Two equal signs (==) are required.<br />
The two equal signs distinguish relational equality from<br />
the =exp assignment phrase. For example, if you want to<br />
create a variable where you will be assigning values to<br />
that variable, you will use an expression (exp) and need<br />
only 1 equal sign (example: gen newvar = oldvar*2.5).<br />
In the above example, prod already has values and we<br />
want to see only records where prod has the value of 47.<br />
There<strong>for</strong>e, it is a relational equality and we must use 2<br />
equal signs (e.g. show me only records where prod ==47<br />
and unit == 8).<br />
We should also run a tabulate on the _merge variable as<br />
well to look at how the merge was done:<br />
59<br />
tab1 _merge