Sep 01

Convert strings to integers in Stata

Tag: stataadmin @ 6:47 pm

Suppose you have a string variable with a finite number of values (e.g. US states, industry, etc).  The encode command plus the generate command will create a new variable that assigns unique ids to each string value: 

encode your_string_variable, gen(new_string_as_int) 

The labels in the edit/browse view will look like strings, so make sure you use ‘nolabel’ on any export or tab commands. 

Leave a Reply