--------------------------------------------------------------------------------
log: /Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/class 12.lo
> g
log type: text
opened on: 5 Nov 2003, 11:14:48
. set linesize 79
. use "/Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/cps_y2k_numeric.
> dta"
no room to add more observations
An attempt was made to increase the number of observations beyond what is
currently possible. You have the following alternatives:
1. Store your variables more efficiently; see help compress. (Think of
Stata's data area as the area of a rectangle; Stata can trade off
width and length.)
2. Drop some variables or observations; see help drop.
3. Increase the amount of memory allocated to the data area using the set
memory command; see help memory.
r(901);
. set mem 50m
(51200k)
. use "/Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/cps_y2k_numeric.
> dta"
. describe
Contains data from /Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/cps_
> y2k_numeric.dta
obs: 133,710
vars: 39 30 May 2001 12:57
size: 9,493,410 (81.9% of memory free)
-------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
phseq str5 %9s household sequence number p2
pernum byte %8.0g
age byte %8.0g p15
maritl byte %26.0g marlbl Marital Status p17
sex byte %8.0g sexnm p20
vet byte %22.0g vetnm veteran status p21
hga byte %8.0g Educational Attainment p22
race byte %11.0g racenm p25
reorigin byte %8.0g Hispanic Origin p27
hrs1 byte %8.0g hours worked last week p76
clswkr byte %32.0g cwrknm sector of worker p109
grswk int %9.0g gross weekly wages p135
unmem byte %13.0g unnm labor union member p139
lfsr byte %28.0g lfsrnm labor force status p145
ernval float %9.0g main job last year earnings p228
ssval long %12.0g last year soc security payments
p291
pawval int %12.0g last year welfare payments p305
wgt2 int %9.0g rounded weight based on p50
ernval2 float %9.0g main job earnings, losses
recoded to zero
htype byte %37.0g htpnm household type h25
state byte %8.0g HG-ST60, or simply state of
residence h40
hpmsasz byte %8.0g metropolitan area size h56
hcccr byte %8.0g residence in central city h58
frelu18 byte %8.0g number of kids in fam under 18
f29
povll byte %8.0g ratio of fam income to poverty
level f38
fwsval float %9.0g family income f48
famwgt2 int %8.0g adjusted family weight f233
yrsed float %9.0g years of education, from hga
citizen byte %33.0g citnm citizenship p733
health byte %11.0g hlthnm self reported health status p800
occ int %8.0g occupation P 106
ptotr byte %8.0g total person income categories
P466
penatvty int %8.0g country of birth P 722,
Appendix H
pemntvty int %8.0g Mother's country of birth,
P725, appendix H
pefntvty int %8.0g Father's country of birth,
P728, appendix H
peinusyr byte %8.0g time of immigration, P 731
pxnatvty byte %8.0g allocation flag for country of
birth P 734
hgmsac int %8.0g metropolitan area code, h44,
appendix E
pppos2 byte %8.0g family sequence number within
each household p46
-------------------------------------------------------------------------------
Sorted by: race
. tabulate race clswkr
| sector of worker p109
p25 | not in un private federal g state gov | Total
------------+--------------------------------------------+----------
White | 54,092 44,489 1,345 2,384 | 113,475
Black | 7,345 4,711 291 347 | 13,626
Amer Indian | 1,054 549 49 37 | 1,894
Asian | 2,282 1,869 78 116 | 4,715
------------+--------------------------------------------+----------
Total | 64,773 51,618 1,763 2,884 | 133,710
| sector of worker p109
p25 | local gov self empl self empl unpaid | Total
------------+--------------------------------------------+----------
White | 4,396 1,957 4,593 64 | 113,475
Black | 592 65 242 2 | 13,626
Amer Indian | 150 6 45 0 | 1,894
Asian | 97 94 162 5 | 4,715
------------+--------------------------------------------+----------
Total | 5,235 2,122 5,042 71 | 133,710
| sector of
| worker
| p109
p25 | never wor | Total
------------+-----------+----------
White | 155 | 113,475
Black | 31 | 13,626
Amer Indian | 4 | 1,894
Asian | 12 | 4,715
------------+-----------+----------
Total | 202 | 133,710
. codebook clswkr race
-------------------------------------------------------------------------------
clswkr sector of worker p109
-------------------------------------------------------------------------------
type: numeric (byte)
label: cwrknm
range: [0,8] units: 1
unique values: 9 missing .: 0/133710
tabulation: Freq. Numeric Label
64773 0 not in universe, children, or AF
51618 1 private
1763 2 federal govt
2884 3 state govt
5235 4 local govt
2122 5 self employed- incorporated
5042 6 self employed, not incorp
71 7 unpaid
202 8 never worked
-------------------------------------------------------------------------------
race p25
-------------------------------------------------------------------------------
type: numeric (byte)
label: racenm
range: [1,4] units: 1
unique values: 4 missing .: 0/133710
tabulation: Freq. Numeric Label
1.1e+05 1 White
13626 2 Black
1894 3 Amer Indian
4715 4 Asian
. contract race clswkr, zero
. rename _freq count
. describe
Contains data from /Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/cps_
> y2k_numeric.dta
obs: 36
vars: 3 30 May 2001 12:57
size: 360 (99.9% of memory free)
-------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
race byte %11.0g racenm p25
clswkr byte %32.0g cwrknm sector of worker p109
count long %12.0g Frequency
-------------------------------------------------------------------------------
Sorted by: race clswkr
Note: dataset has changed since last saved
. *This is the basic 36 cell cross tab of race and class of worker
. *In order to merge some continuous variables to this dataset, you need to sort
by race and class worker, so that you can later match merge
. save "/Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/race_work cross
> tab.dta"
file /Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/race_work crosstab
> .dta saved
. use "/Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/cps_y2k_numeric.
> dta"
. table race clswkr, contents (mean age mean ernval2)
------------------------------------------------------------------------------
| sector of worker p109
p25 | not in universe, chi private federal govt
------------+-----------------------------------------------------------------
White | 31.5214 37.8363 44.2929
| 961.209 28202 40052.48
|
Black | 27.3446 37.1883 42.0447
| 946.9116 21870.88 35586.27
|
Amer Indian | 23.3387 35.0984 44.5714
| 721.3586 18816.68 29912.47
|
Asian | 26.6437 37.2397 44.0641
| 1181.695 30473.98 42933.21
------------------------------------------------------------------------------
------------------------------------------------------------------------------
| sector of worker p109
p25 | state govt local govt self employed- incor
------------+-----------------------------------------------------------------
White | 42.1456 43.1943 47.3608
| 30403.36 29669 59787.36
|
Black | 40.0461 42.2973 45.8
| 28605.13 30311.97 42474.63
|
Amer Indian | 39.5676 40.4867 52
| 21098.81 22219.18 55562
|
Asian | 38.6724 43.6289 46.234
| 28368.94 35644.68 45471.77
------------------------------------------------------------------------------
------------------------------------------------------------------------------
| sector of worker p109
p25 | self employed, not i unpaid never worked
------------+-----------------------------------------------------------------
White | 46.7725 41.0313 20.5548
| 26423.26 2165.938 94.13548
|
Black | 45.3843 37 19.871
| 22218.26 0 6.451613
|
Amer Indian | 44.2889 23
| 13852.16 240
|
Asian | 43.4506 41.4 22
| 34244.63 80 813.3333
------------------------------------------------------------------------------
. table race clswkr, contents (mean age mean ernval2) replace
------------------------------------------------------------------------------
| sector of worker p109
p25 | not in universe, chi private federal govt
------------+-----------------------------------------------------------------
White | 31.5214 37.8363 44.2929
| 961.209 28202 40052.48
|
Black | 27.3446 37.1883 42.0447
| 946.9116 21870.88 35586.27
|
Amer Indian | 23.3387 35.0984 44.5714
| 721.3586 18816.68 29912.47
|
Asian | 26.6437 37.2397 44.0641
| 1181.695 30473.98 42933.21
------------------------------------------------------------------------------
------------------------------------------------------------------------------
| sector of worker p109
p25 | state govt local govt self employed- incor
------------+-----------------------------------------------------------------
White | 42.1456 43.1943 47.3608
| 30403.36 29669 59787.36
|
Black | 40.0461 42.2973 45.8
| 28605.13 30311.97 42474.63
|
Amer Indian | 39.5676 40.4867 52
| 21098.81 22219.18 55562
|
Asian | 38.6724 43.6289 46.234
| 28368.94 35644.68 45471.77
------------------------------------------------------------------------------
------------------------------------------------------------------------------
| sector of worker p109
p25 | self employed, not i unpaid never worked
------------+-----------------------------------------------------------------
White | 46.7725 41.0313 20.5548
| 26423.26 2165.938 94.13548
|
Black | 45.3843 37 19.871
| 22218.26 0 6.451613
|
Amer Indian | 44.2889 23
| 13852.16 240
|
Asian | 43.4506 41.4 22
| 34244.63 80 813.3333
------------------------------------------------------------------------------
. rename table1 mean_age
. rename table2 mean_earn
. sort race clswkr
. describe
Contains data
obs: 35
vars: 4
size: 490 (99.9% of memory free)
-------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
race byte %11.0g racenm p25
clswkr byte %32.0g cwrknm sector of worker p109
mean_age float %8.0g mean(age)
mean_earn float %9.0g mean(ernval2)
-------------------------------------------------------------------------------
Sorted by: race clswkr
Note: dataset has changed since last saved
. edit
- preserve
. *in order to match merge two datasets, both datasets must have common variables,
in this case the two variables that define the number of cases (race and clswkr), and both datasets must be sorted on those variables.
. merge race clswkr "/Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/ra
> ce_work crosstab.dta"
time-series operators not allowed
r(101);
. merge race clswkr using "/Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desk
> top/race_work crosstab.dta"
(label racenm already defined)
(label cwrknm already defined)
. describe
Contains data
obs: 36
vars: 6
size: 684 (99.9% of memory free)
-------------------------------------------------------------------------------
storage display value
variable name type format label variable label
-------------------------------------------------------------------------------
race byte %11.0g racenm p25
clswkr byte %32.0g cwrknm sector of worker p109
mean_age float %8.0g mean(age)
mean_earn float %9.0g mean(ernval2)
count long %12.0g Frequency
_merge byte %8.0g
-------------------------------------------------------------------------------
Sorted by:
Note: dataset has changed since last saved
. tabulate _merge
_merge | Freq. Percent Cum.
------------+-----------------------------------
2 | 1 2.78 2.78
3 | 35 97.22 100.00
------------+-----------------------------------
Total | 36 100.00
. save "/Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/race_work cross
> tab.dta", replace
file /Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/race_work crosstab
> .dta saved
. *This is my new dataset with 35 observations from both contributing datasets,
> and one observation with zero count and missing values for mean_age and mean_earn
. browse
. xi: poisson count i.race i.clswkr mean_age mean_earn
i.race _Irace_1-4 (naturally coded; _Irace_1 omitted)
i.clswkr _Iclswkr_0-8 (naturally coded; _Iclswkr_0 omitted)
Iteration 0: log likelihood = -125054.52
Iteration 1: log likelihood = -36755.225
Iteration 2: log likelihood = -4801.7302
Iteration 3: log likelihood = -648.24967
Iteration 4: log likelihood = -437.37621
Iteration 5: log likelihood = -435.43597
Iteration 6: log likelihood = -435.43594
Poisson regression Number of obs = 35
LR chi2(13) = 486098.46
Prob > chi2 = 0.0000
Log likelihood = -435.43594 Pseudo R2 = 0.9982
------------------------------------------------------------------------------
count | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Irace_2 | -2.114795 .0193723 -109.17 0.000 -2.152764 -2.076826
_Irace_3 | -4.119102 .0411246 -100.16 0.000 -4.199705 -4.038499
_Irace_4 | -3.288698 .0188396 -174.56 0.000 -3.325623 -3.251773
_Iclswkr_1 | -.7238869 .092788 -7.80 0.000 -.905748 -.5420257
_Iclswkr_2 | -4.241375 .1485691 -28.55 0.000 -4.532565 -3.950185
_Iclswkr_3 | -3.565329 .1157961 -30.79 0.000 -3.792286 -3.338373
_Iclswkr_4 | -2.930207 .1198321 -24.45 0.000 -3.165073 -2.69534
_Iclswkr_5 | -4.438719 .2058678 -21.56 0.000 -4.842213 -4.035226
_Iclswkr_6 | -2.783852 .1248396 -22.30 0.000 -3.028534 -2.539171
_Iclswkr_7 | -6.567004 .1276906 -51.43 0.000 -6.817273 -6.316734
_Iclswkr_8 | -6.017023 .0860292 -69.94 0.000 -6.185637 -5.848409
mean_age | -.0262652 .004689 -5.60 0.000 -.0354555 -.0170749
mean_earn | .0000255 2.66e-06 9.61 0.000 .0000203 .0000308
_cons | 11.70196 .1484172 78.85 0.000 11.41107 11.99285
------------------------------------------------------------------------------
. *That approach combined categorical variables race and classworker, in the in
> dependence model, plus continuous variables mean_age and mean_earn.
. *The syntax for xi is a little different than the syntax for desmat, but this
> computer doesn't have xi.
. *I mean this computer doesn't have desmat
. *That poisson regression dealt with only 35 observations, because it had to
drop the one where the continuous variables were missing.
. xi: poisson count i.race i.clswkr
i.race _Irace_1-4 (naturally coded; _Irace_1 omitted)
i.clswkr _Iclswkr_0-8 (naturally coded; _Iclswkr_0 omitted)
Iteration 0: log likelihood = -13328.764
Iteration 1: log likelihood = -879.60003
Iteration 2: log likelihood = -574.81466
Iteration 3: log likelihood = -572.97557
Iteration 4: log likelihood = -572.97158
Iteration 5: log likelihood = -572.97158
Poisson regression Number of obs = 36
LR chi2(11) = 493356.85
Prob > chi2 = 0.0000
Log likelihood = -572.97158 Pseudo R2 = 0.9977
------------------------------------------------------------------------------
count | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Irace_2 | -2.119603 .0090665 -233.78 0.000 -2.137373 -2.101833
_Irace_3 | -4.092892 .0231689 -176.65 0.000 -4.138302 -4.047481
_Irace_4 | -3.180834 .0148628 -214.01 0.000 -3.209964 -3.151703
_Iclswkr_1 | -.2270184 .0059001 -38.48 0.000 -.2385825 -.2154543
_Iclswkr_2 | -3.603872 .0241382 -149.30 0.000 -3.651182 -3.556562
_Iclswkr_3 | -3.111711 .019031 -163.51 0.000 -3.149011 -3.074411
_Iclswkr_4 | -2.515522 .0143687 -175.07 0.000 -2.543684 -2.48736
_Iclswkr_5 | -3.41853 .0220611 -154.96 0.000 -3.461769 -3.375291
_Iclswkr_6 | -2.553086 .014621 -174.62 0.000 -2.581743 -2.524429
_Iclswkr_7 | -6.815964 .1187432 -57.40 0.000 -7.048697 -6.583232
_Iclswkr_8 | -5.770376 .0704694 -81.88 0.000 -5.908494 -5.632259
_cons | 10.91455 .0040954 2665.09 0.000 10.90653 10.92258
------------------------------------------------------------------------------
. *If you leave out the continous variables, you would get all 36 cells, which
> is what you want.
. summarize mean_age mean_earn [fweight=count]
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
mean_age | 133710 35.17963 5.064039 19.87097 52
mean_earn | 133710 15373.05 14676.57 0 59787.36
. replace mean_age=35.179 if mean_age==.
(1 real change made)
. replace mean_earn=15373 if mean_earn==.
(1 real change made)
. xi: poisson count i.race i.clswkr mean_age mean_earn
i.race _Irace_1-4 (naturally coded; _Irace_1 omitted)
i.clswkr _Iclswkr_0-8 (naturally coded; _Iclswkr_0 omitted)
Iteration 0: log likelihood = -77043.884
Iteration 1: log likelihood = -42758.879
Iteration 2: log likelihood = -2897.7619
Iteration 3: log likelihood = -486.90299
Iteration 4: log likelihood = -437.09005
Iteration 5: log likelihood = -437.03778
Iteration 6: log likelihood = -437.03778
Poisson regression Number of obs = 36
LR chi2(13) = 493628.71
Prob > chi2 = 0.0000
Log likelihood = -437.03778 Pseudo R2 = 0.9982
------------------------------------------------------------------------------
count | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
_Irace_2 | -2.115789 .0193579 -109.30 0.000 -2.153729 -2.077848
_Irace_3 | -4.121811 .0410771 -100.34 0.000 -4.202321 -4.041301
_Irace_4 | -3.28896 .0188437 -174.54 0.000 -3.325893 -3.252027
_Iclswkr_1 | -.7174781 .0926441 -7.74 0.000 -.8990572 -.535899
_Iclswkr_2 | -4.231459 .1483563 -28.52 0.000 -4.522231 -3.940686
_Iclswkr_3 | -3.557677 .1156343 -30.77 0.000 -3.784317 -3.331038
_Iclswkr_4 | -2.922341 .119666 -24.42 0.000 -3.156882 -2.6878
_Iclswkr_5 | -4.424653 .2055477 -21.53 0.000 -4.827519 -4.021787
_Iclswkr_6 | -2.776068 .1246888 -22.26 0.000 -3.020454 -2.531683
_Iclswkr_7 | -6.587548 .1279046 -51.50 0.000 -6.838237 -6.33686
_Iclswkr_8 | -6.019113 .0860186 -69.97 0.000 -6.187706 -5.850519
mean_age | -.0264524 .0046873 -5.64 0.000 -.0356393 -.0172654
mean_earn | .0000254 2.65e-06 9.56 0.000 .0000202 .0000305
_cons | 11.70807 .1483581 78.92 0.000 11.41729 11.99884
------------------------------------------------------------------------------
. *This process simply replaced the missing continuous values with the global mean for each continuous variable, so that we could get our last degree of freedom back.
. log close
log: /Network/afs/ir.stanford.edu/users/m/r/mrosenfe/Desktop/class 12.l
> og
log type: text
closed on: 5 Nov 2003, 12:01:19
-------------------------------------------------------------------------------