Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: RE: Destringing alphanumeric string variables


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: Destringing alphanumeric string variables
Date   Wed, 26 Jan 2011 12:15:34 +0000

Also, -destring- with -ignore()- may be useful. 

Nick 
[email protected] 

Andrew Dyck

Although Austin already answered your Q I thought I'd throw this out
there too. You can clean the letters from the V1 variable and have
just the numbers remain by running:

gen V2 = regexs( 1 ) if regexm( V1, "([0-9]+).*" )
destring V2, replace

Again, this will only be useful to you if those alpha-numeric strings
contain useful numeric info.

Austin Nichols 

> drop if mi(real(V1))

Dmitriy Krichevskiy

> > I have a dataset which includes a string variable that I'd like
> > changed to numeric. the issue is some of the observations have a
> > non-numeric components. I would like to drop those observations that
> > are not numeric only. I cannot think of a way to do it either with
> > -destring-,  -encode-, or -substr()-. Below is the data example. As
> > always, all input is greatly appreciated.
> >
> > ID   V1
> > 1    99xx
> > 2    1034
>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index