Skip to Main Content

Elementary Survey Sampling, 5th Edition by Scheaffer, Mendenhall and Ott Chapter 6: Ratio, regression and difference estimation | Stata Textbook Examples

Page 202, Table 6.1

use "a:table61.dta", clear
rename col1 home
rename col2 x
rename col3 y
tabstat x y, s(sum)
display 164.7/154.5
gen diff = (y - x*1.066)
list
. tabstat x y, s(sum)

   stats |         x         y
---------+--------------------
     sum |     154.5     164.7
------------------------------

display 164.7/154.5
1.0660194

gen diff = (y - x*1.066)

list

     +------------------------------+
     | home     x     y        diff |
     |------------------------------|
  1. |    1   6.7   7.1   -.0421999 |
  2. |    2   8.2   8.4   -.3412002 |
  3. |    3   7.9   8.2   -.2214003 |
  4. |    4   6.4   6.9       .0776 |
  5. |    5   8.3   8.4   -.4478006 |
     |------------------------------|
  6. |    6   7.2   7.9    .2248003 |
  7. |    7     6   6.5        .104 |
  8. |    8   7.4   7.6   -.2884002 |
  9. |    9   8.1   8.9    .2653992 |
 10. |   10   9.3   9.9   -.0138006 |
     |------------------------------|
 11. |   11   8.2   9.1    .3588006 |
 12. |   12   6.8   7.3       .0512 |
 13. |   13   7.4   7.8   -.0883999 |
 14. |   14   7.5   8.3    .3050002 |
 15. |   15   8.3   8.9    .0521994 |
     |------------------------------|
 16. |   16   9.1   9.6      -.1006 |
 17. |   17   8.6   8.7   -.4676006 |
 18. |   18   7.9   8.8    .3786001 |
 19. |   19   6.3     7    .2841998 |
 20. |   20   8.9   9.4      -.0874 |
     +------------------------------+
tabstat x y diff, s(n mean p50 sd)
   stats |         x         y      diff
---------+------------------------------
       N |        20        20        20
    mean |     7.725     8.235  .0001499
     p50 |       7.9      8.35  .0186997
      sd |   .946948  .9571201  .2599956
----------------------------------------

Page 202, Figure 6.1

scatter y x, ylabel(6 8 10) xlabel(6.4(.8)8.8)
Image ess5statach61

Page 204, at the top

tabstat x y, s(n mean sd)
   stats |         x         y
---------+--------------------
       N |        20        20
    mean |     7.725     8.235
      sd |   .946948  .9571201
------------------------------
correlate x y
(obs=20)

             |        x        y
-------------+------------------
           x |   1.0000
           y |   0.9664   1.0000

Page 205, Table 6.2

use "a:table62.dta", clear
rename col1 orange
rename col2 y
rename col3 x
tabstat x y, s(sum)
gen r = (.246/4.35)*x
gen diff = y - r
list orange y x diff
. tabstat x y, s(sum)

   stats |         x         y
---------+--------------------
     sum |      4.35      .246
------------------------------

gen r = (.246/4.35)*x

gen diff = y - r

list orange y x diff

     +---------------------------------+
     | orange      y     x        diff |
     |---------------------------------|
  1. |      1   .021    .4   -.0016207 |
  2. |      2    .03   .48    .0028552 |
  3. |      3   .025   .43    .0006828 |
  4. |      4   .022   .42   -.0017517 |
  5. |      5   .033    .5    .0047241 |
     |---------------------------------|
  6. |      6   .027   .46    .0009862 |
  7. |      7   .019   .39   -.0030552 |
  8. |      8   .021   .41   -.0021862 |
  9. |      9   .023   .42   -.0007517 |
 10. |     10   .025   .44    .0001172 |
     +---------------------------------+
tabstat y x diff, s(n mean p50 sd)
   stats |         y         x      diff
---------+------------------------------
       N |        10        10        10
    mean |     .0246      .435  3.73e-10
     p50 |      .024      .425 -.0003172
      sd |  .0043767  .0353553  .0024105
----------------------------------------

Page 205, at the bottom

display (.246/4.35)*1800
101.7931

Figure 6.2, page 206

scatter y x, ylabel(.024 .032) xlabel(.4(.025).5)
Image ess5statach62