.-
help for ^gentrun^
.-

Generate random draws from a truncated standard normal distribution - -------------------------------------------------------------------

^gentrun^ newvarname [^if^ exp] [^in^ range] [^, l^eft^(^#^)^] [^r^ight^(^#^)^]

Description - -----------

^gentrun^ generates random draws from a truncated standard normal distribution. It allows one-sided and two-sided truncations of the distribution. Random draws from a non-truncated standard normal distribution are also permissible.

Options - -------

^l^eft^(^#^)^ specifies the left truncation point. ^r^ight^(^#^)^ specifies the right truncation point.

When only the option ^l^eft^(^#^)^ is specified, the random variable is generated from the conditional distribution f( x | x>=#).

When only the option ^r^ight^(^#^)^ is specified, the random variable is generated from the conditional distribution f( x | x<=#).

If both ^l^eft^(^#1^)^ and ^r^ight^(^#2^)^ are specified, the random variable is generated from the conditional distribution f( x | #1<=x<=#2).

If neither of the options is specified, it is the same as generating random draws from a non-truncated standard normal distribution. In this case, using ^invnorm(uniform())^ should be faster.

The default variable type of the generated variable is float. You can also specify ^double^ as the variable type:

. ^gentrun douoble^ z, [your options here...]

Examples - --------

. set obs 1000 . set seed 1234567

. ^gentrun double w, left(0)^ . sum w

Variable | Obs Mean Std. Dev. Min Max - ---------+----------------------------------------------------- w | 1000 .7817681 .6108022 .0014233 4.275502

. ^gentrun double x, right(0)^ . sum x

Variable | Obs Mean Std. Dev. Min Max - ---------+----------------------------------------------------- x | 1000 -.798516 .6146147 -3.535409 -.0020484

. ^gentrun double y, left(-0.2) right(0.2)^ . sum y

Variable | Obs Mean Std. Dev. Min Max - ---------+----------------------------------------------------- y | 1000 -.0007012 .1151341 -.1999372 .1995915

. ^gentrun double z^ . sum z

Variable | Obs Mean Std. Dev. Min Max - ---------+----------------------------------------------------- z | 1000 .0093139 .9889557 -2.988535 2.796945

Author - ------

Hung-Jen Wang The Institute of Economics Academia Sinica, Taipei, Taiwan hjwang@@ieas.econ.sinica.edu.tw