Joseph Nathan Cohen

Department of Sociology, CUNY Queens College, New York, NY

Replacing Variable Values in Stata

To see more about the “Teaching through YouTube” series.  For more, see this post.

Original Video Description

This video shows you how to change variable values in Stata.

Transcription (Auto-Generated)

in this video we’ll talk about how to replace variable values in Stata we use the replace command to change variables values the syntax for replacing values is replace space the variable name equals an expression and an if statement in this example I am asking Stata to make the abortion variable missing if it is currently equal to minus 99 the expression gives what the new variable value will be what you’re trying to change variable values to the if statement gives the conditions that those variables will be changed so in this example only abortion values that are equal to minus 99 will be changed all other values will be ignored in this example I asked data to replace the value of the region variable to America if the country variable was equal to USA in this example I asked data to replace the variable of GPA to equal 3.9 if the Honorable is equal to 1 let’s review the replace command is used to change variable values in Stata the syntax is replace space the name of the variable that you want to change values in equals expression which defines the new variable that will be inserted in lieu of the old one and an if statement which are the conditions that have to be met if the variables value is to be changed for more help on this command type help replace in the command window it’s data