Purpose: The purpose of this program is to simulate the tossing of a coin or coins and to display the results in the form of a graph with the probability of heads versus the number of trials. The user can alter the probability of obtaining heads and to display the 95% confidence interval on the graph. This program is useful for demonstrating the law of large numbers, in that as the number of trials increases, the mean probability of heads approaches the expected mean.
Download: You can download this program from within Stata by typing search heads (see How can I used the search command to search for programs and get additional help? for more information about using search).
Use of program: To use this program, type heads in the Stata command window. This will open a dialogue window with three pull-down menus that allows the user to select the number of tosses, the number of coins and the probability of obtaining heads. A Stata graph window is also opened, and a graph of the probability of obtaining heads versus the number of tosses is displayed. A check-box in the dialogue window allows the user to request 95% confidence intervals be displayed on the graph. The results of selections made in the dialogue window will be graphed when the user clicks on the "toss coins" button. To exit the program, click on the "done" button.
Examples: The following shows the output from issuing the heads command. Note that as the number of trials increases, the mean probability approaches .5, which is the expected probability of obtaining heads (assuming that a fair coin is being used).
The following shows the results of using 50 tosses of the coin with a probability of obtaining heads of .3. Notice that as the number of trials increases, the mean probability approaches .3.
The following shows the results of 50 tosses of five coins with a probability of heads of .3.
The following shows the results of 50 tosses of five coins with a probability of heads of .3 with the 95% confidence interval. Notice that the width of the confidence interval narrows as the number of trials increases.