UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Textbook Examples
Sampling: Design and Analysis by Sharon L. Lohr
Chapter 6: Sampling with Unequal Probabilities

Page 191, figure 6.1
use http://www.ats.ucla.edu/stat/stata/examples/lohr/statepop.dta, clear
gen psi = popn/255077536
scatter phys psi, ylabel( , nogrid angle(0)) ///
  ytitle("Physicians in County (in thousands)") 
gen x = phys/psi
histogram x, bin(15) freq ylabel(0(5)30) xlabel(0(1000000)3000000)
Page 191, table 6.3
list state county popn psi phys x in 1/7

     +-------------------------------------------------------------+
     | state         county      popn        psi   phys          x |
     |-------------------------------------------------------------|
  1. |    AL         Wilcox     13672   .0000536      4   74627.72 |
  2. |    AZ       Maricopa   2209567   .0086623   4320   498710.8 |
  3. |    AZ       Maricopa   2209567   .0086623   4320   498710.8 |
  4. |    AZ          Pinal    120786   .0004735     61   128820.6 |
  5. |    AR        Garland     76100   .0002983    131   439095.4 |
     |-------------------------------------------------------------|
  6. |    AR    Mississippi     55060   .0002159     48   222370.5 |
  7. |    CA   Contra_Costa    840585   .0032954   1761   534379.7 |
     +-------------------------------------------------------------+
     
list state county popn psi phys x in -4/l 

     +-------------------------------------------------------------+
     | state         county      popn        psi   phys          x |
     |-------------------------------------------------------------|
 97. |    VA   Chesterfield    225225    .000883    181   204990.7 |
 98. |    WA           King   1557537   .0061061   5280   864704.6 |
 99. |    WI        Lincoln     27822   .0001091     28   256709.5 |
100. |    WI       Waukesha    320306   .0012557    687   547096.4 |
     +-------------------------------------------------------------+
     
tabstat x, s(mean sd)

    variable |      mean        sd
-------------+--------------------
           x |  570304.3  414012.3
----------------------------------
Page 203, table 6.5
use http://www.ats.ucla.edu/stat/stata/examples/lohr/audit.dta, clear
list in 1/14

     +-------------------------------------------------+
     | account   bookval   cumbv     rn1     rn2   rn3 |
     |-------------------------------------------------|
  1. |       1      2459    2459       .       .     . |
  2. |       2      2343    4802       .       .     . |
  3. |       3      6842   11644   11016       .     . |
  4. |       4      4179   15823       .       .     . |
  5. |       5       750   16573       .       .     . |
     |-------------------------------------------------|
  6. |       6      2708   19281       .       .     . |
  7. |       7      3073   22354       .       .     . |
  8. |       8      4742   27096       .       .     . |
  9. |       9     16350   43446   31056   38500     . |
 10. |      10      5424   48870       .       .     . |
     |-------------------------------------------------|
 11. |      11      9539   58409       .       .     . |
 12. |      12      3108   61517       .       .     . |
 13. |      13      3935   65452   63047       .     . |
 14. |      14       900   66352       .       .     . |
     +-------------------------------------------------+
Page 204 Table 6.6
egen x = anymatch(account), values(3 9 13 24 29 34 36 43 44 45 46 49 55 56 61 70 74 75 79 81)
keep if x == 1
gen dup = 1
replace dup = 2 if account == 9
replace dup = 3 if account == 46
replace dup = 3 if account == 55
expand dup
gen av = bookval
replace av = 7050 if account == 24
replace av = 2149 if account == 36
replace av = 69000 if account == 46
replace av = 2191 if account == 75
gen bvav_diff = bookval - av
gen psi = bookval/612824
gen diff_psi = bvav_diff / psi
gen diff_dollar = bvav_diff/bookval
sort account
list account bookval psi av bvav_diff diff_psi diff_dollar

     +-----------------------------------------------------------------------+
     | account   bookval        psi      av   bvav_d~f   diff_psi   diff_d~r |
     |-----------------------------------------------------------------------|
  1. |       3      6842   .0111647    6842          0          0          0 |
  2. |       9     16350   .0266798   16350          0          0          0 |
  3. |       9     16350   .0266798   16350          0          0          0 |
  4. |      13      3935   .0064211    3935          0          0          0 |
  5. |      24      7090   .0115694    7050         40   3457.399   .0056417 |
     |-----------------------------------------------------------------------|
  6. |      29      5533   .0090287    5533          0          0          0 |
  7. |      34      2163   .0035296    2163          0          0          0 |
  8. |      36      2399   .0039147    2149        250   63862.44   .1042101 |
  9. |      43      8941   .0145898    8941          0          0          0 |
 10. |      44      3716   .0060637    3716          0          0          0 |
     |-----------------------------------------------------------------------|
 11. |      45      8663   .0141362    8663          0          0          0 |
 12. |      46     69540   .1134747   69000        540   4758.771   .0077653 |
 13. |      46     69540   .1134747   69000        540   4758.771   .0077653 |
 14. |      46     69540   .1134747   69000        540   4758.771   .0077653 |
 15. |      49      6881   .0112283    6881          0          0          0 |
     |-----------------------------------------------------------------------|
 16. |      55     70100   .1143885   70100          0          0          0 |
 17. |      55     70100   .1143885   70100          0          0          0 |
 18. |      55     70100   .1143885   70100          0          0          0 |
 19. |      56      6467   .0105528    6467          0          0          0 |
 20. |      61     21000   .0342676   21000          0          0          0 |
     |-----------------------------------------------------------------------|
 21. |      70      3847   .0062775    3847          0          0          0 |
 22. |      74      2422   .0039522    2422          0          0          0 |
 23. |      75      2291   .0037384    2191        100   26749.19   .0436491 |
 24. |      79      4667   .0076156    4667          0          0          0 |
 25. |      81     31257   .0510049   31257          0          0          0 |
     +-----------------------------------------------------------------------+
     
tabstat diff_psi diff_dollar, s(mean sd)

   stats |  diff_psi  diff_d~r
---------+--------------------
    mean |  4333.814  .0070719
      sd |  13546.64  .0221053
------------------------------

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