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

Re: st: RE: Problem with rndt - random # generator


From   [email protected]
To   [email protected]
Subject   Re: st: RE: Problem with rndt - random # generator
Date   Wed, 2 Oct 2002 15:58:41 EDT

Here is the version of rndt.ado that I have in my working file. I did  not 
have any problems running it. I'm not sure how you had lines disjoined. 

Joe Hilbe


==========================================================
*!version 1.1.1 2000 Joseph Hilbe
* version 1.0.0 1993 Joseph Hilbe            (sg44: STB-28)

* Student's t distribution random number generator (optional noncentral)

* Example: rndt 1000 10 3 [set obs 1000;  10 is the degrees of freedom;
*                          3 is the noncentrality ]

program define rndt
    version 3.1
    set type double
    cap drop xt
    qui     {
        local cases `1'
        set obs `cases'
        mac shift
        local df `1'
mac shift
local delta `1'
if "`delta'" != "" { local labl = "noncentral " }
else { local delta = 0 }
        tempvar ran1 z
        noi di in gr "( Generating " _c
        local i=1
            gen `z'=invnorm(uniform()) + `delta'
        gen `ran1'=0
        while `i'<=`df'  {
            replace `ran1' = `ran1'+ (invnorm(uniform()))^2
            local i=`i'+1
            noi di in gr "." _c 
        }
        gen xt = `z'/sqrt(`ran1'/`df')
        noi di in gr " )"
        noi di in bl "Variable " in ye "xt " in bl "created."
            lab var xt "`labl't random variable"
        set type float
    }
end
*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index