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

Creating New Variables in Stata

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

Original Video Description

How to create new variables in Stata.

Transcription (Auto-Generated)

in this video I’ll show you how to create new variables in Stata you create new variables in Stata using the gen command gen is short for generate the syntax for generating new variables is gen space the name of the new variable equals and an expression the expression defines the new variable expressions can take many values it can be a numerical constant so for example if you type in gen year equals 2000 for all of your observations we’ll have the variable year with a value of 2014 expressions can also be variables for example Gen age equals age years we’ll create a new variable called age that will have exactly the same value as the variable age years you can also do calculations for example Gen test average equals parentheses test 1 + test 2 + test 3 close parentheses divided by 3 will give us the average across the 3 tests that are scored in those 3 variables let’s see what it’s like to generate variables in a state a session in this example I’ll create a variable that gives respondents birth here imagine the survey was taken in 2010 then their birth year is 2010 – their current age I type Gen birth year equals 2010 – age the variable birth here will give their years of birth let’s review you can create new variables in Stata by using the gen command the syntax is gen space the name of the new variable you want to create equals and an expression for more help type in help gen in this data command window