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]

From |
Nick Cox <njcoxstata@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: A bug in egen and gen? |

Date |
Thu, 17 Feb 2011 18:22:46 +0000 |

This isn't a bug. It may well bite you, but a better description is that you get what you ask for. The default default [intended] type for new numeric variables is -float-. As well documented, -float- can not hold sufficiently large integers accurately, which is precisely why -long- and -double- are available as alternatives. As well documented, both commands allow you to depart from the default. So Junlin already documented what is better practice, that you spell out that you want a -long-. The alternatives include 1. You always have to tell -generate-, etc. what variable type you want created. On the whole, I don't think that would be a popular change. 2. You write your own wrappers for -generate-, etc. that insist on variable type being specified. That is programmable. 3. Your attitude is that Stata should always be smart enough to work out what you want. Good luck on that one. Nick On Thu, Feb 17, 2011 at 6:09 PM, Liao, Junlin <junlin-liao@uiowa.edu> wrote: > I happen to notice a problem with the egen and gen commands. I'm using Stata 2011 SE (64 bit). I do not know if this problem exists in other versions. Please run the following commands to reproduce the problem: > > clear > set obs 5 > generate y=83085733 > generate long z=83085733 > egen y_mean=mean(y) > egen z_mean=mean(z) > egen long y_mean_long=mean(y) > egen long z_mean_long=mean(z) > format %10.0g y z y_mean z_mean y_mean_long z_mean_long > list > > By default, both egen and gen command use float for the size of the number and the values generated are not correct. However, if we restrict the numbers to be long integer, we can get correct results. > > Anybody else noticed the bug? Is there an explanation for what happens? Thanks, > * * 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/

**Follow-Ups**:**RE: st: A bug in egen and gen?***From:*"Liao, Junlin" <junlin-liao@uiowa.edu>

**Re: st: A bug in egen and gen?***From:*Stas Kolenikov <skolenik@gmail.com>

**References**:**st: A bug in egen and gen?***From:*"Liao, Junlin" <junlin-liao@uiowa.edu>

- Prev by Date:
**st: A bug in egen and gen?** - Next by Date:
**Re: re:st: pscore question** - Previous by thread:
**st: A bug in egen and gen?** - Next by thread:
**Re: st: A bug in egen and gen?** - Index(es):