UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

Stata Textbook Examples
Econometric Analysis of Cross Section and Panel Data by Jeffrey M. Wooldridge
Chapter 19: Count Data and Related Models

The data files used for the examples in this text can be downloaded in a zip file from the Stata Web site. You can then use a program such as WinZip to unzip the data files.
Example 19.1 on page 652 using fertil2.dta.
use fertil2, clear

reg children educ age agesq evermarr urban electric tv

      Source |       SS       df       MS              Number of obs =    4358
-------------+------------------------------           F(  7,  4350) =  893.91
       Model |  12688.9349     7  1812.70499           Prob > F      =  0.0000
    Residual |  8821.09719  4350  2.02783843           R-squared     =  0.5899
-------------+------------------------------           Adj R-squared =  0.5892
       Total |  21510.0321  4357  4.93689055           Root MSE      =   1.424

------------------------------------------------------------------------------
    children |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        educ |  -.0644086   .0063199   -10.19   0.000    -.0767987   -.0520184
         age |   .2724736    .017019    16.01   0.000     .2391077    .3058395
       agesq |  -.0019067    .000274    -6.96   0.000    -.0024438   -.0013696
    evermarr |   .6822725    .052167    13.08   0.000     .5799986    .7845463
       urban |  -.2278933   .0458653    -4.97   0.000    -.3178126    -.137974
    electric |  -.2617394   .0758688    -3.45   0.001     -.410481   -.1129979
          tv |  -.2499509   .0901474    -2.77   0.006    -.4266858   -.0732161
       _cons |   -3.39384   .2445496   -13.88   0.000    -3.873281   -2.914398
------------------------------------------------------------------------------

glm children educ age agesq evermarr urban electric tv, fam(poisson) link(log) robust

Generalized linear models                          No. of obs      =      4358
Optimization     : ML: Newton-Raphson              Residual df     =      4350
                                                   Scale parameter =         1
Deviance         =   3908.76293                    (1/df) Deviance =  .8985662
Pearson          =  3265.867362                    (1/df) Pearson  =  .7507741

Variance function: V(u) = u                        [Poisson]
Link function    : g(u) = ln(u)                    [Log]
Standard errors  : Sandwich

Log pseudo-likelihood = -6497.059873               AIC             =  2.985342
BIC                   =-32543.23011

------------------------------------------------------------------------------
             |               Robust
    children |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        educ |  -.0216645   .0025918    -8.36   0.000    -.0267442   -.0165847
         age |   .3373308   .0094473    35.71   0.000     .3188144    .3558473
       agesq |  -.0041158    .000144   -28.57   0.000    -.0043981   -.0038335
    evermarr |    .314751   .0232117    13.56   0.000      .269257     .360245
       urban |  -.0860549   .0200471    -4.29   0.000    -.1253465   -.0467633
    electric |  -.1205347   .0372925    -3.23   0.001    -.1936266   -.0474428
          tv |  -.1447046   .0438055    -3.30   0.001    -.2305617   -.0588475
       _cons |  -5.374829   .1477633   -36.37   0.000     -5.66444   -5.085219
------------------------------------------------------------------------------

predict res, r
(3 missing values generated)

predict p
(option mu assumed; predicted mean children)
(3 missing values generated)

gen stdressq = res^2/p
(3 missing values generated)

sum stdressq

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
    stdressq |      4358    .7493959    1.076655   6.55e-07   14.37877

di sqrt(r(mean)*r(N)/(r(N)-7)) /*R-squared for Poisson regression*/
.86637264
Example 19.2 on page 665 using fertil2.dta.
reg educ frsthalf age agesq evermarr urban electric tv

      Source |       SS       df       MS              Number of obs =    4358
-------------+------------------------------           F(  7,  4350) =  208.02
       Model |  16850.0414     7  2407.14877           Prob > F      =  0.0000
    Residual |    50336.75  4350  11.5716667           R-squared     =  0.2508
-------------+------------------------------           Adj R-squared =  0.2496
       Total |  67186.7914  4357  15.4204249           Root MSE      =  3.4017

------------------------------------------------------------------------------
        educ |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
    frsthalf |  -.6361072   .1038091    -6.13   0.000    -.8396258   -.4325885
         age |  -.0702853   .0406438    -1.73   0.084    -.1499678    .0093971
       agesq |  -.0008118   .0006544    -1.24   0.215    -.0020947    .0004711
    evermarr |  -.8023536   .1241223    -6.46   0.000    -1.045697   -.5590106
       urban |   .8637296    .108786     7.94   0.000     .6504536    1.077006
    electric |   1.977712   .1787579    11.06   0.000     1.627255    2.328168
          tv |   2.714666   .2113782    12.84   0.000     2.300257    3.129075
       _cons |    8.20343   .5752279    14.26   0.000     7.075691     9.33117
------------------------------------------------------------------------------

predict r, r
(3 missing values generated)

glm children educ age agesq evermarr urban electric tv r, fam(poisson) link(log) robust

Generalized linear models                          No. of obs      =      4358
Optimization     : ML: Newton-Raphson              Residual df     =      4349
                                                   Scale parameter =         1
Deviance         =  3908.184386                    (1/df) Deviance =  .8986398
Pearson          =  3264.568982                    (1/df) Pearson  =  .7506482

Variance function: V(u) = u                        [Poisson]
Link function    : g(u) = ln(u)                    [Log]
Standard errors  : Sandwich

Log pseudo-likelihood =   -6496.7706               AIC             =  2.985668
BIC                   =-32535.42889

------------------------------------------------------------------------------
             |               Robust
    children |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
        educ |  -.0459847   .0295654    -1.56   0.120    -.1039319    .0119625
         age |   .3357196   .0097048    34.59   0.000     .3166986    .3547405
       agesq |  -.0041373   .0001451   -28.52   0.000    -.0044216   -.0038529
    evermarr |   .2941007   .0343224     8.57   0.000       .22683    .3613714
       urban |  -.0647957   .0323494    -2.00   0.045    -.1281994    -.001392
    electric |  -.0711916   .0688407    -1.03   0.301    -.2061168    .0637337
          tv |  -.0780223   .0937508    -0.83   0.405    -.2617705    .1057258
           r |    .024515   .0296235     0.83   0.408     -.033546    .0825761
       _cons |   -5.18482   .2767832   -18.73   0.000    -5.727305   -4.642335
------------------------------------------------------------------------------

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.