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: Errors, lack if precision in carrying out operations forsome observations


From   "Jan Keil" <keilj051@newschool.edu>
To   <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Errors, lack if precision in carrying out operations forsome observations
Date   Sun, 15 May 2011 13:44:17 -0400

Thank you, Daniel.
It worked. 


>>> Daniel Feenberg <feenberg@nber.org> 05/15/11 11:05 AM >>>

On Sun, 15 May 2011, Jan Keil wrote:

> Dear Statalist,
>
> I have the following problem:
>
> Stata/SE 10.1 (Mac) does not undertake a simple operation on all of the 500,000 observations in my file (or does it with errors or not in a precise way).
>
> I have 2 numeric variables, "gvkey" and "sid" (among others in the file) that are used to create a third, "id".
>
> The commands are:
>
> gen id = .
> format id sid gvkey %16.2f
> replace id = gvkey*1000 + sid
>
>
> The result is that for some observations/rows the "id" variable is not calculated in a correct way.
> Two examples are:
>
>          id     gvkey    sid
> 31567000.00  31567.00   1.00
> 119653096.00 119653.00  99.00
>
> The values for "id" should be instead:
>
>          id     gvkey   sid
> 31567001.00  31567.00  1.00
> 119653099.00 119653.00 99.00
>
>

Try

   . generate double id = .

a -float- has only 5 or 6 digits of precision, the -format- doesn't affect 
the internal storage, only external representation.

Daniel Feenberg
*
*   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