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 use 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). In this example that the
default number of coins is one and the default probability of tossing heads is .5.
heads, flips(100)![]()
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.
heads, flips(50) prob(.3)
![]()
The following shows the results of 100 tosses of five coins with a probability of
heads of .3.
heads, flips(100) coins(5) prob(.3)
![]()
Finally we show the results of 500 tosses of two coins with a probability of
heads of .5 (the default) with the 95% confidence interval.
Notice that the width of the confidence interval narrows as the number of trials
increases.heads, flips(500) coins(2) ci
![]()