--------------------------------------------------------------------------------

 

  log type:  text

 opened on:  23 Nov 2003, 23:32:07

 

. *This is a log where I'm going to demonstrate how to use matrix manipulations

> to generate the XB interactions of the interesting terms.

 

. *First we have to run the model in question, so we can fish out the dummy variable Xs and the Betas

. desmat: poisson count  year*meth*mgen*fgen year*feth*fgen*mgen  ethintct*year*fgen*mgen BWS QS*year QS*mgen QS*fgen BOhS*fgen BWS*year, difficult

--------------------------------------------------------------------------------

   Poisson regression

--------------------------------------------------------------------------------

   Dependent variable                                                     count

   Optimization:                                                             ml

   Number of observations:                                                  225

   Initial log likelihood:                                         -2252613.647

   Log likelihood:                                                     -719.657

   LR chi square:                                                   4503787.980

   Model degrees of freedom:                                                155

   Pseudo R-squared:                                                      1.000

   Prob:                                                                  0.000

--------------------------------------------------------------------------------

nr Effect                                                     Coeff        s.e.

--------------------------------------------------------------------------------

   count

     year

1      80                                                     3.287**     0.856

2      90                                                     3.770**     0.840

     meth

3      Mex_Am                                                 0.434       0.674

4      Oth_H                                                  1.763**     0.672

5      Oth_NH                                                 0.013       0.552

6      Wht_NH                                                 0.977       0.658

     year.meth

7      80.Mex_Am                                             -0.235       0.454

8      80.Oth_H                                               0.303       0.576

9      80.Oth_NH                                              1.052       0.550

10     90.Mex_Am                                              0.489       0.576

11     90.Oth_H                                              -0.176       0.656

12     90.Oth_NH                                              0.924       0.772

13     90.Wht_NH                                             -0.281       0.524

     mgen

14     US native                                              2.807**     0.610

     meth.mgen

15     Mex_Am.US native                                      -1.128*      0.496

16     Oth_H.US native                                       -1.639**     0.492

17     Oth_NH.US native                                      -3.125**     0.776

18     Wht_NH.US native                                      -0.049       0.500

     year.meth.mgen

19     80.Oth_H.US native                                    -1.561**     0.573

20     80.Oth_NH.US native                                   -0.719       0.725

21     80.Wht_NH.US native                                   -0.160       0.312

22     90.Mex_Am.US native                                   -0.377       0.591

23     90.Oth_H.US native                                    -0.658       0.465

24     90.Oth_NH.US native                                   -0.320       0.494

25     90.Wht_NH.US native                                    0.127       0.576

     fgen

26     US native                                              2.919**     0.815

     meth.fgen

27     Mex_Am.US native                                       1.029*      0.404

28     Oth_H.US native                                        0.290       0.382

29     Wht_NH.US native                                       0.547       0.427

     year.meth.fgen

30     80.Mex_Am.US native                                    0.523       0.592

31     80.Wht_NH.US native                                    0.211       0.527

32     90.Oth_H.US native                                     0.307       0.377

33     90.Oth_NH.US native                                   -0.147       0.561

     year.mgen.fgen

34     80.US native.US native                                 0.126       0.600

35     90.US native.US native                                -0.172       0.598

     meth.mgen.fgen

36     Oth_NH.US native.US native                             1.358*      0.629

     year.meth.mgen.fgen

37     80.Mex_Am.US native.US native                         -0.381       0.474

38     80.Oth_H.US native.US native                           0.541       0.374

39     80.Oth_NH.US native.US native                          0.119       0.561

40     80.Wht_NH.US native.US native                          0.186       0.605

41     90.Mex_Am.US native.US native                          0.069       0.400

42     90.Wht_NH.US native.US native                          0.434       0.317

     feth

43     Mex_Am                                                 2.632**     0.959

44     Oth_H                                                  3.799**     0.955

45     Oth_NH                                                 2.278**     0.800

46     Wht_NH                                                 2.854**     0.870

     year.feth

47     80.Mex_Am                                              0.144       0.563

48     80.Oth_H                                              -1.074       0.960

49     80.Oth_NH                                              0.114       0.963

50     80.Wht_NH                                             -0.635       0.803

51     90.Mex_Am                                             -1.099       0.950

52     90.Oth_H                                              -1.257       0.946

53     90.Oth_NH                                             -0.805       0.949

54     90.Wht_NH                                             -1.842*      0.786

     year.fgen

55     80.US native                                          -1.093       0.976

56     90.US native                                          -1.539       0.961

     feth.fgen

57     Mex_Am.US native                                      -1.799*      0.765

58     Oth_H.US native                                       -2.284**     0.761

59     Oth_NH.US native                                      -2.939**     0.921

60     Wht_NH.US native                                      -0.383       0.783

     year.feth.fgen

61     80.Oth_H.US native                                     0.138       0.771

62     80.Oth_NH.US native                                    0.534       0.771

63     80.Wht_NH.US native                                    0.716       0.870

64     90.Mex_Am.US native                                    1.572*      0.758

65     90.Oth_H.US native                                     0.758       0.753

66     90.Oth_NH.US native                                    1.310       0.752

67     90.Wht_NH.US native                                    1.829*      0.855

     feth.mgen

68     Mex_Am.US native                                       0.570       0.495

69     Oth_H.US native                                        0.053       0.485

70     Wht_NH.US native                                       0.259       0.405

     year.feth.mgen

71     80.Mex_Am.US native                                   -1.370       0.881

72     80.Oth_H.US native                                     0.246       0.470

73     80.Oth_NH.US native                                   -0.234       0.570

74     90.Mex_Am.US native                                   -0.365       0.478

75     90.Oth_H.US native                                    -0.153       0.469

76     90.Oth_NH.US native                                   -0.266       0.572

     feth.fgen.mgen

77     Oth_NH.US native.US native                             0.156       0.560

     year.feth.fgen.mgen

78     80.Mex_Am.US native.US native                          1.103       0.777

79     80.Wht_NH.US native.US native                          0.103       0.420

80     90.Wht_NH.US native.US native                          0.032       0.421

     ethintct

81     1                                                      3.031**     0.897

82     2                                                      2.433**     0.729

83     3                                                     -3.083**     0.768

84     5                                                      3.492**     0.573

     ethintct.year

85     1.80                                                   1.195       1.089

86     1.90                                                  -0.817       0.891

87     2.90                                                   0.028       0.518

88     3.80                                                   1.327*      0.524

89     3.90                                                   3.894**     0.696

90     4.80                                                  -1.211       0.686

91     4.90                                                  -0.948       0.686

92     5.80                                                  -0.614       0.489

93     5.90                                                   0.190       0.598

     ethintct.fgen

94     1.US native                                            0.622       1.043

95     2.US native                                            0.149       0.493

96     3.US native                                            3.504**     0.536

97     4.US native                                            3.722**     0.665

98     5.US native                                           -0.402       0.552

     ethintct.year.fgen

99     1.80.US native                                        -0.665       0.863

100    1.90.US native                                         1.120       1.027

101    2.80.US native                                         0.301       0.513

102    2.90.US native                                        -0.253       0.496

103    3.90.US native                                        -2.872**     0.442

104    4.80.US native                                        -0.438       0.809

105    4.90.US native                                        -0.392       0.809

106    5.90.US native                                        -0.547       0.315

     ethintct.mgen

107    2.US native                                           -0.064       0.426

108    3.US native                                            2.137**     0.422

109    4.US native                                            4.088**     0.735

     ethintct.year.mgen

110    1.80.US native                                        -1.171       0.635

111    2.80.US native                                         0.667       0.515

112    3.80.US native                                         0.982       0.554

113    3.90.US native                                        -1.729**     0.380

114    5.80.US native                                        -0.319       0.427

115    5.90.US native                                        -0.755*      0.331

     ethintct.fgen.mgen

116    1.US native.US native                                  2.407**     0.642

117    4.US native.US native                                 -2.374*      0.944

118    5.US native.US native                                  1.235**     0.384

     ethintct.year.fgen.mgen

119    1.90.US native.US native                              -1.402*      0.634

120    2.80.US native.US native                              -0.828       0.643

121    2.90.US native.US native                              -0.230       0.376

122    3.80.US native.US native                              -2.812**     0.442

123    4.80.US native.US native                               0.246       0.582

124    4.90.US native.US native                               0.070       0.584

125    5.80.US native.US native                              -0.166       0.312

     BWS

126    1                                                     -0.666       0.345

     QS

127    BW                                                     0.165       0.515

128    Moh                                                   -0.209       0.559

129    BM                                                    -3.206**     0.596

130    WO                                                     1.447**     0.485

131    OOh                                                   -1.823**     0.398

     QS.year

132    BW.80                                                 -0.743       0.455

133    BW.90                                                 -0.345       0.456

134    Moh.80                                                 0.376       0.405

135    Moh.90                                                 0.055       0.408

136    BM.80                                                  1.189**     0.447

137    BM.90                                                  1.260**     0.447

138    WO.80                                                 -0.482       0.324

139    WO.90                                                 -0.173       0.328

140    OOh.80                                                 0.353       0.336

141    OOh.90                                                 0.589       0.336

     QS.mgen

142    BW.US native                                          -0.281       0.227

143    Moh.US native                                         -0.669**     0.235

144    BM.US native                                           0.082       0.228

145    WO.US native                                           0.431*      0.213

146    OOh.US native                                          1.031**     0.168

     QS.fgen

147    BW.US native                                          -0.132       0.175

148    Moh.US native                                         -0.223       0.342

149    BM.US native                                           0.667       0.346

150    WO.US native                                          -0.357       0.321

151    OOh.US native                                          0.439*      0.175

     BOhS

152    1                                                     -1.556**     0.319

     BOhS.fgen

153    1.US native                                            0.866**     0.324

     BWS.year

154    1.80                                                   0.874*      0.351

155    1.90                                                   0.771*      0.351

156  _cons                                                   -3.353**     1.033

--------------------------------------------------------------------------------

*  p < .05

** p < .01

 

. poisgof

 

         Goodness-of-fit chi2  =  107.3149

         Prob > chi2(69)       =    0.0022

 

. *This is our standard best-fitting model, see HW3 solutions.

. ereturn list

 

scalars:

                e(rc) =  0

                e(ll) =  -719.6574483966351

              e(rank) =  156

              e(df_m) =  155

              e(ll_0) =  -2252613.647448859

              e(chi2) =  4503787.980000925

                 e(p) =  0

                 e(k) =  156

              e(k_eq) =  1

              e(k_dv) =  1

                e(ic) =  27

                 e(N) =  225

              e(r2_p) =  .999680523355964

 

macros:

               e(cmd) : "poisson"

           e(predict) : "poisso_p"

               e(gof) : "poiss_g"

               e(opt) : "ml"

             e(title) : "Poisson regression"

            e(depvar) : "count"

              e(user) : "poiss_lf"

          e(chi2type) : "LR"

          e(crittype) : "log likelihood"

         e(technique) : "nr"

 

matrices:

                 e(b) :  1 x 156

                 e(V) :  156 x 156

              e(ilog) :  1 x 20

 

functions:

            e(sample)  

 

. *That's  a list of the scalars and vectors that Stata returns from this Poisson model.

  Here we're interested in the 1X156 row vector of betas

. matrix Beta=e(b)

 

. matrix list Beta

 

Beta[1,156]

         count:      count:      count:      count:      count:      count:

          _x_1        _x_2        _x_3        _x_4        _x_5        _x_6

y1   3.2869204   3.7700542   .43358739   1.7633315   .01253832    .9769788

 

         count:      count:      count:      count:      count:      count:

          _x_7        _x_8        _x_9       _x_10       _x_11       _x_12

y1  -.23465188   .30295306   1.0520822   .48875664   -.1760566   .92414225

 

         count:      count:      count:      count:      count:      count:

         _x_13       _x_14       _x_15       _x_16       _x_17       _x_18

y1  -.28059816   2.8071998  -1.1281639  -1.6393877  -3.1250781  -.04852231

 

         count:      count:      count:      count:      count:      count:

         _x_19       _x_20       _x_21       _x_22       _x_23       _x_24

y1  -1.5612392  -.71857409  -.15950741  -.37655768  -.65777948  -.32008149

 

         count:      count:      count:      count:      count:      count:

         _x_25       _x_26       _x_27       _x_28       _x_29       _x_30

y1   .12706574   2.9187596   1.0289497   .29048598   .54702787   .52297876

 

         count:      count:      count:      count:      count:      count:

         _x_31       _x_32       _x_33       _x_34       _x_35       _x_36

y1   .21106579   .30729173  -.14720171   .12577605  -.17161296   1.3584232

 

         count:      count:      count:      count:      count:      count:

         _x_37       _x_38       _x_39       _x_40       _x_41       _x_42

y1   -.3814812   .54116319   .11923114    .1863524   .06878716   .43389722

 

         count:      count:      count:      count:      count:      count:

         _x_43       _x_44       _x_45       _x_46       _x_47       _x_48

y1   2.6321063   3.7988162   2.2784686   2.8537647   .14389156  -1.0743172

 

         count:      count:      count:      count:      count:      count:

         _x_49       _x_50       _x_51       _x_52       _x_53       _x_54

y1   .11391668  -.63511572   -1.098611  -1.2572167  -.80499828  -1.8419964

 

         count:      count:      count:      count:      count:      count:

         _x_55       _x_56       _x_57       _x_58       _x_59       _x_60

y1  -1.0934443  -1.5390904  -1.7994081  -2.2841935     -2.9394  -.38295778

 

         count:      count:      count:      count:      count:      count:

         _x_61       _x_62       _x_63       _x_64       _x_65       _x_66

y1   .13812306   .53358184   .71563823   1.5717381   .75845413   1.3103602

 

         count:      count:      count:      count:      count:      count:

         _x_67       _x_68       _x_69       _x_70       _x_71       _x_72

y1    1.828874   .56995392   .05318183   .25902384  -1.3704785   .24578408

 

         count:      count:      count:      count:      count:      count:

         _x_73       _x_74       _x_75       _x_76       _x_77       _x_78

y1  -.23375311   -.3649057  -.15294013  -.26608244    .1555132   1.1026879

 

         count:      count:      count:      count:      count:      count:

         _x_79       _x_80       _x_81       _x_82       _x_83       _x_84

y1   .10310933   .03230763   3.0307771   2.4327198  -3.0825601   3.4921156

 

         count:      count:      count:      count:      count:      count:

         _x_85       _x_86       _x_87       _x_88       _x_89       _x_90

y1   1.1952326  -.81688153   .02817678    1.326957   3.8943289  -1.2114301

 

         count:      count:      count:      count:      count:      count:

         _x_91       _x_92       _x_93       _x_94       _x_95       _x_96

y1   -.9484894  -.61415828   .18959996    .6224094   .14900682   3.5037786

 

         count:      count:      count:      count:      count:      count:

         _x_97       _x_98       _x_99      _x_100      _x_101      _x_102

y1    3.721761  -.40233953  -.66478522   1.1196146   .30062456  -.25332848

 

         count:      count:      count:      count:      count:      count:

        _x_103      _x_104      _x_105      _x_106      _x_107      _x_108

y1  -2.8721667  -.43788223  -.39164979  -.54707785  -.06359967   2.1373953

 

         count:      count:      count:      count:      count:      count:

        _x_109      _x_110      _x_111      _x_112      _x_113      _x_114

y1   4.0879918   -1.171002   .66687121   .98199656  -1.7294296  -.31868311

 

         count:      count:      count:      count:      count:      count:

        _x_115      _x_116      _x_117      _x_118      _x_119      _x_120

y1  -.75490313    2.406866  -2.3740311   1.2348699   -1.401947  -.82763492

 

         count:      count:      count:      count:      count:      count:

        _x_121      _x_122      _x_123      _x_124      _x_125      _x_126

y1  -.23046204  -2.8118997   .24555963   .06996171  -.16625366  -.66579793

 

         count:      count:      count:      count:      count:      count:

        _x_127      _x_128      _x_129      _x_130      _x_131      _x_132

y1   .16480739  -.20932904  -3.2063324   1.4469877  -1.8229311  -.74324886

 

         count:      count:      count:      count:      count:      count:

        _x_133      _x_134      _x_135      _x_136      _x_137      _x_138

y1  -.34462742   .37588769   .05487745   1.1887734   1.2598056  -.48216016

 

         count:      count:      count:      count:      count:      count:

        _x_139      _x_140      _x_141      _x_142      _x_143      _x_144

y1  -.17270311   .35323583   .58866352  -.28063573  -.66877213   .08222256

 

         count:      count:      count:      count:      count:      count:

        _x_145      _x_146      _x_147      _x_148      _x_149      _x_150

y1   .43120917   1.0312175  -.13191066   -.2230634   .66718537  -.35670532

 

         count:      count:      count:      count:      count:      count:

        _x_151      _x_152      _x_153      _x_154      _x_155       _cons

y1   .43947399  -1.5557027   .86619598   .87401659   .77134793  -3.3530702

 

. *These are all the Betas from the model.  We want to ignore the constant

and all the background terms,

 and only look at the 81st through 155th terms, w

hich carry the racial interactions by time and generation.

. matrix Beta_z=Beta

 

. matrix Beta_z[1,156]=0

 

. *That zeros out the constant

. matrix Beta_z[1,1]=J(1,80,0)

 

. *And that zeros out the first 80 terms, the background terms

. *So we have a new Beta that has only the terms of interest.

. matrix Beta_z=Beta_z'

 

. *We now transpose our new Beta vector so it's a column vector.

. *Now let's form our X matrix from our dummy variables

. mkmat _x*, matrix(X_mat)

 

. *Easy as that

. matrix dir

        X_mat[225,155]

       Beta_z[156,1]

         Beta[1,156]

 

. *Our new X_mat has only 155 columns, so we need to add a 'ones' column to account for the constant term.  In reality since we've forced the constant term to

be zero in our beta vector, it doesn't matter what we put in this place, but

we'll put ones just to be proper.

. matrix X_mat_plus=X_mat, J(225,1,1)

 

. *The comma above joins the matrix with a column vector

. matrix dir

    X_mat_plus[225,156]

        X_mat[225,155]

       Beta_z[156,1]

         Beta[1,156]

 

. *now we have an X matrix in the right shape

. matrix XB=X_mat_plus*Beta_z

 

. matrix dir

           XB[225,1]

    X_mat_plus[225,156]

        X_mat[225,155]

       Beta_z[156,1]

         Beta[1,156]

 

. *Now we have a new column vector with values for each cell that reflect all the

 coefficients we're interested in.

 

. svmat XB, names(log_or)

 

. *That gives us a new variable, named log_or

. table meth feth, contents(sum log_or) by(year mgen fgen)

 

-----------------------------------------------------------------

year,     |

mgen,     |

fgen and  |                         feth                        

meth      |    Blk_NH     Mex_Am      Oth_H     Oth_NH     Wht_NH

----------+------------------------------------------------------

70        |

foreign   |

foreign   |

   Blk_NH |                                                     

   Mex_Am |                                                     

    Oth_H |                                                      

   Oth_NH |                                                     

   Wht_NH |                                                     

----------+------------------------------------------------------

70        |

foreign   |

US native |

   Blk_NH |  3.653187  -2.539147  -.6895067          0  -.6329012

   Mex_Am | -2.539147   2.581727  -.4323924          0          0

    Oth_H |         0  -.4323924   .4212185  -1.383457          0

   Oth_NH |         0          0  -1.383457   3.721761   1.090282

   Wht_NH |  .0328967          0          0   1.090282   3.089776

----------+------------------------------------------------------

70        |

US native |

foreign   |

   Blk_NH |  3.030777   -3.12411  -1.555703          0  -.7816263

   Mex_Am |  -3.12411    2.36912  -.8781012          0          0

    Oth_H |         0  -.8781012  -.9451648  -.7917137          0

   Oth_NH |         0          0  -.7917137   4.087992   1.878197

   Wht_NH | -.1158283          0          0   1.878197   3.492115

----------+------------------------------------------------------

70        |

US native |

US native |

   Blk_NH |  6.060052  -2.456924  -.6895067          0  -.9135369

   Mex_Am | -2.456924   2.518127  -1.101165          0          0

    Oth_H |         0  -1.101165   2.558614  -.3522396          0

   Oth_NH |         0          0  -.3522396   5.435722   1.521492

   Wht_NH |  -.247739          0          0   1.521492   4.324646

----------+------------------------------------------------------

80        |

foreign   |

foreign   |

   Blk_NH |                                                     

   Mex_Am |                                                     

    Oth_H |                                                     

   Oth_NH |                                                     

   Wht_NH |                                                     

----------+------------------------------------------------------

80        |

foreign   |

US native |

   Blk_NH |  4.183634  -1.350374  -.6895067          0  -.5021335

   Mex_Am | -1.350374   2.882351  -.0565048          0          0

    Oth_H |         0  -.0565048   1.748176  -1.030221          0

   Oth_NH |         0          0  -1.030221   2.072449   .6081222

   Wht_NH | -.7103521          0          0   .6081222   2.475618

----------+------------------------------------------------------

80        |

US native |

foreign   |

   Blk_NH |  3.055008  -1.935336  -1.555703          0  -.6508585

   Mex_Am | -1.935336   3.035991  -.5022135          0          0

    Oth_H |         0  -.5022135   1.363789  -.4384778          0

   Oth_NH |         0          0  -.4384778   2.876562   1.396037

   Wht_NH | -.8590772          0          0   1.396037   2.559274

----------+------------------------------------------------------

80        |

US native |

US native |

   Blk_NH |  5.419498  -1.268151  -.6895067          0  -.7827692

   Mex_Am | -1.268151   2.657988  -.7252769          0          0

    Oth_H |         0  -.7252769   2.055668   .0009962          0

   Oth_NH |         0          0   .0009962   4.031969   1.039331

   Wht_NH | -.9909878          0          0   1.039331   3.225551

----------+------------------------------------------------------

90        |

foreign   |

foreign   |

   Blk_NH |                                                     

   Mex_Am |                                                     

    Oth_H |                                                     

   Oth_NH |                                                      

   Wht_NH |                                                     

----------+------------------------------------------------------

90        |

foreign   |

US native |

   Blk_NH |   3.95592  -1.279341  -.6895067          0  -.2061807

   Mex_Am | -1.279341   2.356575   -.377515          0          0

    Oth_H |         0   -.377515   1.443381  -.7947936          0

   Oth_NH |         0          0  -.7947936   2.381622   .9175793

   Wht_NH | -.3117307          0          0   .9175793   2.732298

----------+------------------------------------------------------

90        |

US native |

foreign   |

   Blk_NH |  2.213896  -1.864304  -1.555703          0  -.3549058

   Mex_Am | -1.864304   2.397297  -.8232237          0          0

    Oth_H |         0  -.8232237   1.219735  -.2030501          0

   Oth_NH |         0          0  -.2030501   3.139502   1.705494

   Wht_NH | -.4604558          0          0   1.705494   2.926812

----------+------------------------------------------------------

90        |

US native |

US native |

   Blk_NH |  4.960838  -1.197119  -.6895067          0  -.4868164

   Mex_Am | -1.197119   2.062513  -1.046287          0          0

    Oth_H |         0  -1.046287   1.851346   .2364239          0

   Oth_NH |         0          0   .2364239   4.165544   1.348788

   Wht_NH | -.5923664          0          0   1.348788   3.212265

-----------------------------------------------------------------

 

. *And that's our coefficient addition, same as by hand but faster and more accurate.

. log close

--------------------------------------------------------------------------------