sdist

sdist -- Simulate the central limit theorem

Syntax

sdist
[, samples(#) obs(#) type(string) par1(#) par2(#) round(#) histplot saveplot1(string) saveplot2(string) repplot combine lcolor(string) fcolor(string) bckg(string) nlcolor(string) nlwidth(#) nlpattern(string) dots]

samples(#) The number of random variables to generate. Default is 200.

obs(#) The number of observations per sample. Default is 500.

type(string) The type of distribution from which the random samples should be drawn. The default is type(uniform), which generates random samples from a rectangular uniform distribution. Normal and Poisson distributions are also available, indicated by type(normal) and type(poisson), respectively. The distributions are created through calls to Stata’s random number generators (StataCorp n.d.1).

par1(#) The first parameter to be specified depending on the distribution selected in type(). Since the default type() is the rectangular distribution, the default is the lower end of the [a,b) interval. The samples are generated through the runiform() function so the default for is 0, but this can be changed. If type(normal) is selected, this parameter is the mean, with a default of 0. This parameter does not specify anything if type(poisson) is selected; use par2(#) to specify the mean of the Poisson distribution instead.

par2(#) The second parameter to be specified depending on the distribution selected in type(). Since the default type() is the rectangular distribution, the default is the higher end of the [a,b) interval. The samples are generated through the runiform() function so the default for is (an approximation of) 1, but this can be changed. If type(normal) is selected, this parameter is the standard deviation, with a default of 1. If type(poisson) is selected, this parameter is the mean, also with a default of 0.

round(#) the decimal point to which the estimates should be rounded. The default is 0.001.

histplot Indicates whether or not histograms of the two frequency distributions should be plotted. The plots are generated through the histogram command (StataCorp n.d.2). Defaults to no histogram.

saveplot1(string) Indicates whether the first histogram should be saved and the name for the plot. Defaults to plot1.gph if repplot is specified but not saveplot1(). Ignored if histplot is not specified. The default is to not save the plot.

saveplot2(string) Serves the same purpose as saveplot1(), but with reference to the second histogram. Defaults to plot2.gph if repplot is specified but not saveplot2(). Ignored if histplot is not specified. The default is to not save the plot.

repplot Specifies whether or not the saved histograms should replace existing saved histograms in the same directory with the same name. repplot will default to saving both plots if neither saveplot1() nor saveplot2() is specified, using plot1.gph and plot2.gph as the file names, respectively. The default is to not replace plots.

combine Indicates whether or not the two histograms should be stacked to form a third plot. This is a call to the graph combine function (StataCorp n.d.4). Both histograms have to be saved in order for the graphs to be combined, either by specifying both saveplot1() and saveplot2() simultaneously or by specifying repplot without either saveplot options (though repplot can still be used in conjunction with both saveplot1() and saveplot2() if both are specified). Requiring that both saveplot1() and saveplot2() or repplot only be specified prevents the program from erroneously stacking histograms from different simulations. The default is to not stack the plots.

lcolor Indicates the outline color of the histogram bars. This is a call to the histogram function (StataCorp n.d.2). The default is black.

fcolor Indicates the interior color of the histogram bars. This is a call to the histogram function (StataCorp n.d.2). The default is gs6.

bckg Indicates the color of the graph region background. This is a call to the graphregion(fcolor()) argument within the histogram command (StataCorp n.d.3). The default is white.

nlcolor Indicates the color of the normal curve line. This is a call to the normopts(lcolor()) argument within the histogram command (StataCorp n.d.2). The default is black.

nlwidth Indicates the thickness of the normal curve line. This is a call to the normopts(lwidth()) argument within the histogram command (StataCorp n.d.2). The default is .5.

nlpattern Indicates the pattern of the normal curve line. This is a call to the normopts(lpattern()) argument within the histogram command (StataCorp n.d.2). The default is solid.

dots Indicates whether or not the program should show simulation progress using the _dots function. The default is no dots.

Description

sdist simulates the central limit theorem by generating a matrix of randomly generated normal or non-normal variables and comparing the true sampling distribution standard deviation to the standard error from the first randomly-generated sample. The user also has the option of plotting the empirical sampling distribution of sample means, the first random variable distribution, and a stacked visualization of the two distributions.

Remarks

For more detailed information on the random number generators in Stata, see [FN] Random-number functions.

Examples

. sdist

. sdist, samples(300) obs(400) round(.0001)

. sdist, samples(400) obs(400) type(poisson) dots

References

StataCorp. N.d.1. Random-number functions. College Station, TX: StataCorp LP. Accessed September 26, 2017 (https://www.stata.com/manuals13/m-5runiform.pdf).

StataCorp. N.d.2. histogram -- Histograms for continuous and categorical variables. College Station, TX: StataCorp LP. Accessed September 26, 2017 (https://www.stata.com/manuals13/rhistogram.pdf).

StataCorp. N.d.3. region_options -- Options for shading and outlining regions are controlling graph size. College Station, TX: StataCorp LP. Accessed September 26, 2017 (https://www.stata.com/manuals13/g-3region_options.pdf).

StataCorp. N.d.4. graph combine -- Combine multiple graphs. College Station, TX: StataCorp LP. Accessed September 26, 2017 (https://www.stata.com/manuals13/g-2graphcombine.pdf).

Author

Marshall A. Taylor, Department of Sociology, University of Notre Dame
mtaylo15@nd.edu