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...
***********
clear*
set obs 10000
cap ssc inst gentrun
gentrun mynewvar, l(-1)
su
egen float mystdvar = std(mynewvar), mean(0) std(1.5)
su
***********
HTH
Martin
-----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
"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/
*
* 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/