Skip to Main Content

Stata Teaching Tools:  Card playing simulation

Purpose:  The purpose of this program is to simulate
several card playing situations.  The user can select the number of cards drawn and
can also choose to play blackjack.  This program is useful for demonstrating
probability for playing card problems. 

Download:  You can download this program from within Stata by
typing search cards (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 cards in the
Stata command window.  This will open a dialogue window with a number of
buttons, a pull-down menu that allows the user to select the number of cards,
and two radio-buttons to select sampling witha and without replacement.

The results
of selections made in the dialogue window will be displayed in the results
window the user clicks
on any of the buttons.  To exit the program, click on the
"Done" button. 

Image dialog

Examples:  The following shows the output from clicking on the "Draw"
button three times with the "w/o replacement" option.

                              [click "Draw"]
        9  of Clubs                
     King  of Diamonds
     King  of Spades  
        3  of Spades  
        8  of Clubs   
                              [click "Draw"]
      ACE  of Diamonds
     King  of Hearts  
        6  of Diamonds
       10  of Clubs   
        4  of Diamonds
                              [click "Draw"]
        7  of Diamonds
        6  of Spades  
       10  of Hearts  
     Jack  of Diamonds
     Jack  of Spades  
     

Next, we will select the "w/ replacement" option and click on
the "wDraw" button three more time

                              [click "Draw"]
        2  of Diamonds
2 of Spades
2 of Hearts
2 of Spades
3 of Hearts
[click "Draw"] 6 of Spades
Jack of Clubs
Jack of Clubs
King of Spades
Jack of Hearts
[click "Draw"] ACE of Spades
ACE of Clubs
3 of Diamonds
10 of Diamonds
8 of Spades

Note that the 2 of Spades appears twice in the first hand of five cards and that the
Jack of Clubs appears twice in the second hand

We can change the number of cards using the pull-down menu for "n = ".
Let’s try it with 13 cards.

                             [click "Blackjack"]
        2  of Clubs   
        6  of Clubs   
        3  of Hearts  
        9  of Hearts  
       10  of Hearts  
        2  of Hearts  
     Jack  of Diamonds
        6  of Clubs   
        7  of Spades  
        5  of Diamonds
        8  of Spades  
     Jack  of Diamonds
        6  of Clubs   
                             [click "Blackjack"]
        7  of Hearts  
     Jack  of Diamonds
        6  of Clubs   
    Queen  of Clubs   
        9  of Clubs   
        2  of Spades  
        8  of Clubs   
        9  of Clubs   
        2  of Hearts  
        9  of Spades  
     Jack  of Spades  
        4  of Clubs   
        6  of Clubs 

Now let’s play blackjack. Click on the "Blackjack" button to deal your
hand. You may then choose to receive another card by clicking the "Hit Me"
button. When you are staisfied with your hand click on the "Stand" button
to see what the dealer’s hand is.

                             [click "Blackjack"]
Blackjack
You draw
        4  of Clubs   
        9  of Spades  
Your total is 13
                             [click "Hit Me"]
Your card is 
        3  of Clubs   
Your total is 16
                             [click "Stand"]
Dealer draws 
      ACE  of Hearts  
    Queen  of Spades  
Dealer's total is 21
Dealer wins