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

Generating Binary Variables 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 use Stata to create binary variables that demarcate specific groups.

Transcription (Auto-Generated)

in this video we’ll talk about how to generate binary variables using other data binary variables have the value 1 or 0 we use them to create true/false variables for example in an analysis we might want to compare the experiences of whites and non-whites to do this we need a variable that indicates whether or not a subject is white or non-white for example in this survey we might want to distinguish the characteristics of whites versus non-whites however race may be quoted in a multi kata miss variable that means there’s more than one category we want to break down this multi columnist race category into a dichotomous category one where it would be one for all white people and 0 for all non whites to create that type of variable we use the command Jen for generate the syntax for Jen to create a dichotomous variable is Jen space the name of the new variable that you want to create space equals space the old variable and a logical symbol and a value which would be the value that corresponds to the group that you want to demarcate logical operators our operators like greater than less than equal to or not equal to so for example if race is stored as a string variable that means words like white black Asian or whatever we might create a binary variable demarcating race like this Jen white equals race equals equals to white and quotation marks equals equals open quotation mark white close quotation mark in this situation we would be creating a variable called white it will be equal to one if race is equal to the word white and zero if it isn’t this can be done with numbers two in this example I create a variable called senior it’s equal to one if the variable age is greater than or equal to 65 and it’s equal to zero otherwise you can use multiple variables in a logical operation in this example I create a variable called money lost which is equal to one if the person’s income is less than its expenses and zero if the income is equal to or greater than expenses let’s see what it looks like to generate binary indicators in a state a session let’s create a variable that distinguishes college graduates from non college graduates I’ll use the variable degree to see what numbers correspond to each educational attainment level I run the tab a second time using the No Labels option it shows that three is for people who completed a bachelor degree and for us for people who finish graduate school to create the variable type Gen college-educated equals degree is equal to three or degree is equal to four shows that 29% of the sample is college educated and that everybody who had a bachelor’s or graduate degrees in that category let’s review binary indicators take a value of 1 or 0 we use them to demarcate members of a group from non-members to create a binary indicator in Stata use the syntax gen space the name of the new variable equals the old variable from which your classification will be done a logical operator and then a value for more help type help gen in the command window