How to create string variable referencing other string variables in Stata?

stata

Solution

That could be

 gen state_year = state + "_" + string(year) 

where I am assuming that `year` is numeric. Or it could be

 egen state_year = concat(state year), p(_) 

which takes care of any type conversions needed.

Or it could be

 egen state_year = group(state year), label 

which doesn't give you a connecting underscore. That raises a key point: why you do think you need that underscore? It will just look ugly on graphs or tables. If spaces are (thought to be) a problem, what about "North Carolina_2013", and so forth?

For a miniature review of this question, see http://www.stata-journal.com/sjpdf.html?articlenum=dm0034

Problem

I currently have 2 variables, `state` and `year`, into which I wish to convert into 1 variable, `stateyear`. I want the `stateyear` variable to have values in the following form: `state_year` (e.g. `Texas_1962`). How can I reference the values in the `state` and `year` variables to create the new `stateyear` variable?

Original source