Skip to Main Content

Elementary Survey Sampling, 5th Ed, by Scheaffer, Mendenhall and Ott, Chapter 4: Simple random sampling | Stata Textbook Examples

Chapter 4: Simple random sampling

Page 89, Table 4.4

use "a\:table44.dta", clear
list
     +------+
     | col1 |
     |------|
  1. | 33.5 |
  2. |   32 |
  3. |   52 |
  4. |   43 |
  5. |   40 |
     |------|
  6. |   41 |
  7. |   45 |
  8. | 42.5 |
  9. |   39 |
     +------+

Page 89

tabstat col1, s(mean var)
    variable |      mean  variance
-------------+--------------------
        col1 |  40.88889  35.67361
----------------------------------

Figure 4.1, page 90

graph hbox col1, ytitle('Amount')
ess5statach41

Page 102, Table 4.5

use "a:\table46.dta", clear
rename col1 make
rename col2 model
rename col3 size
rename col4 price
rename col5 mpg
rename col6 hp
drop if size == .
list
     +----------------------------------------------------+
     |       make        model   size   price   mpg    hp |
     |----------------------------------------------------|
  1. |      Acura      Integra      1    15.9    31   140 |
  2. |      Dodge         Colt      1     9.2    33    92 |
  3. |      Honda        Civic      1    12.1    46   102 |
  4. |    Hyundai        Excel      1       8    33    81 |
  5. |      Mazda          323      1     8.3    37    82 |
     |----------------------------------------------------|
  6. | Mitsubishi       Mirage      1    10.3    33    92 |
  7. |     Subaru        Justy      1     8.4    37    73 |
  8. |     Suzuki        Swift      1     8.6    43    70 |
  9. |     Toyota       Tercel      1     9.8    37    82 |
 10. | Volkswagen          Fox      1     9.1    33    81 |
     |----------------------------------------------------|
 11. |  Chevrolet      Corsica      2    11.4    34   110 |
 12. |   Chrysler      LeBaron      2    15.8    28   141 |
 13. |       Ford        Tempo      2    11.3    27    96 |
 14. |      Mazda          626      2    16.5    34   164 |
 15. |     Subaru       Lagacy      2    19.5    30   130 |
     |----------------------------------------------------|
 16. |        BMW         535i      3      30    30   208 |
 17. |  Chevrolet       Lumina      3    15.9    29   110 |
 18. |      Dodge      Dynasty      3    15.6    27   100 |
 19. |       Ford       Taurus      3    20.2    30   140 |
 20. |    Hyundai       Sonata      3    13.9    27   128 |
     |----------------------------------------------------|
 21. |      Lexus        SC300      3    35.2    23   225 |
 22. | Mitsubishi     Diamante      3    26.1    24   202 |
 23. |     Nissan       Maxima      3    21.5    26   160 |
 24. |    Pontiac   Grand_Prix      3    18.5    27   200 |
 25. |     Toyota        Camry      3    18.2    29   130 |
     |----------------------------------------------------|
 26. |      Volvo          850      3    26.7    28   168 |
     +----------------------------------------------------+
sort size
by size: tabstat price mpg hp, s(n mean p50 sd semean)
_______________________________________________________________________________
-> size = 1

   stats |     price       mpg        hp
---------+------------------------------
       N |        10        10        10
    mean |      9.97      36.3      89.5
     p50 |      9.15        35        82
      sd |  2.408342  4.854551  20.07901
se(mean) |  .7615846  1.535144  6.349541
----------------------------------------

_______________________________________________________________________________
-> size = 2

   stats |     price       mpg        hp
---------+------------------------------
       N |         5         5         5
    mean |      14.9      30.6     128.2
     p50 |      15.8        30       130
      sd |   3.52633  3.286335  26.53677
se(mean) |  1.577023  1.469694   11.8676
----------------------------------------

_______________________________________________________________________________
-> size = 3

   stats |     price       mpg        hp
---------+------------------------------
       N |        11        11        11
    mean |  21.98182  27.27273       161
     p50 |      20.2        27       160
      sd |  6.716371  2.284334  42.86024
se(mean) |  2.025062  .6887526  12.92285
----------------------------------------

Page 103, Figure 4.2

graph hbox mpg, by(size) ytitle("Highway mpg") ylabel(24(6)42)
 ess5statach42