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

Computing quartiles<br />

The xtile command using if<br />

The new variable does not yet have a variable label. To<br />

assign a variable label:<br />

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

utilities, then Label variable.<br />

2. In the Variables: box, select cprod_ae<br />

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

characters) box, type<br />

Calories produced per adult equivalent per day<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 commands are:<br />

generate double cprod_ae= cprod_tt/ae/365<br />

label variable cprod_ae "Calories produced per adult<br />

equivalent per day"<br />

Be<strong>for</strong>e we can produce the table we want, we have to<br />

create one more variable, denoting which calorieproduction<br />

quartile each household falls into within each<br />

district. The Stata command to use is called xtile. This<br />

command is not available through the menus. To look at<br />

the structure of the command, we can use the Help menu.<br />

1. Click on Help / Stata command.<br />

2. In the Command: box, type xtile and click on Ok.<br />

Under the Description heading, the definition of xtile is<br />

that it is a command that categorizes a variable into the<br />

specified quantiles and places the in<strong>for</strong>mation into a new<br />

variable. Examples can be found under the Examples:<br />

heading. Since we want to divide the data into quartiles<br />

within each district, we can use the “if” subcommand,<br />

e.g.,<br />

xtile quart = cprod_ae if district == 1, nq(4)<br />

where<br />

quart is the new variable that is created<br />

cprod_ae is the variable used to rank the data<br />

district is the controlling variable<br />

nq(4) is short <strong>for</strong> nquantiles(number) which<br />

specifies the number of quantiles to use.<br />

1. Click on Statistics then Summaries, tables and<br />

tests then Summary and Descriptive Statistics<br />

then Create variable of quantiles<br />

75

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

Saved successfully!

Ooh no, something went wrong!