Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: combining two variables


From   Johannes Schoder <[email protected]>
To   [email protected]
Subject   Re: st: combining two variables
Date   Sat, 12 Sep 2009 15:42:26 -0400

Hi Michael:
I tried your suggestion but Stata reports type mismatch.
My state variable is not numeric its a string variable, so I think thats why its not working. But Joseph's recommendation worked out fine.
Thanks a lot for your comment,
Johannes

Michael I. Lichter schrieb:
If you're using FIPS county codes, they're 2-digit state + 3-digit county.

gen int fipscnty = (1000 * state) + county

I'm assuming you want this numeric. You can also create a string code
like this:

gen str5 fipscnty = string(state, "%02.0f") + string(county, "%03.0f")

The "%0#.#f" format creates leading 0s as needed.

-ml

Johannes Schoder wrote:
Dear Statalist users:

I would like to combine two variables in one:

The first variable represents the state: e.g. CA (California) or AZ (Arizona).
The second variable represents the countiy and includes numbers: 01,...

The combination of both variables finally states from which county the individual is from, e.g. CA 01 is county Alameda, AZ 01 is county Apache, etc. Does anyone know a trick how to combine both variables so that it identifies uniquely the county where the person is from?
Thanks a lot!!
Johannes

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index