Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: string to numeric(non-numeric)


From   "Raphael Fraser" <[email protected]>
To   [email protected]
Subject   Re: st: RE: string to numeric(non-numeric)
Date   Thu, 10 Apr 2008 10:22:51 -0500

That's because the syntax is not properly specified. You must tell
destring to remove the comma then convert from str to num by using the
ignore option. See example below. If other characters were involved
like dollar sign, comma and period, you would specified: ignore("$ ,
.")

clear
input str10 malepop
"45,623"
""
"67,345,119"
""
""
"3406"
"56,670,986"
""
end

desc
destring malepop, gen(newvar) ignore(",")
desc

Hope this helps


On Mon, Apr 7, 2008 at 5:39 AM, Gauri Khanna <[email protected]> wrote:
> **Sorry for cross posting - having trouble with messages to Statalist.**
>
>  Dear Stata list,
>
>  I am trying to convert a string variable(malespop) to a numeric variable.
>  I tried to the following:
>
>  -destring malespop, generate(MalesNum)-
>  -destring malespop, replace
>  -destring males, gen(MalesNum) ignore(" ")
>
>  but with each of these I got the following error:
>
>  - malespop contains non-numeric characters; no generate-
>
>  I tried to use -mvencode- but that did not work too. I tried -gen MalesNum=real(malespop) but got missing values for all entries!
>
>  My data looks like this and has blanks in between for no values:
>
>  SNo. malespop
>
>  1. 45,623
>  2.
>  3. 67,345,119
>  4.
>  5.
>  6. 3406
>  7. 56,670,986
>  8.
>
>  I am trying to create a column total of malespop using -egen total- command and for more calculation.
>
>  Grateful for your advice.
>
>  Gauri Khanna
>
>
>
>  _________________________________________________________________
>  Connect to the next generation of MSN Messenger
>  http://imagine-msn.com/messenger/launch80/default.aspx?locale=en-us&source=wlmailtagline
>  *
>  *   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index