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

command to be placed in the do-file. Switch to<br />

the do-file editor and type<br />

levelsof district, local(levels)<br />

3. We can now create variables containing the rank<br />

of the household within each district. We must<br />

type these commands into the do-file because the<br />

command is multiple lines. You are already in the<br />

do-file editor . Type:<br />

<strong>for</strong>each z of local levels {<br />

xtile quartile`z’ = cprod_ae if (district == `z’), nq(4)<br />

}<br />

‘z’ is a local macro name which is set to each value in the<br />

variable “levels”. The values we know are 1, 2, and 3. In<br />

the first loop of this programming command z is equal to<br />

1, in the second loop z is equal to 2, etc.<br />

quartile`z’ refers to a variable name where the contents of<br />

z is appended to the name quart, e.g. quart1, quart2,<br />

quart3, etc.<br />

district = `z’, means that <strong>for</strong> the first loop district is equal<br />

to 1, <strong>for</strong> the second loop district is equal to 2, etc.<br />

Very important note: The macro name `z’ must be<br />

surrounded by a “left” single quote (found in the upper<br />

left hand corner or the keyboard to the left of the key with<br />

the number 1) and a “right” single quote (found on the<br />

key to the left of the key). If you do not use the<br />

left single quote, you will see an error message that says<br />

in red:<br />

' invalid name<br />

Be sure that you end the first line with a left<br />

curly brace, e.g. { and that you place on a line<br />

by itself after all commands that you want to be<br />

included in the loop, a right curly brace, e.g. }<br />

Since we have 3 districts, 3 new variables will be created<br />

with names of quartile1, quartile2, quartile3.<br />

4. We want all the in<strong>for</strong>mation in just one variable<br />

so we will create another variable and fill it with<br />

the in<strong>for</strong>mation from the variables created above.<br />

If you created a variable called “quart” following<br />

the instructions above, you will need to drop it<br />

77

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

Saved successfully!

Ooh no, something went wrong!