Bookmark and Share

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]

st: New Stata command truernd()


From   Sergiy Radyakin <[email protected]>
To   [email protected]
Subject   st: New Stata command truernd()
Date   Tue, 1 Feb 2011 20:08:01 -0500

Dear Statalist Members,

Thanks to Kit Baum, a new Stata package -truernd- is now available for
download from the SSC:

 . ssc install truernd
or
. findit truernd

Individual files and download statistics can be found here:
http://ideas.repec.org/c/boc/bocode/s457232.html


Description

truernd provides an interface to the true random number service
provided by the random.org website created by Mads Haahr. The
random.org web service samples atmospheric noise via radio tuned to an
unused broadcasting frequency together with a skew correction
algorithm due to John von Neumann. For details see
http://www.random.org/
Use of this command requires internet connection. Requesting random
numbers via this command does not affect the random number generator
of Stata itself (current seed).

There was an earlier discussion on Statalist regarding true random
numbers, where random.org was already mentioned:
http://www.stata.com/statalist/archive/2010-09/msg01473.html

The program posted here is used not to initialize the seed of the
built-in random generator, but rather to create a complete random
dataset or a random matrix. More importantly the program complies to
the requirements set forth in the Guidelines for Automated Clients as
described at random.org.

As a curiosity point: the program is compatible with Stata 7-11, and
uses exclusively built-in commands, which means that it has no
dependencies other than the website random.org.
Error codes and limits
    111 Syntax error
    990 Service responded with an error message
    991 Failed to retrieve random numbers from the server
    992 Quota exhausted
    993 Quota exhausted. Must wait before rechecking
    994 Matrix too large (rows*cols>10,000)
    995 Too many random values requested (count*n>10,000)
    996 Inconsistent parameters max and min (max<min)
    997 Parameter max is out of range [-1e9,1e9]
    998 Parameter min is out of range [-1e9,1e9]
    999 Too many random variables requested (n>10,000)
For other codes see Stata manual

Delays
    truernd conforms to the guidelines for automated clients as
described on the website. Mandatory delays between requests and during
the cooling off periods are enforced. It is not recommended for users
to attempt to override these protective mechanisms. The website
provides possibility to purchase additional quota once the limit is
reached: http://www.random.org/quota/
    min interval between requests for random numbers: 30 seconds
(program waits for remaining time during this mandatory interval)
    min interval between requests for quota when quota is negative: 10
minutes (error 993 is issued during this mandatory interval)

If you are creating a random dataset, you must start with an empty
dataset. Adding a random variable to the existing dataset is possible
with the following loop (2 options):

version 11.0

***** variant 1
sysuse auto, clear
preserve
local c = _N
clear
truernd , count(`c') n(1)
tempfile rnd
save `"`rnd'"'
restore
merge 1:1 _n using `"`rnd'"', nogenerate

***** variant 2
sysuse auto, clear
local c = _N
tempname A
matrix `A' = J(`c',1,.)
truernd , matrix(`A')
svmat `A', names("truernd_")

The first one is somewhat disk-intensive, so if you have a large
dataset, it may work slower
than the second. The second is more memory demanding - you may be in need to set
matsize to a larger than the default value (to be equal or larger than
the number of observations).
In both cases you may want to be careful about variable names. In the
first code you get v1...vn,
in the second - you get truernd_1

Let me know if you have any questions,
Sergiy Radyakin
Economist
Research Department (DECRG)
The World Bank
[email protected]
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index