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

we want to merge by have the same names. We will<br />

rename p1a to unit.<br />

1. From the Data menu select Data utilities then<br />

Rename variable<br />

The rename - Rename variables dialog box will<br />

come up.<br />

2. In the Existing Variables box select p1a. In<br />

the New variable name box type unit.<br />

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

The Stata command is:<br />

rename p1a unit<br />

The joinby command The files are now ready to be merged. We are doing a<br />

“File - Table” merge where the second file is our<br />

“Lookup Table”. We want to keep all records in the<br />

“master” file (or the file in memory) and keep only those<br />

records in the “using” file that match.<br />

1. From the Data menu select Combine datasets,<br />

then select Form all pairwise combinations<br />

within groups<br />

The joinby - <strong>for</strong>m all pairwise combinations within<br />

groups dialog box will open.<br />

2. To fill in the box labeled Filename of dataset<br />

on disk: click on the Browse button, Select the<br />

filename conver.dta and click on Open.<br />

3. In the box labeled Join observations by<br />

groups <strong>for</strong>med from specific variables, select<br />

prod unit<br />

4. Click on the “Options” tab.<br />

5. Under “Unmatched Observations”, select<br />

Include from data in memory<br />

This option will keep cases in the “master”<br />

data set (in memory) that do not have a match<br />

in the lookup data set.<br />

6. Click on the copy button, switch to the do-file<br />

editor, paste the command, delete the directory<br />

reference, switch back to the dialog box and<br />

click on Ok<br />

The Stata command is<br />

joinby prod unit using "conver.dta",<br />

unmatched(master) _merge(_merge)<br />

The above command tells Stata to merge the working<br />

data file or “master” (the file in memory) with the<br />

58

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

Saved successfully!

Ooh no, something went wrong!