ABSTRACT

Usually, these operators are associated with the conditional command If for specific variables. For example, to display only those observations in which the age is below 30, the command line is as follows:

Output

The symbol of asterisk (*) is also used to make any comment during the Stata programming; for example:

2.4 generate Command The generate command (or gen) is used to define new variables in an existing database. For example, let us suppose that you have a database of anthropometric measurements (corresponding to the hypothetical participants of your study), such as weight in kilograms (weikg) and height in meters (heimt), and you want to calculate the body mass index (bmi) of each participant, with bmi being defined as the ratio of weikg over heimt squared. Suppose, further, that the following database is active in Stata:

To compute and display the bmi of each participant, the following commands are executed:

You can see that a new variable, named bmi, has been created as a result of using the list command:

Output

2.5 recode Command The recode command allows the user to change or regroup the values of any variable. For example, let us assume that a user wants to regroup the values of the bmi variable of the previous database in the following three groups: (1) Group 1 contains the values ranging from 18.5 to 24.9, (2) Group 2 are those that range from 25 to 29.9, and (3) Group 3 are the values that are 30 or greater. The commands sequence is as follows:

Output

2.6 drop Command The drop command allows us to eliminate from one to several variables from our active database. For example, to eliminate the bmi variable, the following command must be used:

2.7 replace Command This command allows you to change the value of an existing variable according to the rule specified. For example, let us assume that a user wants to categorize bmi into the following groups: Group 1 (persons with a bmi from 18.5 to 24.49), Group 2 (persons with a bmi from 24.5 and 29.9), and Group 3 (persons with a bmi from 30 onward). The command sequence to create these categories of bmi, assuming that bmi was not already created, is as follows:

After the list command, the results will be the same as that reported with the replace command.