-------------------------------------------------------------------------------
       log:  a:\week3_4.log
  log type:  text
 opened on:   1 Aug 2002, 16:37:00
. 
. /*********************************/
. /* Preparatory programming commands, we will worry about these later */
. /* but always start out your syntax files with this. */
. /*********************************/
. 
. set more off
. program drop _all
. clear
. set memory 10m
(10240k)
. 
. /********************************/
. /* Opening data set */
. /********************************/
. 
. use "a:\census", clear
. 
. /********************************/
. /* 1.  Displaying contents of a file */
. /********************************/
. 
. /********************************/
. /* 1.   a.  Full contents: codebook */
. /* NOTE:  Small stata does not have sufficient */
. /* memory to do codebook, so do describe instead */
. /********************************/
. 
. codebook, all
                 Dataset:  a:\census.dta
              Last saved:  26 Jun 2002 13:59
                   Label:  [none]
     Number of variables:  39
  Number of observations:  1,331
                    Size:  113,135 bytes ignoring labels, etc.

v1004 --------------------------------------------------------- fips state code
                  type:  numeric (byte)
                 label:  statelab
                 range:  [11,24]                      units:  1
         unique values:  2                    coded missing:  0 / 1331
            tabulation:  Freq.   Numeric  Label
                           189        11  Washington, D.C.
                          1142        24  Maryland

v1008 -------------------------------------------------------- county fips code
                  type:  numeric (int)
                 label:  ctylab, but 1 value is not labeled
                 range:  [1,510]                      units:  1
         unique values:  24                   coded missing:  0 / 1331
              examples:  3     Anne Arundel
                         13    
                         31    Montgomery
                         43    Washington

v1011 -------------------------------------------------------- census tract id6
                  type:  numeric (long)
                 range:  [100,996200]                 units:  1
         unique values:  1278                 coded missing:  0 / 1331
                  mean:    454735
              std. dev:    325226
           percentiles:        10%       25%       50%       75%       90%
                             5701    120500    450700    750102    806704

v103 ----------------------------------------------------------- total families
                  type:  numeric (int)
                 range:  [0,4449]                     units:  1
         unique values:  949                  coded missing:  0 / 1331
                  mean:   1036.74
              std. dev:   602.317
           percentiles:        10%       25%       50%       75%       90%
                              389       637       914      1340      1828

v151 ------------------------------------------------------------------ % white
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  99                   coded missing:  0 / 1331
                  mean:   65.2186
              std. dev:   34.8224
           percentiles:        10%       25%       50%       75%       90%
                                3        39        81        94        98

v152 ------------------------------------------------------------------ % black
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  100                  coded missing:  0 / 1331
                  mean:   30.9745
              std. dev:   35.0731
           percentiles:        10%       25%       50%       75%       90%
                                1         3        13        56        96

v264 ----------------------------------------------------- %  fam w/kids fem-hd
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  92                   coded missing:  23 / 1331
                  mean:   24.6628
              std. dev:    21.019
           percentiles:        10%       25%       50%       75%       90%
                                5         9        17        34        58

v303 ------------------------------------------------------- mean family income
                  type:  numeric (long)
                 range:  [7572,232165]                units:  1
         unique values:  1306                 coded missing:  13 / 1331
                  mean:   52244.3
              std. dev:   26772.5
           percentiles:        10%       25%       50%       75%       90%
                            27515     36502   46619.5     59817     80041

v312 ------------------------------------------------------ % hhs w/wage income
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  63                   coded missing:  11 / 1331
                  mean:   80.8114
              std. dev:    10.589
           percentiles:        10%       25%       50%       75%       90%
                               68        75        82        88        93

v315 ------------------------------------------------ % hhs w/pub assist income
                  type:  numeric (byte)
                 range:  [0,66]                       units:  1
         unique values:  50                   coded missing:  11 / 1331
                  mean:   7.17348
              std. dev:   8.57891
           percentiles:        10%       25%       50%       75%       90%
                                1         2         4         8      18.5

v316 -------------------------------------------------------- % persons<poverty
                  type:  numeric (byte)
                 range:  [0,96]                       units:  1
         unique values:  66                   coded missing:  7 / 1331
                  mean:   10.6715
              std. dev:   12.0606
           percentiles:        10%       25%       50%       75%       90%
                                2         3         6        13        27

v362 ----------------------------------------------------- % families inc>$ 50k
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  97                   coded missing:  13 / 1331
                  mean:   40.1206
              std. dev:   22.3842
           percentiles:        10%       25%       50%       75%       90%
                               12        22        38        57        73

v401 --------------------------------------------------- % young adult dropouts
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  66                   coded missing:  20 / 1331
                  mean:   12.6667
              std. dev:   13.6072
           percentiles:        10%       25%       50%       75%       90%
                                0         3         9        18        30

v402 -------------------------------------------------- % age25+ 0-8 yrs school
                  type:  numeric (byte)
                 range:  [0,97]                       units:  1
         unique values:  37                   coded missing:  1 / 1331
                  mean:   9.08722
              std. dev:   7.32087
           percentiles:        10%       25%       50%       75%       90%
                                2         4         8        13        18

v403 ------------------------------------------------- % age25+ 9-11 yrs school
                  type:  numeric (byte)
                 range:  [0,61]                       units:  1
         unique values:  50                   coded missing:  1 / 1331
                  mean:   15.4925
              std. dev:   9.78068
           percentiles:        10%       25%       50%       75%       90%
                                4         8        14        21        29

v404 --------------------------------------------------- % age25+ 12 yrs school
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  53                   coded missing:  1 / 1331
                  mean:   27.6962
              std. dev:   10.0306
           percentiles:        10%       25%       50%       75%       90%
                               13        21        29        35        39

v405 ------------------------------------------------ % age25+ 13-15 yrs school
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  50                   coded missing:  1 / 1331
                  mean:   22.3233
              std. dev:   7.58037
           percentiles:        10%       25%       50%       75%       90%
                               13        17        22        27        31

v406 --------------------------------------------------- % age25+ 16+yrs school
                  type:  numeric (byte)
                 range:  [0,92]                       units:  1
         unique values:  86                   coded missing:  1 / 1331
                  mean:   25.4226
              std. dev:   19.4259
           percentiles:        10%       25%       50%       75%       90%
                                5        10        20        36        57

v407 ------------------------------------------------ % yngadults not in school
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  83                   coded missing:  20 / 1331
                  mean:   26.2265
              std. dev:   16.9363
           percentiles:        10%       25%       50%       75%       90%
                                6        14        24        35        47

v451 ------------------------------------------------- % age5+ same hse 5yrsago
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  84                   coded missing:  0 / 1331
                  mean:   53.9887
              std. dev:   14.5063
           percentiles:        10%       25%       50%       75%       90%
                               35        46        56        64        70

v517 --------------------------------------------------------- adult unemp rate
                  type:  numeric (byte)
                 range:  [0,60]                       units:  1
         unique values:  34                   coded missing:  8 / 1331
                  mean:   5.50189
              std. dev:   5.34135
           percentiles:        10%       25%       50%       75%       90%
                                2         2         4         7        11

v520 ----------------------------------------------------- % age16+ 0-26wks emp
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  76                   coded missing:  0 / 1331
                  mean:   37.9797
              std. dev:   12.0566
           percentiles:        10%       25%       50%       75%       90%
                               25        30        36        44        52

v521 --------------------------------------------------- % males16+ 0-26wks emp
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  77                   coded missing:  1 / 1331
                  mean:   30.4654
              std. dev:   13.2959
           percentiles:        10%       25%       50%       75%       90%
                               17        22        28        36        47

v523 --------------------------------------------------- unemp+nlf/all16+ ratio
                  type:  numeric (int)
                 range:  [0,518]                      units:  1
         unique values:  82                   coded missing:  0 / 1331
                  mean:   36.3982
              std. dev:   18.9152
           percentiles:        10%       25%       50%       75%       90%
                               22        28        34        43        51

v601 --------------------------------------------------- % housing units vacant
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  53                   coded missing:  10 / 1331
                  mean:   7.85844
              std. dev:   10.9935
           percentiles:        10%       25%       50%       75%       90%
                                2         3         5         9        15

v604 ----------------------------------------------------------- % units rental
                  type:  numeric (byte)
                 range:  [0,100]                      units:  1
         unique values:  100                  coded missing:  10 / 1331
                  mean:   36.6412
              std. dev:   25.1269
           percentiles:        10%       25%       50%       75%       90%
                                9        15        31        55        74

v1471 --------------------------------------------------------- fam w/inc <$ 5k
                  type:  numeric (int)
                 range:  [0,490]                      units:  1
         unique values:  169                  coded missing:  0 / 1331
                  mean:   32.6912
              std. dev:   47.5862
           percentiles:        10%       25%       50%       75%       90%
                                0         6        16        41        81

v1472 ------------------------------------------------------- fam w/inc $ 5-10k
                  type:  numeric (int)
                 range:  [0,317]                      units:  1
         unique values:  162                  coded missing:  0 / 1331
                  mean:   34.8971
              std. dev:   39.9491
           percentiles:        10%       25%       50%       75%       90%
                                0         7        23        48        84

v1473 ---------------------------------------------------- fam w/inc $ 10-12.5k
                  type:  numeric (int)
                 range:  [0,132]                      units:  1
         unique values:  107                  coded missing:  0 / 1331
                  mean:    23.157
              std. dev:   23.0336
           percentiles:        10%       25%       50%       75%       90%
                                0         6        17        34        55

inc_ord ------------------------------ Mean hh inc in census tract, in $20k
                                       increments
                  type:  numeric (float)
                 range:  [20000,200000]               units:  10000
         unique values:  10                   coded missing:  13 / 1331
                  mean:   62154.8
              std. dev:   26912.5
           percentiles:        10%       25%       50%       75%       90%
                            40000     40000     60000     60000    100000

inc_ord1 ------------------------------ Mean hh inc in census tract, in deciles
                  type:  numeric (float)
                 range:  [27477,232165]               units:  1
         unique values:  10                   coded missing:  13 / 1331
                  mean:   67341.3
              std. dev:   56896.1
           percentiles:        10%       25%       50%       75%       90%
                            33558     38546     48788     64989    232165

fhh_ord ------------------------------ Percentage of FHH in census tract, in 10
                                       percent increments
                  type:  numeric (float)
                 range:  [10,100]                     units:  10
         unique values:  10                   coded missing:  23 / 1331
                  mean:   29.3043
              std. dev:   21.0488
           percentiles:        10%       25%       50%       75%       90%
                               10        10        20        40        60

fhh_ord1 ----------------------------------------- 6 interval variable of % fhh
                  type:  numeric (float)
                 label:  fhh_lab
                 range:  [10,100]                     units:  10
         unique values:  6                    coded missing:  23 / 1331
            tabulation:  Freq.   Numeric  Label
                           392        10  0-10% fhh in census tract
                           353        20  11-20% fhh in census tract
                           182        30  21-30% fhh in census tract
                           113        40  31-40% fhh in census tract
                            83        50  41-50% fhh in census tract
                           185       100  51-100% fhh in census tract

county ------------------------------------------------------------ (unlabeled)
                  type:  numeric (float)
                 label:  ctylab1
                 range:  [1,510]                      units:  1
         unique values:  4                    coded missing:  608 / 1331
            tabulation:  Freq.   Numeric  Label
                           189         1  Washington, D.C.
                           159        31  Montgomery
                           172        33  PG
                           203       510  Baltimore City

hyperseg ----------------------------- hypersegregated neighborhood dummy,
                                       1=91%+ black
                  type:  numeric (float)
                 range:  [0,1]                        units:  1
         unique values:  2                    coded missing:  0 / 1331
            tabulation:  Freq.  Value
                          1140  0
                           191  1

seg_unem ----------------------------- interaction of male unemployment and
                                       hypersegregation
                  type:  numeric (float)
                 range:  [0,91]                       units:  1
         unique values:  48                   coded missing:  1 / 1331
                  mean:   6.56391
              std. dev:   16.6242
           percentiles:        10%       25%       50%       75%       90%
                                0         0         0         0        40

v152_2 -------------------------------------------- % black squared (v152*v152)
                  type:  numeric (float)
                 range:  [0,10000]                    units:  1
         unique values:  100                  coded missing:  0 / 1331
                  mean:   2188.61
              std. dev:   3436.99
           percentiles:        10%       25%       50%       75%       90%
                                1         9       169      3136      9216

v521_2 -------------------------------- % male unemployment squared (v521*v521)
                  type:  numeric (float)
                 range:  [0,10000]                    units:  1
         unique values:  77                   coded missing:  1 / 1331
                  mean:   1104.79
              std. dev:   1127.19
           percentiles:        10%       25%       50%       75%       90%
                              289       484       784      1296      2209

v316_pro ----------------------------------- poverty as a proportion (v316/100)
                  type:  numeric (float)
                 range:  [0,.96]                      units:  .01
         unique values:  66                   coded missing:  7 / 1331
                  mean:   .106715
              std. dev:   .120606
           percentiles:        10%       25%       50%       75%       90%
                              .02       .03       .06       .13       .27
. 
. /********************************/
. /* 1.b. Brief contents: describe */
. /********************************/
. 
. describe
Contains data from a:\census.dta
  obs:         1,331                          
vars:            39                          26 Jun 2002 13:59
 size:       113,135 (98.7% of memory free)
-------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------
v1004           byte   %16.0g      statelab   fips state code
v1008           int    %25.0g      ctylab     county fips code
v1011           long   %12.0g                 census tract id6
v103            int    %8.0g                  total families
v151            byte   %8.0g                  % white
v152            byte   %8.0g                  % black
v264            byte   %8.0g                  %  fam w/kids fem-hd
v303            long   %12.0g                 mean family income
v312            byte   %8.0g                  % hhs w/wage income
v315            byte   %8.0g                  % hhs w/pub assist income
v316            byte   %8.0g                  % persons<poverty
v362            byte   %8.0g                  % families inc>$ 50k
v401            byte   %8.0g                  % young adult dropouts
v402            byte   %8.0g                  % age25+ 0-8 yrs school
v403            byte   %8.0g                  % age25+ 9-11 yrs school
v404            byte   %8.0g                  % age25+ 12 yrs school
v405            byte   %8.0g                  % age25+ 13-15 yrs school
v406            byte   %8.0g                  % age25+ 16+yrs school
v407            byte   %8.0g                  % yngadults not in school
v451            byte   %8.0g                  % age5+ same hse 5yrsago
v517            byte   %8.0g                  adult unemp rate
v520            byte   %8.0g                  % age16+ 0-26wks emp
v521            byte   %8.0g                  % males16+ 0-26wks emp
v523            int    %8.0g                  unemp+nlf/all16+ ratio
v601            byte   %8.0g                  % housing units vacant
v604            byte   %8.0g                  % units rental
v1471           int    %8.0g                  fam w/inc <$ 5k
v1472           int    %8.0g                  fam w/inc $ 5-10k
v1473           int    %8.0g                  fam w/inc $ 10-12.5k
inc_ord         float  %9.0g                  Mean hh inc in census tract, in
                                                $20k increments
inc_ord1        float  %9.0g                  Mean hh inc in census tract, in
                                                deciles
fhh_ord         float  %9.0g                  Percentage of FHH in census
                                                tract, in 10 percent increments
fhh_ord1        float  %27.0g      fhh_lab    6 interval variable of % fhh
county          float  %16.0g      ctylab1    
hyperseg        float  %9.0g                  hypersegregated neighborhood
                                                dummy, 1=91%+ black
seg_unem        float  %9.0g                  interaction of male
                                                unemployment and
                                                hypersegregation
v152_2          float  %9.0g                  % black squared (v152*v152)
v521_2          float  %9.0g                  % male unemployment squared
                                                (v521*v521)
v316_pro        float  %9.0g                  poverty as a proportion
                                                (v316/100)
-------------------------------------------------------------------------------
Sorted by:  v316_pro  
. 
. /********************/
. /*2.  Frequency distribution */
. /********************/
. /********************/
. /* 2. a.  nominal level variable */
. /* v1004 is the census variable for State */
. /********************/
. 
. tab1 v1004
-> tabulation of v1004  
 fips state code |      Freq.     Percent        Cum.
-----------------+-----------------------------------
Washington, D.C. |        189       14.20       14.20
        Maryland |       1142       85.80      100.00
-----------------+-----------------------------------
           Total |       1331      100.00
.  
. /********************/
. /* 2. c. multiple variables at one time */
. /* Inc_ord is income divided into equal-sized */
. /* intervals.  Inc_ord1 is income divided into */
. /* equal FREQUENCY intervals.  Interpret both */
. /********************/
. 
. tab1 v1004 inc_ord inc_ord1 
-> tabulation of v1004  
 fips state code |      Freq.     Percent        Cum.
-----------------+-----------------------------------
Washington, D.C. |        189       14.20       14.20
        Maryland |       1142       85.80      100.00
-----------------+-----------------------------------
           Total |       1331      100.00
-> tabulation of inc_ord  
Mean hh inc |
  in census |
  tract, in |
       $20k |
 increments |      Freq.     Percent        Cum.
------------+-----------------------------------
      20000 |         37        2.81        2.81
      40000 |        404       30.65       33.46
      60000 |        549       41.65       75.11
      80000 |        196       14.87       89.98
     100000 |         60        4.55       94.54
     120000 |         29        2.20       96.74
     140000 |         19        1.44       98.18
     160000 |         11        0.83       99.01
     180000 |          5        0.38       99.39
     200000 |          8        0.61      100.00
------------+-----------------------------------
      Total |       1318      100.00
-> tabulation of inc_ord1  
Mean hh inc |
  in census |
  tract, in |
    deciles |      Freq.     Percent        Cum.
------------+-----------------------------------
      27477 |        131        9.94        9.94
      33558 |        132       10.02       19.95
      38546 |        132       10.02       29.97
      42606 |        132       10.02       39.98
      46556 |        132       10.02       50.00
      51020 |        131        9.94       59.94
      56439 |        132       10.02       69.95
      64989 |        132       10.02       79.97
      79631 |        132       10.02       89.98
     232165 |        132       10.02      100.00
------------+-----------------------------------
      Total |       1318      100.00
. 
. /**********************/
. /*  3. histogram */
. /* What is the implication of the shape of this histogram? */
. /**********************/
. graph inc_ord, hist bin (10) normal xlabel /*
> */ title ("Mean HH Income in Maryland and DC Census Tracts")


 
. /***********************/
. /* 4. command terminators */
. /*    a. carriage return (default) */
. /*    b. ; (semi-colon) */
. /***********************/
. 
. /***********************/
. /* 5.a. single line commands end in carriage return */
. /***********************/
. 
. * example
. 
. tabulate inc_ord
Mean hh inc |
  in census |
  tract, in |
       $20k |
 increments |      Freq.     Percent        Cum.
------------+-----------------------------------
      20000 |         37        2.81        2.81
      40000 |        404       30.65       33.46
      60000 |        549       41.65       75.11
      80000 |        196       14.87       89.98
     100000 |         60        4.55       94.54
     120000 |         29        2.20       96.74
     140000 |         19        1.44       98.18
     160000 |         11        0.83       99.01
     180000 |          5        0.38       99.39
     200000 |          8        0.61      100.00
------------+-----------------------------------
      Total |       1318      100.00
. 
. /***********************/
. /* 5. b. multi-line commands can end in carriage return or ; */
. /* in order to change back and forth between terminators */
. /* use #delimit command */
. /***********************/
. 
. * example: EITHER use comments to hide carriage return from STATA
. 
. graph inc_ord, hist bin (10) normal xlabel /*
> */ title ("Mean HH Income in Maryland and DC Census Tracts")
. 
. * OR change to semi-colon to allow commands to be multi-line
. 
. #delimit;
delimiter now ;
. graph inc_ord, hist bin (10) normal xlabel 
>  title ("Mean HH Income in Maryland and DC Census Tracts");
. * to change back to carriage return: ;
. #delimit cr
delimiter now cr
. 
. /***********************/
. /* closing and saving output file */
. /***********************/
. 
. log close
       log:  a:\week3_4.log
  log type:  text
 closed on:   1 Aug 2002, 16:37:08
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
       log:  a:\week5_6.log
  log type:  text
 opened on:   1 Aug 2002, 16:38:40
. 
. /**************************************/
. /*Initial set up commands, use with EVERY dofile */
. /* 1. makes stata scroll through entire program rather than stopping */
. /*     every time you come to the end of a screen of output, to make */
. /*     stata stop scrolling, type set more on */
. /* 2. drop any programs that you may have created and would still be */
. /*     in memory Stata knows that _all means all existing programs so */
. /*     you don't need to specify a program name */
. /* 3. close any data set that might be open */
. /* 4. set the memory in Stata so that it can handle any dataset (set to */
. /*     10 megabytes) */
. /***************************************/
. 
. set more off
. program drop _all
. clear
. set memory 10m
(10240k)
. 
. /********************/
. /* open data file */
. /********************/
. 
. use "a:\census", clear
. 
. /***********************/
. /* 1.a. measures of central tendency & dispersion */
. /*    mean, median, standard deviation, */
. /*    minimum, maximum, interquartile range, skew */
. /***********************/
. 
. sum v303, detail
                     mean family income
-------------------------------------------------------------
      Percentiles      Smallest
 1%        16815           7572
 5%        23084          10301
10%        27515          11600       Obs                1318
25%        36502          11700       Sum of Wgt.        1318
50%      46619.5                      Mean           52244.29
                        Largest       Std. Dev.      26772.51
75%        59817         193114
90%        80041         209649       Variance       7.17e+08
95%       103784         210363       Skewness       2.302244
99%       159943         232165       Kurtosis       11.04944
. 
. /***********************/
. /* 1.b. mode */
. /* NOTE:  You cannot get a mode directly through a */
. /* command, so you have to create a mode by creating a new */
. /* variable named mode.  */
. /***********************/
. 
. egen modev303=mode (v303), minmode
. sum modev303
    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
    modev303 |    1331       31723          0      31723      31723
. drop modev303
. 
. /***********************/
. /* 2. combining measures of dispersion and central tendency. */
. /*     box and whiskers plot */
. /* shows range; median, IQR, adjacent values (1.5xIQR), outliers. */
. /***********************/
. 
. graph v303, box ylabel title ("Mean HH income in MD/DC Census Tracts")
. 
. /***********************/
. /* closing output file so you can open it in word and print it there */
. /***********************/
. 
. log close 
       log:  a:\week5_6.log
  log type:  text
 closed on:   1 Aug 2002, 16:38:41
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
       log:  a:\week7_8.log
  log type:  text
 opened on:   1 Aug 2002, 16:39:40
. 
. /**************************************/
. /*Initial set up commands, use with EVERY dofile */
. /* 1. makes stata scroll through entire program rather than stopping */
. /*     every time you come to the end of a screen of output, to make */
. /*     stata stop scrolling, type set more on */
. /* 2. drop any programs that you may have created and would still be */
. /*     in memory Stata knows that _all means all existing programs so */
. /*     you don't need to specify a program name */
. /* 3. close any data set that might be open */
. /* 4. set the memory in Stata so that it can handle any dataset (set to */
. /*     10 megabytes) */
. /***************************************/
. 
. set more off
. program drop _all
. clear
. set memory 10m
(10240k)
. 
. /*****************/
. /* Open data set */
. /*****************/ 
.  use "a:\census.dta", clear
. 
. /*****************/
. /* 1. bi-variate measures of central tendency & dispersion */
. /* Comparing Income by county */
. /******************/
. 
. * all except mode 
. sort county
. by county: sum v303, detail
_______________________________________________________________________________
-> county = Washington, D.C.
                     mean family income
-------------------------------------------------------------
      Percentiles      Smallest
 1%        18222          12266
 5%        22230          18222
10%        23667          18990       Obs                 187
25%        28862          19205       Sum of Wgt.         187
50%        42383                      Mean           54483.98
                        Largest       Std. Dev.      37463.94
75%        63814         179394
90%       104857         185228       Variance       1.40e+09
95%       142115         186147       Skewness       1.858514
99%       186147         209649       Kurtosis       6.296177
_______________________________________________________________________________
-> county = Montgomery
                     mean family income
-------------------------------------------------------------
      Percentiles      Smallest
 1%        35523          28345
 5%        41236          35523
10%        45358          37484       Obs                 159
25%        55140          37692       Sum of Wgt.         159
50%        68004                      Mean           77139.47
                        Largest       Std. Dev.      34639.82
75%        87713         179062
90%       124994         181913       Variance       1.20e+09
95%       150034         210363       Skewness       1.775324
99%       210363         232165       Kurtosis       6.786195
_______________________________________________________________________________
-> county = PG
                     mean family income
-------------------------------------------------------------
      Percentiles      Smallest
 1%        23756          21000
 5%        32201          23756
10%        36771          28511       Obs                 172
25%      42695.5          29640       Sum of Wgt.         172
50%        51271                      Mean           52104.81
                        Largest       Std. Dev.      13178.46
75%      61178.5          82737
90%        69472          85308       Variance       1.74e+08
95%        77915          88976       Skewness        .413274
99%        88976          89794       Kurtosis       2.942131
_______________________________________________________________________________
-> county = Baltimore City
                     mean family income
-------------------------------------------------------------
      Percentiles      Smallest
 1%        11700           7572
 5%        17245          10301
10%        19762          11700       Obs                 201
25%        24879          12284       Sum of Wgt.         201
50%        32528                      Mean           35589.93
                        Largest       Std. Dev.      20231.02
75%        39246         114059
90%        47246         120246       Variance       4.09e+08
95%        68662         151267       Skewness       3.204822
99%       120246         153263       Kurtosis       16.37674
_______________________________________________________________________________
-> county = .
                     mean family income
-------------------------------------------------------------
      Percentiles      Smallest
 1%        19938          11600
 5%        28385          14835
10%        31861          16010       Obs                 599
25%        39242          16815       Sum of Wgt.         599
50%        47368                      Mean           50565.43
                        Largest       Std. Dev.      19391.01
75%        57276         135002
90%        69822         153228       Variance       3.76e+08
95%        83627         191664       Skewness       2.468332
99%       131258         193114       Kurtosis       14.88707

. 
. * compare means and median of DC, Baltimore, PG, Montgomery  what does that 
> tell you?
. 
. * mode
. sort county
. by county: egen modev303=mode(v303), minmode
. by county: sum modev303
_______________________________________________________________________________
-> county = Washington, D.C.
    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
    modev303 |     189       34488          0      34488      34488
_______________________________________________________________________________
-> county = Montgomery
    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
    modev303 |     159       28345          0      28345      28345
_______________________________________________________________________________
-> county = PG
    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
    modev303 |     172       44657          0      44657      44657
_______________________________________________________________________________
-> county = Baltimore City
    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
    modev303 |     203        7572          0       7572       7572
_______________________________________________________________________________
-> county = .
    Variable |     Obs        Mean   Std. Dev.       Min        Max
-------------+-----------------------------------------------------
    modev303 |     608       46727          0      46727      46727

. 
. /********************/
. /* 2. bi-variate measures of central tendency and dispersion together: */
. /*     box and whiskers plot */
. /********************/
. 
. sort county
. graph v303, box ylabel title ("Mean HH income in MD/DC Census Tracts") by (co
> unty)
. 
. /********************/
. /* 3. Scatterplot (2 interval level variables) */
. /********************/
. graph v303 v152, xlabel ylabel ti ("Mean Census Tract Income by % Black")
. 
. /********************/
. /* 4. Cross-tabs (i.e. bi-variate frequency distribution */
. /* Distribution of Income in $20k intervals (variable=inc_ord) */
. /* by state */
. /* Difficult to compare using counts since MD and DC */
. /* are of different size, so compare percentages */
. /********************/
. 
. tab inc_ord county, column nofreq
   Mean hh |
    inc in |
    census |
 tract, in |
      $20k |                   county
increments | Washingto  Montgomer         PG  Baltimore |     Total
-----------+--------------------------------------------+----------
     20000 |      3.21       0.00       0.00      12.44 |      4.31 
     40000 |     43.85       4.40      18.02      63.18 |     34.35 
     60000 |     27.27      32.08      55.81      18.41 |     32.68 
     80000 |      6.95      30.82      23.84       1.99 |     14.88 
    100000 |      5.88      15.09       2.33       1.00 |      5.70 
    120000 |      4.81       6.29       0.00       1.49 |      3.06 
    140000 |      2.67       5.66       0.00       0.50 |      2.09 
    160000 |      2.67       1.89       0.00       1.00 |      1.39 
    180000 |      1.07       1.89       0.00       0.00 |      0.70 
    200000 |      1.60       1.89       0.00       0.00 |      0.83 
-----------+--------------------------------------------+----------
     Total |    100.00     100.00     100.00     100.00 |    100.00 

. 
. /********************/
. /* if you wanted row %, just add "row", */
. /* or cell % (% of total) add "cell", or count add "count" */
. /********************/
. 
. /**********************/
. /* 5. bi-variate histogram */
. /**********************/
. sort v1004
. graph inc_ord, hist bin (10) normal xlabel ylabel by (v1004) /*
> */ title ("Mean HH Income in Maryland and DC Census Tracts")
. 
. /********************/
. /* closing output file so you can open it in word and print it there */
. /********************/
. log close 
       log:  a:\week7_8.log
  log type:  text
 closed on:   1 Aug 2002, 16:39:41
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
       log:  a:\week10_11.log
  log type:  text
 opened on:   1 Aug 2002, 16:42:21
. 
. /*******************/
. /* initial set up commands, use with EVERY dofile */
. /* 1. makes stata scroll through entire program rather than stopping */
. /*    every time you come to the end of a screen of output, to make stata */
. /*    stop scrolling, type: set more on */
. /* 2. drop any programs that you may have created and would still be in memor
> y */
. /*    Stata knows that _all means all existing programs so you don't have to 
> */
. /*    specify a program name */
. /* 3. close any data set that might be open */
. /* 4. set the memory in Stata so that it can handle any dataset */
. /*    (set to 10 megabytes) */
. /*******************/
. 
. set more off
. program drop _all
. clear
. set memory 10m
(10240k)
. 
. /*******************/
. /* open data file */
. /*******************/
. 
. use "a:\census", clear
. 
. /*******************/
. /* a.  chi-square (differences in nominal or ordinal distributions between tw
> o or more groups): */
. /*******************/
. 
. tabulate inc_ord v1004, column nofreq chi2
   Mean hh |
    inc in |
    census |
 tract, in |
      $20k |    fips state code
increments | Washingto   Maryland |     Total
-----------+----------------------+----------
     20000 |      3.21       2.74 |      2.81 
     40000 |     43.85      28.47 |     30.65 
     60000 |     27.27      44.03 |     41.65 
     80000 |      6.95      16.18 |     14.87 
    100000 |      5.88       4.33 |      4.55 
    120000 |      4.81       1.77 |      2.20 
    140000 |      2.67       1.24 |      1.44 
    160000 |      2.67       0.53 |      0.83 
    180000 |      1.07       0.27 |      0.38 
    200000 |      1.60       0.44 |      0.61 
-----------+----------------------+----------
     Total |    100.00     100.00 |    100.00 
          Pearson chi2(9) =  57.5592   Pr = 0.000
. 
. 
. /*******************/
. /* b.  ONE WAY ANOVA (assessing three or more group level differences along a
>  single interval level variable) */
. /*******************/
. 
. oneway v303 county, scheffe tabulate
            |    Summary of mean family income
     county |        Mean   Std. Dev.       Freq.
------------+------------------------------------
  Washingto |   54483.984   37463.941         187
  Montgomer |   77139.472   34639.822         159
         PG |   52104.814   13178.463         172
  Baltimore |   35589.925   20231.018         201
------------+------------------------------------
      Total |   53642.954   31579.421         719
                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      1.5383e+11      3   5.1276e+10     65.21     0.0000
 Within groups      5.6220e+11    715    786298406
------------------------------------------------------------------------
    Total           7.1603e+11    718    997259848
Bartlett's test for equal variances:  chi2(3) = 213.7624  Prob>chi2 = 0.000
                  Comparison of mean family income by county
                                  (Scheffe)
Row Mean-|
Col Mean |   Washingt   Montgome         PG
---------+---------------------------------
Montgome |    22655.5
         |      0.000
         |
      PG |   -2379.17   -25034.7
         |      0.886      0.000
         |
Baltimor |   -18894.1   -41549.5   -16514.9
         |      0.000      0.000      0.000
. 
. 
. /*******************/
. /* c.  two sample unpaired t-test with unequal variances */
. /*******************/
. 
. * Example without a statistically significant difference
. 
. ttest v303, by(v1004) unequal welch
Two-sample t test with unequal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
Washingt |     187    54483.98    2739.635    37463.94    49079.23    59888.74
Maryland |    1131    51873.98     730.411    24563.97    50440.86    53307.09
---------+--------------------------------------------------------------------
combined |    1318    52244.29    737.4479    26772.51    50797.59    53690.99
---------+--------------------------------------------------------------------
    diff |            2610.005     2835.33               -2978.822    8198.832
------------------------------------------------------------------------------
Welch's degrees of freedom:  213.495
               Ho: mean(Washingt) - mean(Maryland) = diff = 0
     Ha: diff < 0               Ha: diff ~= 0              Ha: diff > 0
       t =   0.9205                t =   0.9205              t =   0.9205
   P < t =   0.8208          P > |t| =   0.3583          P > t =   0.1792
. 
. /*******************/
. /* Example WITH a statistically significant difference. */
. /* Comparing Baltimore and D.C. */
. /* NOTE:  For this test, I need to drop all other cases other than D.C. and B
> altimore */
. /*******************/
. 
. keep if v1004==11 | v1008==510
(939 observations deleted)
. 
. ttest v303, by(county) unequal welch
Two-sample t test with unequal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
Washingt |     187    54483.98    2739.635    37463.94    49079.23    59888.74
Baltimor |     201    35589.93    1426.986    20231.02    32776.06    38403.79
---------+--------------------------------------------------------------------
combined |     388    44696.08    1585.578    31232.27    41578.66    47813.51
---------+--------------------------------------------------------------------
    diff |            18894.06    3088.995                12813.68    24974.44
------------------------------------------------------------------------------
Welch's degrees of freedom:  282.367
               Ho: mean(Washingt) - mean(Baltimor) = diff = 0
     Ha: diff < 0               Ha: diff ~= 0              Ha: diff > 0
       t =   6.1166                t =   6.1166              t =   6.1166
   P < t =   1.0000          P > |t| =   0.0000          P > t =   0.0000
. 
. /*******************/
. * CORRESPONDENCE BETWEEN ANOVA AND T-TEST: scheffe test is two sample t-test 
> with equal variances, HA: u1-u2~=0, 
. /*******************/
. 
. use "a:\census", clear
. 
. oneway v303 v1004, tabulate scheffe
 fips state |    Summary of mean family income
       code |        Mean   Std. Dev.       Freq.
------------+------------------------------------
  Washingto |   54483.984   37463.941         187
   Maryland |   51873.979   24563.974        1131
------------+------------------------------------
      Total |   52244.291   26772.506        1318
                        Analysis of Variance
    Source              SS         df      MS            F     Prob > F
------------------------------------------------------------------------
Between groups      1.0931e+09      1   1.0931e+09      1.53     0.2170
 Within groups      9.4289e+11   1316    716481088
------------------------------------------------------------------------
    Total           9.4398e+11   1317    716767077
Bartlett's test for equal variances:  chi2(1) =  68.9288  Prob>chi2 = 0.000
             Comparison of mean family income by fips state code
                                  (Scheffe)
Row Mean-|
Col Mean |   Washingt
---------+-----------
Maryland |   -2610.01
         |      0.217
. ttest v303, by(v1004)
Two-sample t test with equal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. Err.   Std. Dev.   [95% Conf. Interval]
---------+--------------------------------------------------------------------
Washingt |     187    54483.98    2739.635    37463.94    49079.23    59888.74
Maryland |    1131    51873.98     730.411    24563.97    50440.86    53307.09
---------+--------------------------------------------------------------------
combined |    1318    52244.29    737.4479    26772.51    50797.59    53690.99
---------+--------------------------------------------------------------------
    diff |            2610.005    2113.041               -1535.292    6755.302
------------------------------------------------------------------------------
Degrees of freedom: 1316
               Ho: mean(Washingt) - mean(Maryland) = diff = 0
     Ha: diff < 0               Ha: diff ~= 0              Ha: diff > 0
       t =   1.2352                t =   1.2352              t =   1.2352
   P < t =   0.8915          P > |t| =   0.2170          P > t =   0.1085
. 
. /*******************/
. /* closing output file so you can open it in word and print it there */
. /*******************/
. 
. log close
       log:  a:\week10_11.log
  log type:  text
 closed on:   1 Aug 2002, 16:42:23
-------------------------------------------------------------------------------


-------------------------------------------------------------------------------
       log:  a:\week13_14.log
  log type:  text
 opened on:   1 Aug 2002, 16:42:49
. 
. /**************************************/
. /* REMOVE THE LAST COMMAND IF YOU ARE USING SMALL STATA */
. /*Initial set up commands, use with EVERY dofile */
. /* 1. makes stata scroll through entire program rather than stopping */
. /*     every time you come to the end of a screen of output, to make */
. /*     stata stop scrolling, type set more on */
. /* 2. drop any programs that you may have created and would still be */
. /*     in memory Stata knows that _all means all existing programs so */
. /*     you don't need to specify a program name */
. /* 3. close any data set that might be open */
. /* 4. set the memory in Stata so that it can handle any dataset (set to */
. /*     10 megabytes) */
. /***************************************/
. 
. set more off
. program drop _all
. clear
. set memory 10m
(10240k)
. 
. /*****************/
. /* NOTE: OPEN a:\census_small IF USING SMALL STATA */
. /* Open data set */
. /*****************/ 
. 
. use "a:\census", clear
. 
. /***************************/
. /* 1.  Assessing the degree of linear association via correlation */
. /*      Pearson correlation coefficient (measure of association) */
. /*      -1 indicates perfect linear negative relationship, +1 positive */
. /*      0 not linear relationship, p-value listed below pearson, >.05 indicat
> es a statistical 0 */
. /***********************/
. 
. pwcorr v316 v152 v303 v521 v401 v315, sig
             |     v316     v152     v303     v521     v401     v315
-------------+------------------------------------------------------
        v316 |   1.0000 
             |
             |
        v152 |   0.5010   1.0000 
             |   0.0000
             |
        v303 |  -0.4377  -0.3925   1.0000 
             |   0.0000   0.0000
             |
        v521 |   0.7146   0.4901  -0.3497   1.0000 
             |   0.0000   0.0000   0.0000
             |
        v401 |   0.4488   0.2545  -0.3798   0.4604   1.0000 
             |   0.0000   0.0000   0.0000   0.0000
             |
        v315 |   0.8268   0.5966  -0.4919   0.6544   0.4297   1.0000 
             |   0.0000   0.0000   0.0000   0.0000   0.0000
             |
. 
. /***********************/
.  /* 2.  Testing hypotheses: */
. /*      a. two interval-ratio variables are linearly related */
. /*          bi-variate regression (includes coefficient of determination: r-s
> quare) */
. /*          r-square indicates proportion of total variance in dependent vari
> able */
. /*          accounted for by independent variable */
. /***********************/
. 
. regress v303 v521
      Source |       SS       df       MS              Number of obs =    1318
-------------+------------------------------           F(  1,  1316) =  183.33
       Model |  1.1542e+11     1  1.1542e+11           Prob > F      =  0.0000
    Residual |  8.2856e+11  1316   629604204           R-squared     =  0.1223
-------------+------------------------------           Adj R-squared =  0.1216
       Total |  9.4398e+11  1317   716767077           Root MSE      =   25092
------------------------------------------------------------------------------
        v303 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        v521 |   -749.714   55.37109   -13.54   0.000    -858.3392   -641.0888
       _cons |   74855.73    1807.37    41.42   0.000     71310.09    78401.37
------------------------------------------------------------------------------
. 
. /***********************/
. /* 2.  Testing hypotheses: */
. /*      b. two variables are linearly related, controlling for other variable
> s */
. /*          This is called multivariate regression */
. /***********************/
. 
. regress v303 v521 v152 v401 v315
      Source |       SS       df       MS              Number of obs =    1305
-------------+------------------------------           F(  4,  1300) =  140.11
       Model |  2.7386e+11     4  6.8466e+10           Prob > F      =  0.0000
    Residual |  6.3525e+11  1300   488653919           R-squared     =  0.3012
-------------+------------------------------           Adj R-squared =  0.2991
       Total |  9.0911e+11  1304   697172738           Root MSE      =   22106
------------------------------------------------------------------------------
        v303 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        v521 |   16.47806    73.9863     0.22   0.824    -128.6676    161.6237
        v152 |  -116.7234   22.28016    -5.24   0.000    -160.4324   -73.01444
        v401 |  -414.4836   53.18193    -7.79   0.000    -518.8154   -310.1518
        v315 |  -1010.088   109.8971    -9.19   0.000    -1225.683   -794.4927
       _cons |   67815.18     1834.6    36.96   0.000     64216.08    71414.28
------------------------------------------------------------------------------
. 
. /***************************/
. /* 2.  Testing hypotheses: */
. /*      c. there is an overall difference between groups */
. /*          This is called a dummy variable, it has two values 0 and 1 */
. /*          This allows for easy interpretation, coefficient of dummy variabl
> e */
. /*          is the effect unique to group 1. */
. /*          Hyperseg is 1 if 90% or more black, 0 otherwise */
. /***********************/
. 
. regress v303 v521 hyperseg
      Source |       SS       df       MS              Number of obs =    1318
-------------+------------------------------           F(  2,  1315) =  111.89
       Model |  1.3728e+11     2  6.8641e+10           Prob > F      =  0.0000
    Residual |  8.0670e+11  1315   613459805           R-squared     =  0.1454
-------------+------------------------------           Adj R-squared =  0.1441
       Total |  9.4398e+11  1317   716767077           Root MSE      =   24768
------------------------------------------------------------------------------
        v303 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        v521 |  -556.4392   63.52689    -8.76   0.000    -681.0643   -431.8141
    hyperseg |  -13505.64   2262.498    -5.97   0.000    -17944.14   -9067.139
       _cons |   70963.24   1899.482    37.36   0.000      67236.9    74689.59
------------------------------------------------------------------------------
. 
. /***************************/
. /* 2.  Testing hypotheses: */
. /*      d. the effect of the independent variable depends on group membership
>  */
. /*       Intuitively, which group get more bang for their buck out of having 
> more of the IR indep variable */
. /*       This is called an interaction  term (dummy*interval) */
. /*       Specifically, it is the interaction between hyperseg and v521 (% mal
> e unemployment) */
. /*       The interaction term is the variable seg_unem */
. /***********************/
. 
. regress v303 v521 hyperseg seg_unem
      Source |       SS       df       MS              Number of obs =    1318
-------------+------------------------------           F(  3,  1314) =   74.54
       Model |  1.3728e+11     3  4.5761e+10           Prob > F      =  0.0000
    Residual |  8.0670e+11  1314   613926636           R-squared     =  0.1454
-------------+------------------------------           Adj R-squared =  0.1435
       Total |  9.4398e+11  1317   716767077           Root MSE      =   24778
------------------------------------------------------------------------------
        v303 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        v521 |  -556.2206    68.5676    -8.11   0.000    -690.7345   -421.7066
    hyperseg |  -13438.71   8198.768    -1.64   0.101    -29522.81    2645.397
    seg_unem |  -1.551102   182.6222    -0.01   0.993     -359.814    356.7118
       _cons |   70957.22   2028.322    34.98   0.000     66978.12    74936.32
------------------------------------------------------------------------------
. 
. /***************************/
. /* 2.  Testing hypotheses: */
. /*      e. the effect of the independent variable is non-linear: 4 possibilit
> ies */
. /*          1.  overall negative relationship but the negative relationship s
> ubsides */
. /*          2.  overall negative relationship but the negative relationship i
> s increasingly exacerbated */
. /*          3.  overall positive relationship but the positive relationship s
> ubsides */
. /*          4.  overall positive relationship but the positive relationship i
> s increasingly exacerbated */
. /*          The way this is defined is something you learned in algebra -- to
>  get a line to bend, add a square term */
. /*          In this case, I multiplied v152 (% black) by itself.  It is calle
> d v152_2 */
. /***************************/
. 
. regress v303 v152 v152_2
      Source |       SS       df       MS              Number of obs =    1318
-------------+------------------------------           F(  2,  1315) =  120.87
       Model |  1.4659e+11     2  7.3294e+10           Prob > F      =  0.0000
    Residual |  7.9739e+11  1315   606383699           R-squared     =  0.1553
-------------+------------------------------           Adj R-squared =  0.1540
       Total |  9.4398e+11  1317   716767077           Root MSE      =   24625
------------------------------------------------------------------------------
        v303 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        v152 |   -413.862   83.83939    -4.94   0.000    -578.3355   -249.3884
      v152_2 |   1.190095   .8546082     1.39   0.164    -.4864497    2.866639
       _cons |   62414.22   1117.286    55.86   0.000     60222.36    64606.08
------------------------------------------------------------------------------
. 
. /***********************/
. /* closing output file so you can open it in word and print it there */
. /***********************/
. log close
       log:  a:\week13_14.log
  log type:  text
 closed on:   1 Aug 2002, 16:42:51
-------------------------------------------------------------------------------

