UCLA Academic Technology Services HomeServicesClassesContactJobs
Help the Stat Consulting Group by giving a gift             
Loading

Stata Textbook Examples
Introduction to the Practice of Statistics by Moore and McCabe
Chapter 1: Looking at Data, Distributions

The examples presented in Chapter 1 involve several different datasets that appear more than once in different parts of the chapter. This web page follows each dataset throughout the whole chapter.

Newcomb's 66 measurements of the passage time of light

Table 1.1, page 8.

use http://www.ats.ucla.edu/stat/stata/examples/mm/chap01/ta01_001, clear

list

          time 
  1.        28  
  2.        26  
  3.        33  
  4.        24  
  5.        34  
[data omitted]
 62.        27  
 63.        28  
 64.        29  
 65.        16  
 66.        23  
Figure 1.5, page 17.
histogram time, bin(24) freq ylabel(0(5)30) xlabel(-60(20)60) 
Figure 1.6, page 19.
generate order = _n
graph twoway scatter time order, ylabel(-60(20)60) xlabel(0(10)70)
Babe Ruth home run data
Example 1.4, page 10.
use http://www.ats.ucla.edu/stat/stata/examples/mm/chap01/ex01_037, clear

drop if year < 1920
drop if year > 1934
list

          year        hrs 
  1.      1920         54  
  2.      1921         59  
  3.      1922         35  
  4.      1923         41  
  5.      1924         46  
  6.      1925         25  
  7.      1926         47  
  8.      1927         60  
  9.      1928         54  
 10.      1929         46  
 11.      1930         49  
 12.      1931         46  
 13.      1932         41  
 14.      1933         34  
 15.      1934         22  
Figure 1.2c, page 11.
stem hrs, round(1) lines(1)

Stem-and-leaf plot for hrs

hrs rounded to integers

  2* | 25
  3* | 45
  4* | 1166679
  5* | 449
  6* | 0
Example 1.12, page 41.
summarize hrs

Variable |     Obs        Mean   Std. Dev.       Min        Max
---------+-----------------------------------------------------
     hrs |      15    43.93333   11.24701         22         60 
Example 1.13, page 43. The median is the same as the 50th percentile which is displayed as 50% in Stata.
summarize hrs, detail

                             hrs
-------------------------------------------------------------
      Percentiles      Smallest
 1%           22             22
 5%           22             25
10%           25             34       Obs                  15
25%           35             35       Sum of Wgt.          15

50%           46                      Mean           43.93333
                        Largest       Std. Dev.      11.24701
75%           54             54
90%           59             54       Variance       126.4952
95%           60             59       Skewness      -.4827278
99%           60             60       Kurtosis       2.466472
Spending by 50 supermarket shoppers
Example 1.5, page 12.
use http://www.ats.ucla.edu/stat/stata/examples/mm/chap01/eg01_005, clear

list

        amount 
  1.      3.11  
  2.      8.88  
  3.      9.26  
  4.     10.81  
  5.     12.69  
[data omitted]
 46.     70.32  
 47.      82.7  
 48.     85.76  
 49.     86.37  
 50.     93.34  
Figure 1.3a, page 12.
stem amount, round(1)

Stem-and-leaf plot for amount

amount rounded to integers

  0* | 399
  1* | 1345677889
  2* | 000123455668888
  3* | 25699
  4* | 1345579
  5* | 0359
  6* | 1
  7* | 0
  8* | 366
  9* | 3
Figure 1.3b, page 12.
stem amount, round(1) lines(2)

Stem-and-leaf plot for amount

amount rounded to integers

  0* | 3
  0. | 99
  1* | 134
  1. | 5677889
  2* | 0001234
  2. | 55668888
  3* | 2
  3. | 5699
  4* | 134
  4. | 5579
  5* | 03
  5. | 59
  6* | 1
  6. | 
  7* | 0
  7. | 
  8* | 3
  8. | 66
  9* | 3
Example 1.15, page 45 and Five-Number Summary, page 48. This analysis uses data rounded to whole numbers using the round function in Stata. Note Q1 is given as 25% and Q3 as 75%.
generate ramount = round(amount,1)
summarize ramount, detail

                           ramount
-------------------------------------------------------------
      Percentiles      Smallest
 1%            3              3
 5%            9              9
10%         13.5              9       Obs                  50
25%           19             11       Sum of Wgt.          50

50%           28                      Mean              34.68
                        Largest       Std. Dev.      21.68272
75%           45             83
90%         65.5             86       Variance       470.1404
95%           86             86       Skewness       1.066941
99%           93             93       Kurtosis       3.511037
Figure 1.14, page 46. This analysis is on the unrounded data. The univar command is an ado which was down loaded from Stata. It can be found in Stata Technical Bulletin 51.
univar amount, detail

                                        -------------- Quantiles --------------
Variable       n     Mean     S.D.      Min      .25      Mdn      .75      Max
-------------------------------------------------------------------------------
  amount      50    34.70    21.70     3.11    19.27    27.85    45.40    93.34
-------------------------------------------------------------------------------
Figure 1.15, page 49.
graph box amount, ylabel(0(20)100)
Calories and sodium in three types of hot dogs
Table 1.8, page 40.
use http://www.ats.ucla.edu/stat/stata/examples/mm/chap01/ta01_008,clear

list

      beef_cal   beef_sod   meat_cal   meat_sod   poultry_   poultry1 
  1.       186        495        173        458        129        430  
  2.       181        477        191        506        132        375  
  3.       176        425        182        473        102        396  
  4.       149        322        190        545        106        383  
  5.       184        482        172        496         94        387  
  6.       190        587        147        360        102        542  
  7.       158        370        146        387         87        359  
  8.       139        322        139        386         99        357  
  9.       175        479        175        507        170        528  
 10.       148        375        136        393        113        513  
 11.       152        330        179        405        135        426  
 12.       111        300        153        372        142        513  
 13.       141        386        107        144         86        358  
 14.       153        401        195        511        143        581  
 15.       190        645        135        405        152        588  
 16.       157        440        140        428        146        522  
 17.       131        317        138        339        144        545  
 18.       149        319          .          .          .          .  
 19.       135        298          .          .          .          .  
 20.       132        253          .          .          .          .  
Figure 1.16, page 49.
graph box beef_cal meat_cal poultry_, ylabel(80(20)200)
Example 1.17, page 50
univar beef_cal meat_cal poultry_

 
                                        -------------- Quantiles --------------
Variable       n     Mean     S.D.      Min      .25      Mdn      .75      Max
-------------------------------------------------------------------------------
beef_cal      20   156.85    22.64   111.00   140.00   152.50   178.50   190.00
meat_cal      17   158.71    25.24   107.00   139.00   153.00   179.00   195.00
poultry_      17   122.47    25.48    86.00   102.00   129.00   143.00   170.00
-------------------------------------------------------------------------------
Stemplot, page 50
stem meat_cal

Stem-and-leaf plot for meat_cal

  10* | 7
  11* | 
  12* | 
  13* | 5689
  14* | 067
  15* | 3
  16* | 
  17* | 2359
  18* | 2
  19* | 015 
Example 1.23, page 74.
The zcalc command can be downloaded from UCLA ATS from within Stata (see How can I use the findit command to search for programs and get additional help? for more information about using findit).
zcalc 68 64.5 2.5
 
z-score for sample observations

      (X - m)       (68 - 64.5)
 z = ---------  =  ------------------  =  1.40
         s              2.5
Example 1.25, pages 76-77.
zcalc 240 170 30

z-score for sample observations

      (X - m)       (240 - 170)
 z = ---------  =  ------------------  =  2.33
         s              30
Figure 1.30, page 82.
use http://www.ats.ucla.edu/stat/stata/examples/mm/chap01/ta01_001, clear

qnorm time, ylabel(-40(20)40)
Figure 1.31, page 82.
keep if time > 0
qnorm time, ylabel(10(10)40)
Figure 1.32, page 83.
use http://www.ats.ucla.edu/stat/stata/examples/mm/chap01/eg01_005, clear

qnorm amount, ylabel(0(10)100)
Education data for 78 seventh-grade students.
Figure 1.33, page 83.
use http://www.ats.ucla.edu/stat/stata/examples/mm/chap01/ta01_006, clear

qnorm col3, ylabel(60(20)140)
Guinea pig survival data
Figure 1.34, page 84.
use http://ats.ucla.edu/stat/stata/examples/mm/chap01/ta01_005, clear

histogram survival, bin(12) xlabel(0(100)600) kdensity

How to cite this page

Report an error on this page or leave a comment

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California