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: Destringing alphanumeric string variables


From   Andrew Dyck <[email protected]>
To   send to stata list <[email protected]>
Subject   st: Destringing alphanumeric string variables
Date   Tue, 25 Jan 2011 15:37:51 -0800

Dear Dmitriy,

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.

Cheers,
Andrew

On Tue, Jan 25, 2011 at 9:49 AM, Austin Nichols <[email protected]> wrote:
>
> Dmitriy Krichevskiy <[email protected]>:
> drop if mi(real(V1))
>
> On Tue, Jan 25, 2011 at 12:34 PM, Dmitriy Krichevskiy
> <[email protected]> wrote:
> > Dear Statalisters,
> > 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/

*
*   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