Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: The command "gentrun"


From   "Alexander Kalb" <kalb@zew.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: The command "gentrun"
Date   Thu, 18 Sep 2008 17:34:03 +0200

I am using the command "gentrun" to generate random draws form a
truncated standard normal distribution. The command uses the program
"gentrun.ado":

program define gentrun
   tempvar tem1
   tempname mltrn mrtrn
   if "`left'" != "" & "`right'" != "" {
      if `left' >= `right' {
         di in red /*
    */ "The left truncation point cannot be >= the right truncation
point."
         exit 198
      }
   }
     if "`left'" == ""{
         scalar `mltrn' = 0
     }
     else {
         scalar `mltrn' = normprob(`left')
     }
     if "`right'" == ""{
         scalar `mrtrn' = 1
     }
     else {
         scalar `mrtrn' = normprob(`right')
     }
    tokenize `varlist'
    while "`1'" ~= ""{
        quie gen double `tem1' = (`mrtrn'-`mltrn')*uniform() + `mltrn'
`if' `in'
        quie gen `typlist' `1' = invnorm(`tem1') `if' `in'
        drop `tem1'
        mac shift
    }
end

Now, I have the following question: if I would like to have a random
draw from a truncated normal distribution with zero mean and standard
deviation 1.5 do I just have to replace the line "quie gen `typlist' `1'
= invnorm(`tem1') `if' `in'" of the .ado-file with "quie gen `typlist'
`1' = invnorm(`tem1')*1.5 `if' `in'"?

Zentrum für Europäische Wirtschaftsforschung GmbH (ZEW) 
Centre for European Economic Research 
L 7, 1 · 68161 Mannheim · Germany 
Sitz der Gesellschaft: Mannheim · Amtsgericht Mannheim HRB 6554 
Aufsichtsratsvorsitzender: Gerhard Stratthaus MdL, Finanzminister a.D. 
Geschaeftsfuehrer: Prof. Dr. Dr. h.c. mult. Wolfgang Franz, Thomas Kohl
------------------------------------------------------------------------
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index