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

st: RE: The command "gentrun"

From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: The command "gentrun"
Date   Thu, 18 Sep 2008 17:53:33 +0200

First of all, -gentrun- takes us all the way back to -version- 6 -- which need not be a bad thing, but shows that the author has not released a new version since 1999. As far as I can tell, he is not active on the list, either.

On the question, with a truncation from either left or right, the mean of the sample will never be zero, and the standard deviation will be smaller than 1 due to the truncation of at least one of the tails.  I would be tempted to use -egen, std()- after the creation of the truncated normal to achieve the desired outcome, but then the truncation points will be shifted, which is probably not what you want...

set obs 10000
cap ssc inst gentrun
gentrun mynewvar, l(-1)
egen float mystdvar = std(mynewvar), mean(0) std(1.5)


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Alexander Kalb
Sent: Thursday, September 18, 2008 5:34 PM
To: [email protected]
Subject: st: The command "gentrun"

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

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
         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

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:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index