-------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  c:\acdbookrevision\stata_final_programs_2013\racd10.txt
  log type:  text
 opened on:  21 Jan 2013, 16:26:28

. 
. ********** OVERVIEW OF racd10.do **********
. 
. * STATA Program 
. * copyright C 2013 by A. Colin Cameron and Pravin K. Trivedi 
. * used for "Regression Analyis of Count Data" SECOND EDITION
. * by A. Colin Cameron and Pravin K. Trivedi (2013)
. * Cambridge University Press
. 
. * This STATA program analyzes doctor visits data for chapter 10
. *  10.5 EXAMPLE: DOCTOR VISITS AND HEALTH INSURANCE
. 
. * To run you need file
. *   racd10data.dta
. * in your directory
. 
. * And you need Stata user-written program
. *   mtreatreg
. * in your directory
. 
. * To speed up program reduce the number of bootstraps
. 
. ********** SETUP **********
. 
. set more off

. version 12

. clear all

. * set mem 10m
. * set linesize 82
. set scheme s1mono  /* Graphics scheme */

. * set maxvar 100 width 1000
.  
. ********** DATA DESCRIPTION
. 
. * The original data are from 
. * P. Deb and P.K. Trivedi (2006a), "Specification and simulated 
. * likelihood estimation of a nonnormal treatment-outcome model with
. * selection: application to health care utilization," 
. * Econometrics Journal 9: 307-331.
. * See this article for more detailed discussion 
. 
. ********** 10.5.1 READ DATA, DROP OBSERVATIONS, AND SUMMARIZE 
. 
. use racd10data.dta, clear

. 
. * Drop some observations before analysis
. drop if docvis > 70
(3 observations deleted)

. drop if private==1 & medicaid==1
(45 observations deleted)

. 
. describe

Contains data from racd10data.dta
  obs:         3,629                          
 vars:            21                          26 Jan 2012 15:37
 size:       192,337                          
-------------------------------------------------------------------------------------------------------------------------------
              storage  display     value
variable name   type   format      label      variable label
-------------------------------------------------------------------------------------------------------------------------------
offer           byte   %8.0g                  =1 if employer offers insurance
ssiratio        float  %9.0g                   ratio of SSI income to toatl income
age             byte   %8.0g                  Age
educyr          byte   %8.0g                  Years of education
physician       int    %8.0g                  #Visits to doctor
nonphysician    int    %8.0g                  #Visits to health professional, but not doctor
medicaid        byte   %8.0g                  =1 if has Medicaid public insurance
private         byte   %8.0g                  =1 if has private supplementary insurance
female          byte   %8.0g                  =1 if female
phylim          byte   %8.0g                  =1 if physical limitation
actlim          byte   %8.0g                  =1 if activity limitation
income          float  %9.0g                  Income
totchr          byte   %8.0g                  # chronic conditions
insured         float  %9.0g                  =1 if has private supplementary insurance
age2            float  %9.0g                  Age-squared
linc            float  %9.0g                  log(income)
bh              float  %9.0g                  =1 if black or Hispanic
docvis          float  %9.0g                  # doctor visits
ldocvis         float  %9.0g                  log(docvis) if docvis >0
ldocvisa        float  %9.0g                  log(docvis+.01)
docbin          float  %9.0g                  
-------------------------------------------------------------------------------------------------------------------------------
Sorted by:  
     Note:  dataset has changed since last saved

. summarize

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
       offer |      3629    .0341692    .1816886          0          1
    ssiratio |      3629    .5299119    .3712278          0   3.210616
         age |      3629    74.23202    6.379764         65         90
      educyr |      3629    11.18187    3.831986          0         17
   physician |      3629    6.744833    6.751408          0         59
-------------+--------------------------------------------------------
nonphysician |      3629    2.703224    7.758116          0        187
    medicaid |      3629    .1559658    .3628729          0          1
     private |      3629    .4907688    .4999837          0          1
      female |      3629    .5993387       .4901          0          1
      phylim |      3629    .4659686    .4989093          0          1
-------------+--------------------------------------------------------
      actlim |      3629     .332323     .471111          0          1
      income |      3629    20.26295    21.46129         -1     312.46
      totchr |      3629    1.841554     1.35019          0          8
     insured |      3629    .4907688    .4999837          0          1
        age2 |      3629    5551.083    959.3996       4225       8100
-------------+--------------------------------------------------------
        linc |      3499    2.676676    .9077517  -4.710531   5.744476
          bh |      3629    .2551667     .436015          0          1
      docvis |      3629    6.744833    6.751408          0         59
     ldocvis |      3237    1.667428    .8785539          0   4.077538
    ldocvisa |      3629    .9898702    2.116712   -4.60517   4.077538
-------------+--------------------------------------------------------
      docbin |      3629    .8919813    .3104469          0          1

. tabulate docvis

   # doctor |
     visits |      Freq.     Percent        Cum.
------------+-----------------------------------
          0 |        392       10.80       10.80
          1 |        312        8.60       19.40
          2 |        353        9.73       29.13
          3 |        329        9.07       38.19
          4 |        338        9.31       47.51
          5 |        261        7.19       54.70
          6 |        228        6.28       60.98
          7 |        199        5.48       66.46
          8 |        179        4.93       71.40
          9 |        152        4.19       75.59
         10 |        107        2.95       78.53
         11 |        125        3.44       81.98
         12 |         89        2.45       84.43
         13 |         85        2.34       86.77
         14 |         79        2.18       88.95
         15 |         69        1.90       90.85
         16 |         51        1.41       92.26
         17 |         41        1.13       93.39
         18 |         33        0.91       94.30
         19 |         27        0.74       95.04
         20 |         26        0.72       95.76
         21 |         19        0.52       96.28
         22 |         21        0.58       96.86
         23 |         17        0.47       97.33
         24 |         14        0.39       97.71
         25 |          6        0.17       97.88
         26 |          5        0.14       98.02
         27 |         11        0.30       98.32
         28 |          4        0.11       98.43
         29 |          6        0.17       98.59
         30 |          8        0.22       98.82
         31 |          2        0.06       98.87
         32 |          6        0.17       99.04
         33 |          3        0.08       99.12
         34 |          3        0.08       99.20
         35 |          5        0.14       99.34
         36 |          1        0.03       99.37
         37 |          2        0.06       99.42
         38 |          2        0.06       99.48
         39 |          2        0.06       99.53
         40 |          4        0.11       99.64
         41 |          1        0.03       99.67
         42 |          1        0.03       99.70
         43 |          2        0.06       99.75
         44 |          2        0.06       99.81
         47 |          2        0.06       99.86
         48 |          2        0.06       99.92
         50 |          1        0.03       99.94
         54 |          1        0.03       99.97
         59 |          1        0.03      100.00
------------+-----------------------------------
      Total |      3,629      100.00

. 
. ********** 10.5.2 ONE ENDOGENOUS REGRESSOR (private)
. 
. *** No endogeneity
. 
. global XLISTEXOG medicaid age age2 educyr actlim totchr

. 
. * Poisson
. poisson docvis private $XLISTEXOG, vce(robust)

Iteration 0:   log pseudolikelihood = -14287.962  
Iteration 1:   log pseudolikelihood = -14287.949  
Iteration 2:   log pseudolikelihood = -14287.949  

Poisson regression                                Number of obs   =       3629
                                                  Wald chi2(7)    =     800.22
                                                  Prob > chi2     =     0.0000
Log pseudolikelihood = -14287.949                 Pseudo R2       =     0.1296

------------------------------------------------------------------------------
             |               Robust
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |    .169514   .0358951     4.72   0.000      .099161    .2398671
    medicaid |   .0821526    .048155     1.71   0.088    -.0122294    .1765346
         age |    .291377   .0599239     4.86   0.000     .1739282    .4088258
        age2 |   -.001907   .0003986    -4.78   0.000    -.0026883   -.0011257
      educyr |   .0280664   .0046154     6.08   0.000     .0190204    .0371125
      actlim |   .1701243   .0363851     4.68   0.000     .0988107    .2414378
      totchr |   .2466393   .0113038    21.82   0.000     .2244842    .2687943
       _cons |  -10.13827   2.244194    -4.52   0.000    -14.53681   -5.739729
------------------------------------------------------------------------------

. estimates store P

. 
. * Negative binomial
. nbreg docvis private $XLISTEXOG, vce(robust)

Fitting Poisson model:

Iteration 0:   log pseudolikelihood = -14287.962  
Iteration 1:   log pseudolikelihood = -14287.949  
Iteration 2:   log pseudolikelihood = -14287.949  

Fitting constant-only model:

Iteration 0:   log pseudolikelihood = -10812.582  
Iteration 1:   log pseudolikelihood = -10786.692  
Iteration 2:   log pseudolikelihood = -10786.689  
Iteration 3:   log pseudolikelihood = -10786.689  

Fitting full model:

Iteration 0:   log pseudolikelihood = -10461.355  
Iteration 1:   log pseudolikelihood = -10406.915  
Iteration 2:   log pseudolikelihood = -10404.957  
Iteration 3:   log pseudolikelihood = -10404.956  
Iteration 4:   log pseudolikelihood = -10404.956  

Negative binomial regression                      Number of obs   =       3629
Dispersion           = mean                       Wald chi2(7)    =     748.12
Log pseudolikelihood = -10404.956                 Prob > chi2     =     0.0000

------------------------------------------------------------------------------
             |               Robust
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .1852818   .0367187     5.05   0.000     .1133144    .2572492
    medicaid |   .0847578   .0477144     1.78   0.076    -.0087607    .1782764
         age |   .2953122   .0630027     4.69   0.000     .1718292    .4187952
        age2 |  -.0019269    .000419    -4.60   0.000    -.0027482   -.0011056
      educyr |   .0269255    .004632     5.81   0.000      .017847     .036004
      actlim |   .1704804   .0363176     4.69   0.000     .0992993    .2416615
      totchr |   .2751617   .0126817    21.70   0.000     .2503061    .3000173
       _cons |  -10.37585   2.357934    -4.40   0.000    -14.99731   -5.754383
-------------+----------------------------------------------------------------
    /lnalpha |   -.483415   .0337391                     -.5495425   -.4172875
-------------+----------------------------------------------------------------
       alpha |   .6166739   .0208061                      .5772138    .6588315
------------------------------------------------------------------------------

. estimates store NB2

. 
. *** Control function for Endogeneity
. 
. * First stage regression
. regress private income ssiratio $XLISTEXOG, vce(robust)

Linear regression                                      Number of obs =    3629
                                                       F(  8,  3620) =  535.11
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.2404
                                                       Root MSE      =  .43624

------------------------------------------------------------------------------
             |               Robust
     private |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      income |    .002612   .0004684     5.58   0.000     .0016936    .0035304
    ssiratio |  -.0755889    .020675    -3.66   0.000    -.1161248    -.035053
    medicaid |  -.4732672   .0135616   -34.90   0.000    -.4998563    -.446678
         age |  -.0870886   .0290213    -3.00   0.003    -.1439884   -.0301888
        age2 |    .000549   .0001935     2.84   0.005     .0001696    .0009284
      educyr |   .0191878   .0020095     9.55   0.000     .0152479    .0231277
      actlim |  -.0228225   .0174173    -1.31   0.190    -.0569712    .0113263
      totchr |   .0210607   .0056451     3.73   0.000     .0099927    .0321286
       _cons |   3.723108   1.082708     3.44   0.001     1.600329    5.845888
------------------------------------------------------------------------------

. predict pres, residuals

. generate pressq = pres^2

. 
. * Poisson with residuals added
. * Standard errors here do not control for 2-step estimation
. * Instead use the bootstrap below 
. poisson docvis private $XLISTEXOG pres, vce(robust)

Iteration 0:   log pseudolikelihood = -14284.946  
Iteration 1:   log pseudolikelihood = -14284.933  
Iteration 2:   log pseudolikelihood = -14284.933  

Poisson regression                                Number of obs   =       3629
                                                  Wald chi2(8)    =     805.13
                                                  Prob > chi2     =     0.0000
Log pseudolikelihood = -14284.933                 Pseudo R2       =     0.1298

------------------------------------------------------------------------------
             |               Robust
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .4101744   .2288202     1.79   0.073    -.0383049    .8586537
    medicaid |   .1988853   .1190741     1.67   0.095    -.0344957    .4322664
         age |   .3167488   .0645511     4.91   0.000     .1902311    .4432665
        age2 |  -.0020666   .0004268    -4.84   0.000    -.0029031   -.0012301
      educyr |   .0221361   .0073286     3.02   0.003     .0077723       .0365
      actlim |    .179425   .0378674     4.74   0.000     .1052062    .2536438
      totchr |   .2419625   .0124466    19.44   0.000     .2175677    .2663573
        pres |  -.2458785    .228684    -1.08   0.282    -.6940909    .2023339
       _cons |   -11.2003   2.454156    -4.56   0.000    -16.01036   -6.390243
------------------------------------------------------------------------------

. estimates store PCF

. 
. * Negative binomial with residuals added 
. * Standard errors here do not control for 2-step estimation
. * Instead use the bootstrap below 
. nbreg docvis private $XLISTEXOG pres, vce(robust)

Fitting Poisson model:

Iteration 0:   log pseudolikelihood = -14284.946  
Iteration 1:   log pseudolikelihood = -14284.933  
Iteration 2:   log pseudolikelihood = -14284.933  

Fitting constant-only model:

Iteration 0:   log pseudolikelihood = -10812.582  
Iteration 1:   log pseudolikelihood = -10786.692  
Iteration 2:   log pseudolikelihood = -10786.689  
Iteration 3:   log pseudolikelihood = -10786.689  

Fitting full model:

Iteration 0:   log pseudolikelihood = -10460.321  
Iteration 1:   log pseudolikelihood = -10405.301  
Iteration 2:   log pseudolikelihood = -10403.262  
Iteration 3:   log pseudolikelihood =  -10403.26  
Iteration 4:   log pseudolikelihood =  -10403.26  

Negative binomial regression                      Number of obs   =       3629
Dispersion           = mean                       Wald chi2(8)    =     757.13
Log pseudolikelihood = -10403.26                  Prob > chi2     =     0.0000

------------------------------------------------------------------------------
             |               Robust
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .5955767   .2394801     2.49   0.013     .1262042    1.064949
    medicaid |   .2841287   .1241392     2.29   0.022     .0408204    .5274371
         age |   .3395244   .0677356     5.01   0.000      .206765    .4722838
        age2 |  -.0022051   .0004478    -4.92   0.000    -.0030829   -.0013274
      educyr |   .0169896   .0072951     2.33   0.020     .0026915    .0312877
      actlim |   .1855003   .0374633     4.95   0.000     .1120735    .2589271
      totchr |   .2677403    .013592    19.70   0.000     .2411004    .2943801
        pres |  -.4193073   .2398769    -1.75   0.080    -.8894574    .0508427
       _cons |  -12.22616   2.574876    -4.75   0.000    -17.27283   -7.179499
-------------+----------------------------------------------------------------
    /lnalpha |  -.4844278   .0337269                     -.5505314   -.4183242
-------------+----------------------------------------------------------------
       alpha |   .6160496   .0207775                      .5766433    .6581488
------------------------------------------------------------------------------

. estimates store NB2CF

. 
. * Program to return b for Poisson 2-step estimator of selection model 
. program poisson2step, eclass
  1.   version 12
  2.   tempname b V
  3.   capture drop pres pressq
  4.   regress private income ssiratio $XLISTEXOG, vce(robust)
  5.   predict pres, residuals
  6.   generate pressq = pres^2
  7.   poisson docvis private $XLISTEXOG pres
  8.   matrix `b' = e(b)
  9.   ereturn post `b' 
 10. end

. * Check preceding program by running once
. poisson2step

Linear regression                                      Number of obs =    3629
                                                       F(  8,  3620) =  535.11
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.2404
                                                       Root MSE      =  .43624

------------------------------------------------------------------------------
             |               Robust
     private |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      income |    .002612   .0004684     5.58   0.000     .0016936    .0035304
    ssiratio |  -.0755889    .020675    -3.66   0.000    -.1161248    -.035053
    medicaid |  -.4732672   .0135616   -34.90   0.000    -.4998563    -.446678
         age |  -.0870886   .0290213    -3.00   0.003    -.1439884   -.0301888
        age2 |    .000549   .0001935     2.84   0.005     .0001696    .0009284
      educyr |   .0191878   .0020095     9.55   0.000     .0152479    .0231277
      actlim |  -.0228225   .0174173    -1.31   0.190    -.0569712    .0113263
      totchr |   .0210607   .0056451     3.73   0.000     .0099927    .0321286
       _cons |   3.723108   1.082708     3.44   0.001     1.600329    5.845888
------------------------------------------------------------------------------

Iteration 0:   log likelihood = -14284.946  
Iteration 1:   log likelihood = -14284.933  
Iteration 2:   log likelihood = -14284.933  

Poisson regression                                Number of obs   =       3629
                                                  LR chi2(8)      =    4262.73
                                                  Prob > chi2     =     0.0000
Log likelihood = -14284.933                       Pseudo R2       =     0.1298

------------------------------------------------------------------------------
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .4101744   .0985647     4.16   0.000     .2169912    .6033576
    medicaid |   .1988853   .0515257     3.86   0.000     .0978969    .2998738
         age |   .3167488   .0281749    11.24   0.000      .261527    .3719706
        age2 |  -.0020666   .0001859   -11.12   0.000    -.0024309   -.0017023
      educyr |   .0221361   .0030692     7.21   0.000     .0161207    .0281516
      actlim |    .179425   .0152542    11.76   0.000     .1495273    .2093227
      totchr |   .2419625   .0050747    47.68   0.000     .2320162    .2519088
        pres |  -.2458785   .0995593    -2.47   0.014    -.4410111   -.0507459
       _cons |   -11.2003   1.072624   -10.44   0.000    -13.30261   -9.097997
------------------------------------------------------------------------------

. ereturn display
------------------------------------------------------------------------------
             |      Coef.
-------------+----------------------------------------------------------------
docvis       |
     private |   .4101744
    medicaid |   .1988853
         age |   .3167488
        age2 |  -.0020666
      educyr |   .0221361
      actlim |    .179425
      totchr |   .2419625
        pres |  -.2458785
       _cons |   -11.2003
------------------------------------------------------------------------------

. * Bootstrap for Poisson two-step estimator
. bootstrap _b, reps(400) seed(10101) nowarn: poisson2step
(running poisson2step on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Bootstrap results                               Number of obs      =      3629
                                                Replications       =       400

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .4101744   .2383667     1.72   0.085    -.0570158    .8773646
    medicaid |   .1988853   .1198318     1.66   0.097    -.0359807    .4337514
         age |   .3167488   .0638713     4.96   0.000     .1915633    .4419343
        age2 |  -.0020666   .0004229    -4.89   0.000    -.0028955   -.0012377
      educyr |   .0221361   .0078371     2.82   0.005     .0067757    .0374966
      actlim |    .179425   .0378189     4.74   0.000     .1053013    .2535487
      totchr |   .2419625    .012262    19.73   0.000     .2179295    .2659955
        pres |  -.2458785   .2385494    -1.03   0.303    -.7134268    .2216698
       _cons |   -11.2003    2.42088    -4.63   0.000    -15.94514   -6.455464
------------------------------------------------------------------------------

. estimates store PCFboot

. 
. * Program to return b for Negative binomial 2-step estimator of selection model 
. program NB2step, eclass
  1.   version 12
  2.   tempname b V
  3.   capture drop pres pressq
  4.   regress private income ssiratio $XLISTEXOG, vce(robust)
  5.   predict pres, residuals
  6.   generate pressq = pres^2
  7.   nbreg docvis private $XLISTEXOG pres
  8.   matrix `b' = e(b)
  9.   ereturn post `b' 
 10. end

. * Check preceding program by running once
. NB2step

Linear regression                                      Number of obs =    3629
                                                       F(  8,  3620) =  535.11
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.2404
                                                       Root MSE      =  .43624

------------------------------------------------------------------------------
             |               Robust
     private |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      income |    .002612   .0004684     5.58   0.000     .0016936    .0035304
    ssiratio |  -.0755889    .020675    -3.66   0.000    -.1161248    -.035053
    medicaid |  -.4732672   .0135616   -34.90   0.000    -.4998563    -.446678
         age |  -.0870886   .0290213    -3.00   0.003    -.1439884   -.0301888
        age2 |    .000549   .0001935     2.84   0.005     .0001696    .0009284
      educyr |   .0191878   .0020095     9.55   0.000     .0152479    .0231277
      actlim |  -.0228225   .0174173    -1.31   0.190    -.0569712    .0113263
      totchr |   .0210607   .0056451     3.73   0.000     .0099927    .0321286
       _cons |   3.723108   1.082708     3.44   0.001     1.600329    5.845888
------------------------------------------------------------------------------

Fitting Poisson model:

Iteration 0:   log likelihood = -14284.946  
Iteration 1:   log likelihood = -14284.933  
Iteration 2:   log likelihood = -14284.933  

Fitting constant-only model:

Iteration 0:   log likelihood = -10812.582  
Iteration 1:   log likelihood = -10786.692  
Iteration 2:   log likelihood = -10786.689  
Iteration 3:   log likelihood = -10786.689  

Fitting full model:

Iteration 0:   log likelihood = -10460.321  
Iteration 1:   log likelihood = -10405.301  
Iteration 2:   log likelihood = -10403.262  
Iteration 3:   log likelihood =  -10403.26  
Iteration 4:   log likelihood =  -10403.26  

Negative binomial regression                      Number of obs   =       3629
                                                  LR chi2(8)      =     766.86
Dispersion     = mean                             Prob > chi2     =     0.0000
Log likelihood = -10403.26                        Pseudo R2       =     0.0355

------------------------------------------------------------------------------
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .5955767   .2266821     2.63   0.009     .1512879    1.039865
    medicaid |   .2841287   .1186969     2.39   0.017     .0514871    .5167704
         age |   .3395244    .064331     5.28   0.000     .2134379    .4656108
        age2 |  -.0022051   .0004249    -5.19   0.000     -.003038   -.0013723
      educyr |   .0169896     .00685     2.48   0.013     .0035639    .0304153
      actlim |   .1855003   .0354233     5.24   0.000     .1160718    .2549288
      totchr |   .2677403   .0127178    21.05   0.000     .2428139    .2926667
        pres |  -.4193073    .229089    -1.83   0.067    -.8683135    .0296988
       _cons |  -12.22616   2.446314    -5.00   0.000    -17.02085   -7.431476
-------------+----------------------------------------------------------------
    /lnalpha |  -.4844278   .0313529                     -.5458784   -.4229772
-------------+----------------------------------------------------------------
       alpha |   .6160496    .019315                      .5793327    .6550936
------------------------------------------------------------------------------
Likelihood-ratio test of alpha=0:  chibar2(01) = 7763.35 Prob>=chibar2 = 0.000

. ereturn display
------------------------------------------------------------------------------
             |      Coef.
-------------+----------------------------------------------------------------
docvis       |
     private |   .5955767
    medicaid |   .2841287
         age |   .3395244
        age2 |  -.0022051
      educyr |   .0169896
      actlim |   .1855003
      totchr |   .2677403
        pres |  -.4193073
       _cons |  -12.22616
-------------+----------------------------------------------------------------
lnalpha      |
       _cons |  -.4844278
------------------------------------------------------------------------------

. * Bootstrap for Poisson two-step estimator
. bootstrap _b, reps(400) seed(10101) nowarn: NB2step
(running NB2step on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Bootstrap results                               Number of obs      =      3629
                                                Replications       =       400

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
docvis       |
     private |   .5955767   .2584521     2.30   0.021     .0890198    1.102133
    medicaid |   .2841287   .1282868     2.21   0.027     .0326912    .5355662
         age |   .3395244    .069167     4.91   0.000     .2039596    .4750892
        age2 |  -.0022051   .0004572    -4.82   0.000    -.0031011   -.0013091
      educyr |   .0169896   .0081035     2.10   0.036     .0011072    .0328721
      actlim |   .1855003   .0378704     4.90   0.000     .1112757    .2597249
      totchr |   .2677403   .0135019    19.83   0.000      .241277    .2942036
        pres |  -.4193073   .2576686    -1.63   0.104    -.9243286    .0857139
       _cons |  -12.22616   2.628887    -4.65   0.000    -17.37869    -7.07364
-------------+----------------------------------------------------------------
lnalpha      |
       _cons |  -.4844278   .0337942   -14.33   0.000    -.5506632   -.4181925
------------------------------------------------------------------------------

. estimates store NB2CFboot

. 
. *** GMM for endogeneity
. 
. * Additive heterogeneity - one step GMM
. gmm (docvis - exp({xb:private $XLISTEXOG}+{b0})),              ///
>   instruments(income ssiratio $XLISTEXOG) onestep vce(robust)

Step 1
Iteration 0:   GMM criterion Q(b) =  41.189479  
Iteration 1:   GMM criterion Q(b) =  4.7362062  
Iteration 2:   GMM criterion Q(b) =  .49016483  
Iteration 3:   GMM criterion Q(b) =  .01465891  
Iteration 4:   GMM criterion Q(b) =  .01320522  
Iteration 5:   GMM criterion Q(b) =  .01320518  

GMM estimation 

Number of parameters =   8
Number of moments    =   9
Initial weight matrix: Unadjusted                     Number of obs  =    3629

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 /xb_private |   .4518809   .2782494     1.62   0.104    -.0934778    .9972397
/xb_medicaid |    .248381   .1768957     1.40   0.160    -.0983283    .5950903
     /xb_age |   .3187113   .0650341     4.90   0.000     .1912469    .4461757
    /xb_age2 |  -.0020792   .0004301    -4.83   0.000    -.0029222   -.0012363
  /xb_educyr |    .022319   .0073138     3.05   0.002     .0079842    .0366538
  /xb_actlim |   .1813001   .0386059     4.70   0.000     .1056338    .2569663
  /xb_totchr |   .2413728   .0127057    19.00   0.000       .21647    .2662757
         /b0 |  -11.32244   2.495393    -4.54   0.000    -16.21332   -6.431556
------------------------------------------------------------------------------
Instruments for equation 1: income ssiratio medicaid age age2 educyr actlim totchr _cons

. estimates store GMMadd1S

. 
. * Additive heterogeneity - two step GMM
. gmm (docvis - exp({xb:private $XLISTEXOG}+{b0})),              ///
>   instruments(income ssiratio $XLISTEXOG) twostep vce(robust)

Step 1
Iteration 0:   GMM criterion Q(b) =  41.189479  
Iteration 1:   GMM criterion Q(b) =  4.7362062  
Iteration 2:   GMM criterion Q(b) =  .49016483  
Iteration 3:   GMM criterion Q(b) =  .01465891  
Iteration 4:   GMM criterion Q(b) =  .01320522  
Iteration 5:   GMM criterion Q(b) =  .01320518  

Step 2
Iteration 0:   GMM criterion Q(b) =  .00039161  
Iteration 1:   GMM criterion Q(b) =  .00038357  
Iteration 2:   GMM criterion Q(b) =  .00038357  

GMM estimation 

Number of parameters =   8
Number of moments    =   9
Initial weight matrix: Unadjusted                     Number of obs  =    3629
GMM weight matrix:     Robust

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 /xb_private |   .4456056   .2775002     1.61   0.108    -.0982848    .9894959
/xb_medicaid |    .247667   .1760894     1.41   0.160    -.0974619    .5927959
     /xb_age |   .3194941   .0650462     4.91   0.000     .1920059    .4469822
    /xb_age2 |  -.0020838   .0004302    -4.84   0.000    -.0029269   -.0012407
  /xb_educyr |   .0222492   .0073056     3.05   0.002     .0079305    .0365679
  /xb_actlim |   .1760243   .0383702     4.59   0.000     .1008202    .2512285
  /xb_totchr |   .2413189   .0127068    18.99   0.000      .216414    .2662238
         /b0 |  -11.34879   2.495686    -4.55   0.000    -16.24025   -6.457335
------------------------------------------------------------------------------
Instruments for equation 1: income ssiratio medicaid age age2 educyr actlim totchr _cons

. estimates store GMMadd2S

. estat overid

  Test of overidentifying restriction:

  Hansen's J chi2(1) = 1.39196 (p = 0.2381)

. 
. * Multiplicative heterogeneity - one step GMM 
. gmm ( (docvis / exp({xb:private $XLISTEXOG}+{b0})) - 1),      ///
>   instruments(income ssiratio $XLISTEXOG) onestep vce(robust)

Step 1
Iteration 0:   GMM criterion Q(b) =  41.189479  
Iteration 1:   GMM criterion Q(b) =  .18423738  
Iteration 2:   GMM criterion Q(b) =  .13582044  
Iteration 3:   GMM criterion Q(b) =  .00091458  
Iteration 4:   GMM criterion Q(b) =  .00026374  
Iteration 5:   GMM criterion Q(b) =  .00026347  
Iteration 6:   GMM criterion Q(b) =  .00026347  

GMM estimation 

Number of parameters =   8
Number of moments    =   9
Initial weight matrix: Unadjusted                     Number of obs  =    3629

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 /xb_private |   .6704558   .2503905     2.68   0.007     .1796994    1.161212
/xb_medicaid |   .2855124   .1035892     2.76   0.006     .0824813    .4885435
     /xb_age |   .3450055   .0720268     4.79   0.000     .2038356    .4861753
    /xb_age2 |  -.0022428   .0004766    -4.71   0.000    -.0031769   -.0013087
  /xb_educyr |   .0144838   .0078256     1.85   0.064    -.0008541    .0298217
  /xb_actlim |   .1813037   .0382173     4.74   0.000     .1063991    .2562084
  /xb_totchr |   .2814616    .013804    20.39   0.000     .2544064    .3085169
         /b0 |  -12.43548   2.724964    -4.56   0.000    -17.77631   -7.094651
------------------------------------------------------------------------------
Instruments for equation 1: income ssiratio medicaid age age2 educyr actlim totchr _cons

. estimates store GMMmult1S

. 
. * Multiplicative heterogeneity - two step GMM
. gmm ( (docvis / exp({xb:private $XLISTEXOG}+{b0})) - 1),      ///
>   instruments(income ssiratio $XLISTEXOG) twostep vce(robust)

Step 1
Iteration 0:   GMM criterion Q(b) =  41.189479  
Iteration 1:   GMM criterion Q(b) =  .18423738  
Iteration 2:   GMM criterion Q(b) =  .13582044  
Iteration 3:   GMM criterion Q(b) =  .00091458  
Iteration 4:   GMM criterion Q(b) =  .00026374  
Iteration 5:   GMM criterion Q(b) =  .00026347  
Iteration 6:   GMM criterion Q(b) =  .00026347  

Step 2
Iteration 0:   GMM criterion Q(b) =   .0002625  
Iteration 1:   GMM criterion Q(b) =  .00025898  
Iteration 2:   GMM criterion Q(b) =  .00025898  

GMM estimation 

Number of parameters =   8
Number of moments    =   9
Initial weight matrix: Unadjusted                     Number of obs  =    3629
GMM weight matrix:     Robust

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 /xb_private |   .6781529   .2505397     2.71   0.007     .1871042    1.169202
/xb_medicaid |   .2887284   .1032734     2.80   0.005     .0863162    .4911406
     /xb_age |   .3500587   .0719318     4.87   0.000     .2090749    .4910425
    /xb_age2 |  -.0022763   .0004759    -4.78   0.000    -.0032092   -.0013435
  /xb_educyr |   .0143812   .0078322     1.84   0.066    -.0009696     .029732
  /xb_actlim |   .1803826   .0382665     4.71   0.000     .1053816    .2553837
  /xb_totchr |   .2825103   .0137848    20.49   0.000     .2554926    .3095279
         /b0 |  -12.62855   2.721193    -4.64   0.000    -17.96199   -7.295113
------------------------------------------------------------------------------
Instruments for equation 1: income ssiratio medicaid age age2 educyr actlim totchr _cons

. estimates store GMMmult2S

. estat overid

  Test of overidentifying restriction:

  Hansen's J chi2(1) = .939848 (p = 0.3323)

. 
. *** RESULTS: TABLE 10.1
. 
. *** TABLE 10.1 - Poisson and NB models
. estimates table P NB2 PCFboot NB2CFboot, b(%7.4f) se(%7.3f) stats(N ll) ///
>    stfmt(%9.1f) modelwidth(9) equations(1)

--------------------------------------------------------------
    Variable |     P          NB2       PCFboot    NB2CFboot  
-------------+------------------------------------------------
#1           |
     private |    0.1695      0.1853      0.4102      0.5956  
             |     0.036       0.037       0.238       0.258  
    medicaid |    0.0822      0.0848      0.1989      0.2841  
             |     0.048       0.048       0.120       0.128  
         age |    0.2914      0.2953      0.3167      0.3395  
             |     0.060       0.063       0.064       0.069  
        age2 |   -0.0019     -0.0019     -0.0021     -0.0022  
             |     0.000       0.000       0.000       0.000  
      educyr |    0.0281      0.0269      0.0221      0.0170  
             |     0.005       0.005       0.008       0.008  
      actlim |    0.1701      0.1705      0.1794      0.1855  
             |     0.036       0.036       0.038       0.038  
      totchr |    0.2466      0.2752      0.2420      0.2677  
             |     0.011       0.013       0.012       0.014  
        pres |                           -0.2459     -0.4193  
             |                             0.239       0.258  
       _cons |  -10.1383    -10.3758    -11.2003    -12.2262  
             |     2.244       2.358       2.421       2.629  
-------------+------------------------------------------------
lnalpha      |
       _cons |               -0.4834                 -0.4844  
             |                 0.034                   0.034  
-------------+------------------------------------------------
Statistics   |                                                
           N |      3629        3629        3629        3629  
          ll |  -14287.9    -10405.0                          
--------------------------------------------------------------
                                                  legend: b/se

. 
. *** TABLE 10.1 (Continued) - GMM (two-step estimates used in Table 10.1)
. estimates table GMMadd1S GMMmult1S GMMadd2S GMMmult2S, b(%7.4f) se(%7.3f) ///
>    stats(N ll) stfmt(%9.1f) modelwidth(9)

--------------------------------------------------------------
    Variable | GMMadd1S    GMMmult1S   GMMadd2S    GMMmult2S  
-------------+------------------------------------------------
xb_private   |
       _cons |    0.4519      0.6705      0.4456      0.6782  
             |     0.278       0.250       0.278       0.251  
-------------+------------------------------------------------
xb_medicaid  |
       _cons |    0.2484      0.2855      0.2477      0.2887  
             |     0.177       0.104       0.176       0.103  
-------------+------------------------------------------------
xb_age       |
       _cons |    0.3187      0.3450      0.3195      0.3501  
             |     0.065       0.072       0.065       0.072  
-------------+------------------------------------------------
xb_age2      |
       _cons |   -0.0021     -0.0022     -0.0021     -0.0023  
             |     0.000       0.000       0.000       0.000  
-------------+------------------------------------------------
xb_educyr    |
       _cons |    0.0223      0.0145      0.0222      0.0144  
             |     0.007       0.008       0.007       0.008  
-------------+------------------------------------------------
xb_actlim    |
       _cons |    0.1813      0.1813      0.1760      0.1804  
             |     0.039       0.038       0.038       0.038  
-------------+------------------------------------------------
xb_totchr    |
       _cons |    0.2414      0.2815      0.2413      0.2825  
             |     0.013       0.014       0.013       0.014  
-------------+------------------------------------------------
b0           |
       _cons |  -11.3224    -12.4355    -11.3488    -12.6286  
             |     2.495       2.725       2.496       2.721  
-------------+------------------------------------------------
Statistics   |                                                
           N |      3629        3629        3629        3629  
          ll |                                                
--------------------------------------------------------------
                                                  legend: b/se

. 
. *** ASIDE: Not included in text 
. 
. *** Terza two-step estimator
. global XLISTEXOG2 age age2 educyr actlim totchr

. global y2 private

. * Note: need to drop medicaid as probit does not work with Medicaid
. * note: medicaid != 0 predicts failure perfectly
. *      medicaid dropped and 566 obs not used
. probit $y2 $XLISTEXOG2 income ssiratio

Iteration 0:   log likelihood = -2514.8126  
Iteration 1:   log likelihood = -2227.4605  
Iteration 2:   log likelihood = -2226.3962  
Iteration 3:   log likelihood = -2226.3957  
Iteration 4:   log likelihood = -2226.3957  

Probit regression                                 Number of obs   =       3629
                                                  LR chi2(7)      =     576.83
                                                  Prob > chi2     =     0.0000
Log likelihood = -2226.3957                       Pseudo R2       =     0.1147

------------------------------------------------------------------------------
     private |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         age |   -.291607   .0876776    -3.33   0.001     -.463452   -.1197619
        age2 |   .0018801   .0005827     3.23   0.001     .0007379    .0030222
      educyr |     .09171   .0066339    13.82   0.000     .0787079    .1047122
      actlim |  -.2220357   .0518764    -4.28   0.000    -.3237116   -.1203599
      totchr |   .0335732   .0173978     1.93   0.054    -.0005259    .0676723
      income |   .0122801   .0013535     9.07   0.000     .0096273    .0149329
    ssiratio |  -.0495863   .0647675    -0.77   0.444    -.1765283    .0773557
       _cons |   9.950489   3.276446     3.04   0.002     3.528773     16.3722
------------------------------------------------------------------------------

. predict hat, xb

. nl (docvis = exp({xb: private $XLISTEXOG2}+{b0})*( $y2*normal({theta}+hat)/normal(hat) ///
>    + (1-$y2)*(1-normal({theta}+hat))/(1-normal(hat)) ))
(obs = 3629)

Iteration 0:  residual SS =    178046
Iteration 1:  residual SS =  137694.6
Iteration 2:  residual SS =  136194.9
Iteration 3:  residual SS =  136191.4
Iteration 4:  residual SS =  136191.4
Iteration 5:  residual SS =  136191.4
Iteration 6:  residual SS =  136191.4

      Source |       SS       df       MS
-------------+------------------------------         Number of obs =      3629
       Model |  194271.625     8  24283.9531         R-squared     =    0.5879
    Residual |  136191.375  3621   37.611537         Adj R-squared =    0.5870
-------------+------------------------------         Root MSE      =  6.132825
       Total |      330463  3629   91.061725         Res. dev.     =  23454.16

------------------------------------------------------------------------------
      docvis |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 /xb_private |   .1539226   .1753202     0.88   0.380    -.1898136    .4976589
     /xb_age |   .2816204   .0619719     4.54   0.000      .160117    .4031238
    /xb_age2 |  -.0018545     .00041    -4.52   0.000    -.0026584   -.0010506
  /xb_educyr |   .0278465   .0081887     3.40   0.001     .0117916    .0439013
  /xb_actlim |   .1865616   .0361066     5.17   0.000     .1157704    .2573529
  /xb_totchr |   .2197484   .0098621    22.28   0.000     .2004126    .2390843
         /b0 |  -9.616267   2.332167    -4.12   0.000    -14.18876   -5.043775
      /theta |  -.0117633   .1087284    -0.11   0.914    -.2249383    .2014116
------------------------------------------------------------------------------

. 
. *********** 10.5.3 TWO ENDOGENOUS REGRESSORS (private and medicaid)
. 
. global XLISTEXOG2 age age2 educyr actlim totchr

. 
. *** Control function approach
. 
. * First stage regression
. regress private income ssiratio $XLISTEXOG2, vce(robust)

Linear regression                                      Number of obs =    3629
                                                       F(  7,  3621) =  112.05
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.1443
                                                       Root MSE      =  .46295

------------------------------------------------------------------------------
             |               Robust
     private |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      income |   .0037262   .0005379     6.93   0.000     .0026715    .0047808
    ssiratio |  -.0305643    .022337    -1.37   0.171    -.0743586    .0132301
         age |  -.0957731   .0309024    -3.10   0.002     -.156361   -.0351853
        age2 |   .0006167   .0002059     3.00   0.003      .000213    .0010203
      educyr |   .0322792   .0020068    16.09   0.000     .0283447    .0362137
      actlim |  -.0816137   .0183369    -4.45   0.000    -.1175653   -.0456621
      totchr |   .0118382   .0061218     1.93   0.053    -.0001643    .0238406
       _cons |    3.76219   1.153787     3.26   0.001     1.500054    6.024327
------------------------------------------------------------------------------

. predict pres1, residuals

. regress medicaid income ssiratio $XLISTEXOG2, vce(robust)

Linear regression                                      Number of obs =    3629
                                                       F(  7,  3621) =   86.21
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.1855
                                                       Root MSE      =  .32781

------------------------------------------------------------------------------
             |               Robust
    medicaid |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      income |  -.0023543   .0003013    -7.81   0.000     -.002945   -.0017636
    ssiratio |  -.0951358   .0190293    -5.00   0.000     -.132445   -.0578266
         age |   .0183502   .0222047     0.83   0.409    -.0251847    .0618851
        age2 |  -.0001429    .000148    -0.97   0.334     -.000433    .0001472
      educyr |  -.0276618   .0018668   -14.82   0.000    -.0313218   -.0240017
      actlim |   .1242242   .0143453     8.66   0.000     .0960985      .15235
      totchr |   .0194869   .0046774     4.17   0.000     .0103162    .0286576
       _cons |  -.0825787   .8271261    -0.10   0.920    -1.704258    1.539101
------------------------------------------------------------------------------

. predict pres2, residuals

. 
. * Poisson with residuals added 
. * Standard errors here do not control for 2-step estimation
. * Instead use the bootstrap below 
. poisson docvis private medicaid $XLISTEXOG2 pres1 pres2, vce(robust)

Iteration 0:   log pseudolikelihood = -14281.014  
Iteration 1:   log pseudolikelihood =     -14281  
Iteration 2:   log pseudolikelihood =     -14281  

Poisson regression                                Number of obs   =       3629
                                                  Wald chi2(9)    =     806.56
                                                  Prob > chi2     =     0.0000
Log pseudolikelihood =     -14281                 Pseudo R2       =     0.1301

------------------------------------------------------------------------------
             |               Robust
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .5297173   .2547635     2.08   0.038     .0303901    1.029044
    medicaid |    .672714   .4037453     1.67   0.096    -.1186123     1.46404
         age |    .319196   .0647017     4.93   0.000     .1923829    .4460091
        age2 |  -.0020697   .0004277    -4.84   0.000     -.002908   -.0012313
      educyr |   .0320988   .0110848     2.90   0.004     .0103729    .0538246
      actlim |   .1312195   .0515194     2.55   0.011     .0302434    .2321956
      totchr |   .2313097   .0151932    15.22   0.000     .2015317    .2610878
       pres1 |  -.3655598   .2538032    -1.44   0.150    -.8630049    .1318854
       pres2 |  -.5979708    .408592    -1.46   0.143    -1.398797    .2028548
       _cons |  -11.57331   2.473056    -4.68   0.000    -16.42041   -6.726207
------------------------------------------------------------------------------

. 
. * Program to return b for Poisson 2-step estimator of selection model 
. program poisson2step2, eclass
  1.   version 12
  2.   tempname b V
  3.   capture drop pres1 pres2
  4.   regress private income ssiratio $XLISTEXOG2, vce(robust)
  5.   predict pres1, residuals
  6.   regress medicaid income ssiratio $XLISTEXOG2, vce(robust)
  7.   predict pres2, residuals
  8.   poisson docvis private medicaid $XLISTEXOG2 pres1 pres2
  9.   matrix `b' = e(b)
 10.   ereturn post `b' 
 11. end

. * Check preceding program by running once
. poisson2step2

Linear regression                                      Number of obs =    3629
                                                       F(  7,  3621) =  112.05
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.1443
                                                       Root MSE      =  .46295

------------------------------------------------------------------------------
             |               Robust
     private |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      income |   .0037262   .0005379     6.93   0.000     .0026715    .0047808
    ssiratio |  -.0305643    .022337    -1.37   0.171    -.0743586    .0132301
         age |  -.0957731   .0309024    -3.10   0.002     -.156361   -.0351853
        age2 |   .0006167   .0002059     3.00   0.003      .000213    .0010203
      educyr |   .0322792   .0020068    16.09   0.000     .0283447    .0362137
      actlim |  -.0816137   .0183369    -4.45   0.000    -.1175653   -.0456621
      totchr |   .0118382   .0061218     1.93   0.053    -.0001643    .0238406
       _cons |    3.76219   1.153787     3.26   0.001     1.500054    6.024327
------------------------------------------------------------------------------

Linear regression                                      Number of obs =    3629
                                                       F(  7,  3621) =   86.21
                                                       Prob > F      =  0.0000
                                                       R-squared     =  0.1855
                                                       Root MSE      =  .32781

------------------------------------------------------------------------------
             |               Robust
    medicaid |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      income |  -.0023543   .0003013    -7.81   0.000     -.002945   -.0017636
    ssiratio |  -.0951358   .0190293    -5.00   0.000     -.132445   -.0578266
         age |   .0183502   .0222047     0.83   0.409    -.0251847    .0618851
        age2 |  -.0001429    .000148    -0.97   0.334     -.000433    .0001472
      educyr |  -.0276618   .0018668   -14.82   0.000    -.0313218   -.0240017
      actlim |   .1242242   .0143453     8.66   0.000     .0960985      .15235
      totchr |   .0194869   .0046774     4.17   0.000     .0103162    .0286576
       _cons |  -.0825787   .8271261    -0.10   0.920    -1.704258    1.539101
------------------------------------------------------------------------------

Iteration 0:   log likelihood = -14281.014  
Iteration 1:   log likelihood =     -14281  
Iteration 2:   log likelihood =     -14281  

Poisson regression                                Number of obs   =       3629
                                                  LR chi2(9)      =    4270.59
                                                  Prob > chi2     =     0.0000
Log likelihood =     -14281                       Pseudo R2       =     0.1301

------------------------------------------------------------------------------
      docvis |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .5297173   .1083302     4.89   0.000     .3173941    .7420405
    medicaid |    .672714   .1764061     3.81   0.000     .3269644    1.018464
         age |    .319196   .0282197    11.31   0.000     .2638864    .3745055
        age2 |  -.0020697   .0001861   -11.12   0.000    -.0024343    -.001705
      educyr |   .0320988   .0047196     6.80   0.000     .0228486    .0413489
      actlim |   .1312195   .0229977     5.71   0.000     .0861448    .1762942
      totchr |   .2313097   .0063364    36.50   0.000     .2188905    .2437289
       pres1 |  -.3655598   .1092794    -3.35   0.001    -.5797434   -.1513761
       pres2 |  -.5979708   .1778695    -3.36   0.001    -.9465886   -.2493531
       _cons |  -11.57331   1.082133   -10.69   0.000    -13.69425   -9.452367
------------------------------------------------------------------------------

. ereturn display
------------------------------------------------------------------------------
             |      Coef.
-------------+----------------------------------------------------------------
docvis       |
     private |   .5297173
    medicaid |    .672714
         age |    .319196
        age2 |  -.0020697
      educyr |   .0320988
      actlim |   .1312195
      totchr |   .2313097
       pres1 |  -.3655598
       pres2 |  -.5979708
       _cons |  -11.57331
------------------------------------------------------------------------------

. * Bootstrap for Poisson two-step estimator
. bootstrap _b, reps(400) seed(10101) nowarn: poisson2step2
(running poisson2step2 on estimation sample)

Bootstrap replications (400)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
..................................................    50
..................................................   100
..................................................   150
..................................................   200
..................................................   250
..................................................   300
..................................................   350
..................................................   400

Bootstrap results                               Number of obs      =      3629
                                                Replications       =       400

------------------------------------------------------------------------------
             |   Observed   Bootstrap                         Normal-based
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     private |   .5297173     .26941     1.97   0.049     .0016833    1.057751
    medicaid |    .672714   .4237781     1.59   0.112    -.1578759    1.503304
         age |    .319196   .0651432     4.90   0.000     .1915176    .4468743
        age2 |  -.0020697   .0004314    -4.80   0.000    -.0029153   -.0012241
      educyr |   .0320988   .0120188     2.67   0.008     .0085423    .0556552
      actlim |   .1312195   .0530065     2.48   0.013     .0273286    .2351104
      totchr |   .2313097   .0159915    14.46   0.000      .199967    .2626525
       pres1 |  -.3655598   .2687934    -1.36   0.174    -.8923851    .1612656
       pres2 |  -.5979708   .4333765    -1.38   0.168    -1.447373    .2514315
       _cons |  -11.57331   2.479164    -4.67   0.000    -16.43238   -6.714235
------------------------------------------------------------------------------

. estimates store PCF2endog

. 
. *** GMM
. 
. * Additive heterogeneity
. gmm ( docvis - exp({xb:private medicaid $XLISTEXOG2}+{b0})),          ///
>   instruments(income ssiratio $XLISTEXOG2) onestep vce(robust)

Step 1
Iteration 0:   GMM criterion Q(b) =   41.18897  
Iteration 1:   GMM criterion Q(b) =   5.701709  
Iteration 2:   GMM criterion Q(b) =  .40078917  
Iteration 3:   GMM criterion Q(b) =  .00081619  
Iteration 4:   GMM criterion Q(b) =  7.947e-09  
Iteration 5:   GMM criterion Q(b) =  5.526e-19  

GMM estimation 

Number of parameters =   8
Number of moments    =   8
Initial weight matrix: Unadjusted                     Number of obs  =    3629

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 /xb_private |   .6209381    .359066     1.73   0.084    -.0828184    1.324695
/xb_medicaid |    .688957   .4383715     1.57   0.116    -.1702354    1.548149
     /xb_age |   .3298571   .0710658     4.64   0.000     .1905706    .4691436
    /xb_age2 |  -.0021412   .0004687    -4.57   0.000    -.0030599   -.0012225
  /xb_educyr |   .0310625   .0103233     3.01   0.003     .0108292    .0512957
  /xb_actlim |   .1417537   .0494608     2.87   0.004     .0448122    .2386951
  /xb_totchr |    .231281   .0156626    14.77   0.000     .2005828    .2619791
         /b0 |  -12.04651   2.792853    -4.31   0.000     -17.5204   -6.572621
------------------------------------------------------------------------------
Instruments for equation 1: income ssiratio age age2 educyr actlim totchr _cons

. estimates store GMM2add

. 
. * Multiplicative heterogeneity
. gmm ( (docvis / exp({xb:private medicaid $XLISTEXOG2}+{b0})) - 1),    /// 
>   instruments(income ssiratio $XLISTEXOG2) onestep vce(robust)

Step 1
Iteration 0:   GMM criterion Q(b) =   41.18897  
Iteration 1:   GMM criterion Q(b) =  .18326889  
Iteration 2:   GMM criterion Q(b) =  .14775404  
Iteration 3:   GMM criterion Q(b) =  .00083273  
Iteration 4:   GMM criterion Q(b) =  4.475e-07  
Iteration 5:   GMM criterion Q(b) =  1.269e-13  
Iteration 6:   GMM criterion Q(b) =  2.154e-20  

GMM estimation 

Number of parameters =   8
Number of moments    =   8
Initial weight matrix: Unadjusted                     Number of obs  =    3629

------------------------------------------------------------------------------
             |               Robust
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
 /xb_private |   .7412669   .2595375     2.86   0.004     .2325828    1.249951
/xb_medicaid |   .6700525   .4474294     1.50   0.134    -.2068931    1.546998
     /xb_age |   .3473228   .0743883     4.67   0.000     .2015244    .4931212
    /xb_age2 |  -.0022555    .000492    -4.58   0.000    -.0032199   -.0012912
  /xb_educyr |   .0216783   .0115135     1.88   0.060    -.0008878    .0442443
  /xb_actlim |   .1409982   .0570124     2.47   0.013      .029256    .2527405
  /xb_totchr |   .2742124    .016684    16.44   0.000     .2415123    .3069126
         /b0 |  -12.67156   2.811061    -4.51   0.000    -18.18113   -7.161977
------------------------------------------------------------------------------
Instruments for equation 1: income ssiratio age age2 educyr actlim totchr _cons

. estimates store GMM2mult

. 
. *** Structural model
. 
. * Create a combined insurance variable
. generate suppins = private + 2*medicaid

. label define instype 0 none 1 private 2 medicaid

. label values suppins instype

. tabulate suppins

    suppins |      Freq.     Percent        Cum.
------------+-----------------------------------
       none |      1,282       35.33       35.33
    private |      1,781       49.08       84.40
   medicaid |        566       15.60      100.00
------------+-----------------------------------
      Total |      3,629      100.00

. 
. * NB1 model 
. mtreatreg docvis $XLISTEXOG2, mtreat(suppins = $XLISTEXOG2 income ssiratio) ///
>    sim(300) density(negbin1) basecategory(0) vce(robust)

Fitting mixed multinomial logit regression for treatments:

Iteration 0:   log pseudolikelihood = -3109.5608  
Iteration 1:   log pseudolikelihood = -3094.7902  
Iteration 2:   log pseudolikelihood = -3094.7341  
Iteration 3:   log pseudolikelihood = -3094.7341  

Fitting Negative Binomial-1 regression for outcome:

Iteration 0:   log likelihood = -14287.962  
Iteration 1:   log likelihood = -14287.949  
Iteration 2:   log likelihood = -14287.949  

Iteration 0:   log likelihood = -12379.659  
Iteration 1:   log likelihood =   -10970.8  
Iteration 2:   log likelihood = -10787.045  
Iteration 3:   log likelihood = -10786.689  
Iteration 4:   log likelihood = -10786.689  

Iteration 0:   log likelihood = -10786.689  
Iteration 1:   log likelihood = -10371.058  
Iteration 2:   log likelihood = -10336.405  
Iteration 3:   log likelihood = -10336.308  
Iteration 4:   log likelihood = -10336.308  

Fitting full model for treatments and outcome:

Iteration 0:   log pseudolikelihood = -13431.042  
Iteration 1:   log pseudolikelihood = -13430.634  
Iteration 2:   log pseudolikelihood = -13430.407  
Iteration 3:   log pseudolikelihood = -13430.397  
Iteration 4:   log pseudolikelihood = -13430.397  

Multinomial treatment-effects regression          Number of obs   =       3629
                                                  Wald chi2(21)   =    1524.93
Log pseudolikelihood = -13430.397                 Prob > chi2     =     0.0000

---------------------------------------------------------------------------------
                |               Robust
                |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------+----------------------------------------------------------------
_Tprivate       |
            age |  -.5732624   .1810053    -3.17   0.002    -.9280263   -.2184985
           age2 |   .0036321   .0012039     3.02   0.003     .0012725    .0059918
         educyr |   .1340687   .0140481     9.54   0.000     .1065349    .1616025
         actlim |  -.1652801   .1078625    -1.53   0.125    -.3766867    .0461265
         totchr |   .1306642   .0361985     3.61   0.000     .0597164     .201612
         income |   .0182385   .0042659     4.28   0.000     .0098775    .0265996
       ssiratio |  -.3589233    .142948    -2.51   0.012    -.6390963   -.0787504
          _cons |   20.80832   6.766931     3.08   0.002     7.545383    34.07126
----------------+----------------------------------------------------------------
_Tmedicaid      |
            age |  -.1939146   .2677233    -0.72   0.469    -.7186425    .3308134
           age2 |   .0010012    .001773     0.56   0.572    -.0024737    .0044762
         educyr |  -.1507701   .0178591    -8.44   0.000    -.1857734   -.1157668
         actlim |    1.01606   .1432584     7.09   0.000     .7352785    1.296841
         totchr |   .2775219   .0514542     5.39   0.000     .1766735    .3783702
         income |  -.1062385   .0105428   -10.08   0.000    -.1269021   -.0855749
       ssiratio |  -.8338379   .1766901    -4.72   0.000    -1.180144   -.4875317
          _cons |   9.940068   10.04901     0.99   0.323    -9.755633    29.63577
----------------+----------------------------------------------------------------
docvis          |
      _Tprivate |   .2899975   .0892202     3.25   0.001      .115129     .464866
     _Tmedicaid |   .1267913   .0781725     1.62   0.105    -.0264241    .2800067
            age |   .2868279   .0535054     5.36   0.000     .1819593    .3916965
           age2 |  -.0018699   .0003552    -5.26   0.000    -.0025661   -.0011737
         educyr |   .0218365   .0048162     4.53   0.000     .0123968    .0312761
         actlim |   .1323455   .0342258     3.87   0.000      .065264    .1994269
         totchr |   .2520047   .0103787    24.28   0.000     .2316627    .2723466
          _cons |  -10.00752   2.016748    -4.96   0.000    -13.96028   -6.054771
----------------+----------------------------------------------------------------
       /lndelta |   1.365015   .0695968    19.61   0.000     1.228608    1.501423
/lambda_private |  -.1336182   .1002608    -1.33   0.183    -.3301258    .0628893
/lambda_medic~d |  -.0260303   .0819637    -0.32   0.751    -.1866761    .1346155
----------------+----------------------------------------------------------------
          delta |   3.915784    .272526                      3.416471    4.488069
---------------------------------------------------------------------------------
Notes:
1. none is the control group (base category)
2. 300 Halton sequence-based quasirandom draws per observation
3. Outcome density is negbin1
4. Standard deviation of factor density is 1

. estimates store MMNLNB1

. 
. * NB2 model
. mtreatreg docvis $XLISTEXOG2, mtreat(suppins = $XLISTEXOG2 income ssiratio) ///
>    sim(300) density(negbin2) basecategory(0) vce(robust)

Fitting mixed multinomial logit regression for treatments:

Iteration 0:   log pseudolikelihood = -3109.5608  
Iteration 1:   log pseudolikelihood = -3094.7902  
Iteration 2:   log pseudolikelihood = -3094.7341  
Iteration 3:   log pseudolikelihood = -3094.7341  

Fitting Negative Binomial-2 regression for outcome:

Iteration 0:   log likelihood = -14287.962  
Iteration 1:   log likelihood = -14287.949  
Iteration 2:   log likelihood = -14287.949  

Iteration 0:   log likelihood = -10812.582  
Iteration 1:   log likelihood = -10786.692  
Iteration 2:   log likelihood = -10786.689  
Iteration 3:   log likelihood = -10786.689  

Iteration 0:   log likelihood = -10461.355  
Iteration 1:   log likelihood = -10406.915  
Iteration 2:   log likelihood = -10404.957  
Iteration 3:   log likelihood = -10404.956  
Iteration 4:   log likelihood = -10404.956  

Fitting full model for treatments and outcome:

Iteration 0:   log pseudolikelihood =  -13499.69  (not concave)
Iteration 1:   log pseudolikelihood =  -13499.31  (not concave)
Iteration 2:   log pseudolikelihood = -13498.048  (not concave)
Iteration 3:   log pseudolikelihood = -13491.711  
Iteration 4:   log pseudolikelihood = -13491.495  
Iteration 5:   log pseudolikelihood = -13484.353  (not concave)
Iteration 6:   log pseudolikelihood = -13484.175  
Iteration 7:   log pseudolikelihood = -13483.657  
Iteration 8:   log pseudolikelihood = -13483.191  
Iteration 9:   log pseudolikelihood =  -13483.12  
Iteration 10:  log pseudolikelihood = -13483.102  
Iteration 11:  log pseudolikelihood = -13483.101  
Iteration 12:  log pseudolikelihood = -13483.101  

Multinomial treatment-effects regression          Number of obs   =       3629
                                                  Wald chi2(21)   =    1496.85
Log pseudolikelihood = -13483.101                 Prob > chi2     =     0.0000

---------------------------------------------------------------------------------
                |               Robust
                |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
----------------+----------------------------------------------------------------
_Tprivate       |
            age |  -.5650713   .1806697    -3.13   0.002    -.9191774   -.2109652
           age2 |   .0035789   .0012015     2.98   0.003      .001224    .0059338
         educyr |   .1356324    .014152     9.58   0.000     .1078949    .1633698
         actlim |  -.1622597   .1077109    -1.51   0.132    -.3733691    .0488497
         totchr |   .1311182    .036026     3.64   0.000     .0605085    .2017279
         income |   .0176068   .0042301     4.16   0.000     .0093161    .0258976
       ssiratio |  -.3850331   .1402973    -2.74   0.006    -.6600108   -.1100554
          _cons |   20.50129    6.75609     3.03   0.002       7.2596    33.74299
----------------+----------------------------------------------------------------
_Tmedicaid      |
            age |  -.1851331   .2688751    -0.69   0.491    -.7121187    .3418524
           age2 |   .0009463   .0017803     0.53   0.595    -.0025431    .0044357
         educyr |  -.1500232   .0179347    -8.36   0.000    -.1851745    -.114872
         actlim |   1.014646   .1426368     7.11   0.000     .7350831    1.294209
         totchr |   .2783077   .0520933     5.34   0.000     .1762066    .3804088
         income |  -.1065472   .0104946   -10.15   0.000    -.1271162   -.0859783
       ssiratio |  -.8306707   .1810924    -4.59   0.000    -1.185605    -.475736
          _cons |   9.585179   10.09813     0.95   0.343    -10.20679    29.37714
----------------+----------------------------------------------------------------
docvis          |
      _Tprivate |   .5566001   .0651993     8.54   0.000     .4288119    .6843884
     _Tmedicaid |   .1145188    .250525     0.46   0.648    -.3765013    .6055389
            age |    .352924   .0626767     5.63   0.000     .2300799    .4757681
           age2 |  -.0022969   .0004167    -5.51   0.000    -.0031136   -.0014803
         educyr |   .0144475   .0090572     1.60   0.111    -.0033043    .0321994
         actlim |    .196418   .0465883     4.22   0.000     .1051066    .2877294
         totchr |   .2904762   .0139739    20.79   0.000     .2630878    .3178645
          _cons |  -12.76867   2.348299    -5.44   0.000    -17.37125   -8.166089
----------------+----------------------------------------------------------------
       /lnalpha |  -.8375794   .1075666    -7.79   0.000    -1.048406   -.6267528
/lambda_private |  -.4488533   .0592112    -7.58   0.000    -.5649051   -.3328014
/lambda_medic~d |   .0233875   .3167202     0.07   0.941    -.5973726    .6441476
----------------+----------------------------------------------------------------
          alpha |   .4327568   .0465502                       .350496     .534324
---------------------------------------------------------------------------------
Notes:
1. none is the control group (base category)
2. 300 Halton sequence-based quasirandom draws per observation
3. Outcome density is negbin2
4. Standard deviation of factor density is 1

. estimates store MMNLNB2

. 
. *** RESULTS: TABLE 10.2 TWO ENDOGENOUS REGRESSORS
. 
. *** TABLE 10.2 - Poisson CF GMM and MMNL-NB columns
. estimates table PCF2endog, b(%7.4f) se(%7.3f) stats(N ll) stfmt(%9.1f) ///
>   modelwidth(9) equations(1)

--------------------------
    Variable | PCF2endog  
-------------+------------
     private |    0.5297  
             |     0.269  
    medicaid |    0.6727  
             |     0.424  
         age |    0.3192  
             |     0.065  
        age2 |   -0.0021  
             |     0.000  
      educyr |    0.0321  
             |     0.012  
      actlim |    0.1312  
             |     0.053  
      totchr |    0.2313  
             |     0.016  
       pres1 |   -0.3656  
             |     0.269  
       pres2 |   -0.5980  
             |     0.433  
       _cons |  -11.5733  
             |     2.479  
-------------+------------
           N |      3629  
          ll |            
--------------------------
              legend: b/se

. 
. *** TABLE 10.2 (Continued) - GMM columns
. estimates table GMM2add GMM2mult, b(%7.4f) se(%7.3f) stats(N ll) stfmt(%9.1f) modelwidth(9)

--------------------------------------
    Variable |  GMM2add    GMM2mult   
-------------+------------------------
xb_private   |
       _cons |    0.6209      0.7413  
             |     0.359       0.260  
-------------+------------------------
xb_medicaid  |
       _cons |    0.6890      0.6701  
             |     0.438       0.447  
-------------+------------------------
xb_age       |
       _cons |    0.3299      0.3473  
             |     0.071       0.074  
-------------+------------------------
xb_age2      |
       _cons |   -0.0021     -0.0023  
             |     0.000       0.000  
-------------+------------------------
xb_educyr    |
       _cons |    0.0311      0.0217  
             |     0.010       0.012  
-------------+------------------------
xb_actlim    |
       _cons |    0.1418      0.1410  
             |     0.049       0.057  
-------------+------------------------
xb_totchr    |
       _cons |    0.2313      0.2742  
             |     0.016       0.017  
-------------+------------------------
b0           |
       _cons |  -12.0465    -12.6716  
             |     2.793       2.811  
-------------+------------------------
Statistics   |                        
           N |      3629        3629  
          ll |                        
--------------------------------------
                          legend: b/se

. 
. *** TABLE 10.2 (Continued) - MMNL-NB columns
. estimates table MMNLNB1 MMNLNB2, b(%7.4f) se(%7.3f) stats(N ll) stfmt(%9.1f) modelwidth(9)

--------------------------------------
    Variable |  MMNLNB1     MMNLNB2   
-------------+------------------------
_Tprivate    |
         age |   -0.5733     -0.5651  
             |     0.181       0.181  
        age2 |    0.0036      0.0036  
             |     0.001       0.001  
      educyr |    0.1341      0.1356  
             |     0.014       0.014  
      actlim |   -0.1653     -0.1623  
             |     0.108       0.108  
      totchr |    0.1307      0.1311  
             |     0.036       0.036  
      income |    0.0182      0.0176  
             |     0.004       0.004  
    ssiratio |   -0.3589     -0.3850  
             |     0.143       0.140  
       _cons |   20.8083     20.5013  
             |     6.767       6.756  
-------------+------------------------
_Tmedicaid   |
         age |   -0.1939     -0.1851  
             |     0.268       0.269  
        age2 |    0.0010      0.0009  
             |     0.002       0.002  
      educyr |   -0.1508     -0.1500  
             |     0.018       0.018  
      actlim |    1.0161      1.0146  
             |     0.143       0.143  
      totchr |    0.2775      0.2783  
             |     0.051       0.052  
      income |   -0.1062     -0.1065  
             |     0.011       0.010  
    ssiratio |   -0.8338     -0.8307  
             |     0.177       0.181  
       _cons |    9.9401      9.5852  
             |    10.049      10.098  
-------------+------------------------
docvis       |
   _Tprivate |    0.2900      0.5566  
             |     0.089       0.065  
  _Tmedicaid |    0.1268      0.1145  
             |     0.078       0.251  
         age |    0.2868      0.3529  
             |     0.054       0.063  
        age2 |   -0.0019     -0.0023  
             |     0.000       0.000  
      educyr |    0.0218      0.0144  
             |     0.005       0.009  
      actlim |    0.1323      0.1964  
             |     0.034       0.047  
      totchr |    0.2520      0.2905  
             |     0.010       0.014  
       _cons |  -10.0075    -12.7687  
             |     2.017       2.348  
-------------+------------------------
lndelta      |
       _cons |    1.3650              
             |     0.070              
-------------+------------------------
lambda_pri~e |
       _cons |   -0.1336     -0.4489  
             |     0.100       0.059  
-------------+------------------------
lambda_med~d |
       _cons |   -0.0260      0.0234  
             |     0.082       0.317  
-------------+------------------------
lnalpha      |
       _cons |               -0.8376  
             |                 0.108  
-------------+------------------------
Statistics   |                        
           N |      3629        3629  
          ll |  -13430.4    -13483.1  
--------------------------------------
                          legend: b/se

. 
. ********** CLOSE OUTPUT
. 
. * log close
. * clear
. * exit
. 
end of do-file

. exit, clear
