Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: Counter-intuitive overflow behavior

From   "Roger B. Newson" <>
To   "" <>
Subject   st: Counter-intuitive overflow behavior
Date   Mon, 27 Feb 2012 21:01:03 +0000

I have a query about -c(mindouble)- and -c(maxdouble)- (see -help creturn- for more about these). I am currently using Stata/MP Version 12.1 (current update level: 06 Feb 2012, which is up to the minute according to -update query-), and I have noticed some very counter-intuitive behavior when I attempt to assign variables of type -double- to values outside the range from -c(mindouble)- to -c(maxdouble)-, which (according to -help creturn-) are "the largest negative number that can be stored in the 8-byte double storage type" and "the largest positive number that can be stored in a double", respectively.

In the -auto- data, if I type

gene double dopey=c(mindouble)-c(maxdouble)

then Stata does its work without error or warning. And, when I then type

tab dopey, m

then Stata replies with

      dopey |      Freq.     Percent        Cum.
  -1.8e+308 |         74      100.00      100.00
      Total |         74      100.00

This is curious, because, when I type

disp c(mindouble)

Stata gives the value of -8.99e+307, implying that -dopey- contains a negative value of about twice the magnitude that Stata is supposed to allow.

On the other hand, when I type

gene double doc=c(maxdouble)-c(mindouble)

then Stata warns me with

(74 missing values generated)

and when I then type

tab doc, m

then Stata replies with

        doc |      Freq.     Percent        Cum.
        .z_ |         74      100.00      100.00
      Total |         74      100.00

suggesting that the variable -doc- contains a missing value that I haven't seen mentioned in -help missing-. And what is even more curious is that, if I type

gene double bashful=.z_

then Stata responds with the error message

invalid matrix stripe;

and doesn't generate the new variable requested. This is in contrast to what happens when I generate a new -double- variable with a publicized missing value. As in:

gene double grumpy=.z

to which Stata replies (as expected) with

(74 missing values generated)

and, when I then type

tab grumpy, m

then Stata replies with

     grumpy |      Freq.     Percent        Cum.
         .z |         74      100.00      100.00
      Total |         74      100.00

(again as expected).

Is this counterintuitive behavior a bug or a feature? I have always assumed that -c(mindouble)- and -c(maxdouble)- are as advertized, and that we can assume that non-missing -double- values can be expected to be in the closed interval between these 2 limits. This doesn't seem to be the case.

Best wishes


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
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Web page:
Departmental Web page:

Opinions expressed are those of the author, not of the institution.
*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index