Data Transformations in STATA


To create a new variable that is an algebraic expression of existing variables use the command "generate" (An acceptable short form of "generate" is "gen".)

To change the values of an existing variables as a function of its original values or the values of other variables, use the command "replace". (An acceptable short form of "replace" is "rep".)

Many operators and functions are permissible:

Examples of the "gen" command:

Extensions of the Generate Command - "egen"

"egen" incorporates a variety of special functions extending the capabilities of the "generate" command. Among those available: count, ma mean, median, rank, st, std, sum


The STATA command "recode" changes the values of a categorical variable into new values. Ranges can be specified by using the slash "/" operator.

Examples of the "recode" command: