UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Elementary Survey Sampling, 5th Edition by Scheaffer, Mendenhall and Ott
Chapter 8: Cluster sampling

Page 294, Table 8.1 and example 8.2
use "A:\table81.dta", clear
rename col1 cluster
rename col2 m
rename col3 y
list
     +--------------------+
     | cluster    m     y |
     |--------------------|
  1. |       1    8    96 |
  2. |       2   12   121 |
  3. |       3    4    42 |
  4. |       4    5    65 |
  5. |       5    6    52 |
     |--------------------|
  6. |       6    6    40 |
  7. |       7    7    75 |
  8. |       8    5    65 |
  9. |       9    8    45 |
 10. |      10    3    50 |
     |--------------------|
 11. |      11    2    85 |
 12. |      12    6    43 |
 13. |      13    5    54 |
 14. |      14   10    49 |
 15. |      15    9    53 |
     |--------------------|
 16. |      16    3    50 |
 17. |      17    6    32 |
 18. |      18    5    22 |
 19. |      19    5    45 |
 20. |      20    4    37 |
     |--------------------|
 21. |      21    6    51 |
 22. |      22    8    30 |
 23. |      23    7    39 |
 24. |      24    3    47 |
 25. |      25    8    41 |
     +--------------------+

tabstat m y, s(sum)

   stats |         m         y
---------+--------------------
     sum |       151      1329
------------------------------
Page 295
NOTE:  Use the y-bar as calculated in the middle of page 295, not the mean of income (y) shown in the table.
display 53.16/6.04

8.8013245
gen diff = (y - 8.801*m)
tabstat m y diff, s(n mean median sd)
   stats |         m         y      diff
---------+------------------------------
       N |        25        25        25
    mean |      6.04     53.16  .0019601
     p50 |         6        49      .995
      sd |  2.371357  21.78432  25.18887
----------------------------------------
Page 296, the table at the top
tabstat y m, s(n mean sd)
   stats |         y         m
---------+--------------------
       N |        25        25
    mean |     53.16      6.04
      sd |  21.78432  2.371357
------------------------------
corr y m
(obs=25)

             |        y        m
-------------+------------------
           y |   1.0000
           m |   0.3031   1.0000
Page 296, Figure 8.1
scatter y m, xlabel(2(2)12) ylabel(35 70 105) 

Page 309
use "A:\table82.dta", clear
rename col1 cluster
rename col2 m
rename col3 a
tabstat m a, s(sum)
   stats |         m         a
---------+--------------------
     sum |       151        72
------------------------------
di 72/151

.47682119
gen diff = a - (.48*m)
list
     +--------------------------+
     | cluster    m   a    diff |
     |--------------------------|
  1. |       1    8   4     .16 |
  2. |       2   12   7    1.24 |
  3. |       3    4   1    -.92 |
  4. |       4    5   3      .6 |
  5. |       5    6   3     .12 |
     |--------------------------|
  6. |       6    6   4    1.12 |
  7. |       7    7   4     .64 |
  8. |       8    5   2     -.4 |
  9. |       9    8   3    -.84 |
 10. |      10    3   2     .56 |
     |--------------------------|
 11. |      11    2   1     .04 |
 12. |      12    6   3     .12 |
 13. |      13    5   2     -.4 |
 14. |      14   10   5      .2 |
 15. |      15    9   4    -.32 |
     |--------------------------|
 16. |      16    3   1    -.44 |
 17. |      17    6   4    1.12 |
 18. |      18    5   2     -.4 |
 19. |      19    5   3      .6 |
 20. |      20    4   1    -.92 |
     |--------------------------|
 21. |      21    6   3     .12 |
 22. |      22    8   3    -.84 |
 23. |      23    7   4     .64 |
 24. |      24    3   0   -1.44 |
 25. |      25    8   3    -.84 |
     +--------------------------+
tabstat m a diff, s(n mean median sd)
   stats |         m         a      diff
---------+------------------------------
       N |        25        25        25
    mean |      6.04      2.88    -.0192
     p50 |         6         3       .12
      sd |  2.371357  1.508863    .72628
----------------------------------------
tabstat m, s(sum)
    variable |       sum
-------------+----------
           m |       151
------------------------
di 151/25
6.04
Page 310
tabstat a m, s(n mean sd)
   stats |         a         m
---------+--------------------
       N |        25        25
    mean |      2.88      6.04
      sd |  1.508863  2.371357
------------------------------
corr a m
(obs=25)

             |        a        m
-------------+------------------
           a |   1.0000
           m |   0.8864   1.0000
Page 310, Figure 8.2
scatter a m, xlabel(2(2)12) ylabel(0(2.5)7.5)

How to cite this page

Report an error on this page

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