Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Benford's Law


From   "Michael Levitan" <michael.levitan@villanova.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Benford's Law
Date   Wed, 30 Nov 2005 10:37:38 -0500

Many thanks to Nick, Svend and Al for their attention to this.

            Michael

Nick Winter wrote:

One option:

gen firstdigit = int( x / 10^int(log10(abs(x))) )

This works for positive and negative numbers. It generates missing for x==0, and it generates 0 for -1<x<1.

--Nick WInter

At 09:23 AM 11/30/2005, you wrote:


Michael wrote:
Does anyone have an easy way to identify the leading digit for each
entry in a diverse data set other than a series of inequality filters?
--------------------------------------------------

If you convert numbers to strings it is easy to identify the first
digit, as shown here:

clear
set obs 100
gen x = int(1000*uniform())
gen str10 xstr = string(x , "%6.0f")
gen strx1 = substr(xstr,1,1)
destring strx1 , generate(x1)

Hope this helps
Svend
__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: sj@soci.au.dk
__________________________________________

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

________________________________________________________
Nicholas J. G. Winter                     607.255.8819 t
Assistant Professor                       607.255.4530 f
Department of Government              nw53@cornell.edu e
Cornell University        falcon.arts.cornell.edu/nw53 w
308 White Hall
Ithaca, NY 14853-4601

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index