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

Re: st: Converting strings to Numerics


From   Tim Wade <[email protected]>
To   [email protected]
Subject   Re: st: Converting strings to Numerics
Date   Tue, 23 Dec 2003 11:05:02 -0800 (PST)

Try using "subinstr"
e.g., 

. replace string=subinstr(string, ",", "", .)
(1 real change made)

. replace str=subinstr(string, ">", "", .)
(1 real change made)

. gen real=real(string)
(1 missing value generated)


. list

     +-------------------+
     |     str      real |
     |-------------------|
  1. |     5.3       5.3 |
  2. |   hello         . |
  3. |       2         2 |
  4. | 2500000   2500000 |
     +-------------------+

. 


--- "Fultz, Shawn" <[email protected]> wrote:
> I am trying to convert a series of string variables
> to numeric variables.
> Because some of the numbers contain commas, the
> real() function does not
> work, instead returning a missing value.
> 
> What I get
> String    Number
> 5.3        5.3
> hello    	 .
> >2       	 .
> 2,500,000    .
> 
> What I want to get
> String	Number
> 5.3		5.3
> hello		.
> >2		2
> 2,500,000	2500000
> 
> Is there any way to extract a numeric value from the
> string variable?
> 
> Thanks,
> Shawn
> *
> *   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/


=====
[email protected]

__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index