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: AW: RE: AW: Identifying unique values with codebook

From   "Martin Weiss" <>
To   <>
Subject   st: AW: RE: AW: Identifying unique values with codebook
Date   Wed, 16 Jun 2010 16:24:38 +0200


A "string representation" seems to work with -codebook-, but not -inspect-
which claims to find o unique values...

inp str25 mystrvar


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Nick Cox
Gesendet: Mittwoch, 16. Juni 2010 16:13
Betreff: st: RE: AW: Identifying unique values with codebook

As Martin says, at root this is a precision problem. 

Neither -codebook- nor anything else is to blame if it is presented with
the same values. To hold very large integers you may need to consider
-long- as another possibility, or even a string representation. 


Martin Weiss

As -help data_types- says: "doubles have 16 digits of accuracy." So you
increase the digits of your "y" up to the point where even -double- can
nothing for you:

set obs 10
gen byte x=_n
codebook x
gen double y1 = 1000000000000000 + x
gen double y2 = 10000000000000000 + x
gen double y3 = 100000000000000000 + x
gen double y4 = 1000000000000000000 + x
codebook y?
ins y?

Interestingly, -inspect- seems to differ from -codebook-`s opinion.

Walter Garcia-Fontes

I stumped into a problem when identifying unique values of a numeric
variable using "codebook": if the values are large they will be
identified as the same value.  

For instance I have a variable x with the following values:
0, 1, 2, ... 10 (that is 10 different values)

codebook x 
reports "unique values: 10"

Now do 
gen y = 100000000000000000 + x

codebook y
reports "unique values = 1"

Is this a feature?

*   For searches and help try:

*   For searches and help try:

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