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 1 - Basic functions: Files, Descriptives, Data Trans<strong>for</strong>mations<br />
Data Trans<strong>for</strong>mations After examining the results of the descriptive statistics you<br />
will often want to do data trans<strong>for</strong>mations. A data<br />
trans<strong>for</strong>mation is an operation that takes an existing variable<br />
and either changes the values in a systematic way or uses<br />
the values to calculate a new variable. The following<br />
example shows a common data trans<strong>for</strong>mation: the<br />
conversion of a continuous variable to a categorical<br />
variable.<br />
Converting continuous<br />
variables to categorical<br />
variables<br />
The generate command<br />
The replace command<br />
The label variable command<br />
The label define command<br />
First method:<br />
The generate command<br />
The in<strong>for</strong>mation we received from the summarize<br />
command is interesting, but it might also be useful to see<br />
the actual distribution of the ages into groups or categories,<br />
so we can tell, <strong>for</strong> example, how many heads of household<br />
are older than 60. Since the age variable, ca3, is<br />
continuous, we cannot do this directly—first we have to<br />
trans<strong>for</strong>m it. Let's suppose we're interested in four<br />
categories: 0-10 years old, <strong>11</strong>-19 years, 20-60 years, and<br />
over 60 years of age.<br />
To categorize a variable, we can use the generate<br />
command. Categorizing a continuous variable makes<br />
detailed in<strong>for</strong>mation more general. To keep the detailed<br />
in<strong>for</strong>mation as well as the new general in<strong>for</strong>mation, you<br />
must recode the variable into a new variable. If you recode<br />
into the same variable the original values will be lost.<br />
There are several methods that can be used to recode a<br />
continuous variable.<br />
First method: If you wish to see the category values of 1,<br />
2, 3, and 4 where<br />
1 = 0-10,<br />
2 = <strong>11</strong>-19,<br />
3 = 20-60 and<br />
4 = over 60<br />
you can do the following:<br />
1. From the Data menu select Create or change<br />
variables / Create new variable<br />
The Generate - Create a new variable dialog box opens.<br />
2. Under the Main tab, type the name of the new<br />
variable in the Variable name box: age_gp<br />
3. For the Contents of new variable box, type in<br />
1<br />
This is the value that you want the new variable to have.<br />
4. In the drop down box <strong>for</strong> the Variable type select<br />
byte.<br />
5. Click on the If/In tab.<br />
41