Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: Tostring (string from a numerical variable)


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: Tostring (string from a numerical variable)
Date   Wed, 17 Mar 2010 18:02:50 +0100

<>

But the connection to the "-" sign is simply not there. Your code with a
positive large number causes the exact same effects:


*************
clear
set obs 1
gen double x = 123456789123456
tostring x, gen(strx)
tostring x, gen(strx) format(%17.0g)
*************


HTH
Martin


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Scott Merryman
Sent: Mittwoch, 17. März 2010 17:58
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: Tostring (string from a numerical variable)

There is no problem with negative signs.  Is var_1 a large number?  Compare:

clear
set obs 1
gen x = -100
tostring x, gen(strx)
clear
set obs 1
gen double x = -123456789123456
tostring x, gen(strx)
tostring x, gen(strx) format(%17.0g)

If you -set trace on- on the -tostring- that fails, you will see it
appears to default to %12.0g format - which is too small in this case:

  - else {
  - local fmt "%12.0g"
  - local format `", "%12.0g""'
  - }

Scott

On Wed, Mar 17, 2010 at 11:36 AM, carmen gamarra
<carmengamarra@hotmail.com> wrote:
>
>  Hi people,
> I wanna generate a variable string from a numerical variable that  has
negative signe (in front of the number). Is this possible? Because  Stata
gives me the following message.
>
>  (tostring  var_1, generate( var_1str)) var_1 cannot be converted
reversibly; no generate.
>
>  What must I do? Thanks in advance
>
> carmen

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index