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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With