Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: how to split numeric variable


From   Fernando Lozano <lozano@econ.ucsb.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: how to split numeric variable
Date   Wed, 24 Sep 2003 17:32:08 -0700 (PDT)

On Wed, 24 Sep 2003, Wade T Roberts wrote:

> Hi, I was hoping someone might be able to shed some light on this issue.
>
> I have a single numeric variable that identifies the city/county/state
> for
> each case, where the first three digits represent the city, the next two
> the county, and the final two represent the state.
>
> Examples:
>
>  223406
> 1453209
> 2785845
> etc...
>
> I'm only interested in identifying cases by state at the moment.  How do
> I
> go about singling out this part of the data, or creating a new
> identifying
> state variable?

gen newvar=string(oldvar)
gen state=substr(newvar,n1,n2)

where n1 is the first digit of the variable to appear on state and n2 is
the last digit. For example:

if newvar(i)=1453209 
then gen state(i)=substr(newvar,5,7) will generate state(i)=09

hope this helps.

Fernando

_____________________________________________________________________________________

On Wed, 24 Sep 2003, Wade T Roberts wrote:

> Hi, I was hoping someone might be able to shed some light on this issue.
> 
> I have a single numeric variable that identifies the city/county/state for
> each case, where the first three digits represent the city, the next two
> the county, and the final two represent the state.
> 
> Examples:
> 
>  223406
> 1453209
> 2785845
> etc...
> 
> I'm only interested in identifying cases by state at the moment.  How do I
> go about singling out this part of the data, or creating a new identifying
> state variable?
> 
> Thanks for any help.
> 
> Wade
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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