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]
Re: st: problem converting a string variable to a numeric variable
From
Gwinyai Masukume <[email protected]>
To
[email protected]
Subject
Re: st: problem converting a string variable to a numeric variable
Date
Thu, 25 Apr 2013 19:34:03 +0200
Dear Roger,
generate x = real(y)
Works like a charm. Thanks.
Kind regards,
Gwinyai
On 4/25/13, Roger B. Newson <[email protected]> wrote:
> I think you need -destring- here. Type -help destring- to find out more.
>
> Or you might even want to type
>
> gene weightgrams=real(weight)
>
> which may have the same effect, if your string values are all
> well-formed numbers with no commas or other awkward characters.
>
> Best wishes
>
> Roger
>
> Roger B Newson BSc MSc DPhil
> Lecturer in Medical Statistics
> Respiratory Epidemiology and Public Health Group
> National Heart and Lung Institute
> Imperial College London
> Royal Brompton Campus
> Room 33, Emmanuel Kaye Building
> 1B Manresa Road
> London SW3 6LR
> UNITED KINGDOM
> Tel: +44 (0)20 7352 8121 ext 3381
> Fax: +44 (0)20 7351 8322
> Email: [email protected]
> Web page: http://www.imperial.ac.uk/nhli/r.newson/
> Departmental Web page:
> http://www1.imperial.ac.uk/medicine/about/divisions/nhli/respiration/popgenetics/reph/
>
> Opinions expressed are those of the author, not of the institution.
>
> On 25/04/2013 18:17, Gwinyai Masukume wrote:
>> Dear Stata listers,
>>
>> I have a variable weight. The original dataset has weight as a string
>> variable. Type - str13
>> Format - %13s.
>>
>> encode weight, generate(weightgrams)
>>
>> The above code apparently creates a numeric variable weightgrams.
>> Type - long
>> Format - %13.0g
>>
>> However when dealing with this new variable e.g summ weightgrams, I get
>> completely abnormal results which bear no resemblance to the expected
>> results for the variable weight.
>>
>> I suspect there is some kind of error in conversion from a string to
>> numeric variable.
>>
>> I am using version 12.1
>>
>> Kind regards,
>> Gwinyai
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/