Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Andrew Dyck <andrew@andrewdyck.com> |
To | send to stata list <statalist@hsphsun2.harvard.edu> |
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 <austinnichols@gmail.com> wrote: > > Dmitriy Krichevskiy <krichevskyd@gmail.com>: > drop if mi(real(V1)) > > On Tue, Jan 25, 2011 at 12:34 PM, Dmitriy Krichevskiy > <krichevskyd@gmail.com> 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/