|
/*********************************************************************
2) Get goodness-of-fit statistics for Table 12.2, shown in Table 12.3.
**********************************************************************/
*Define s=stratification, t=technology, and p=political integration.
infile s t p count using tab12_2.raw , clear
list /*Confirm that I have read in the data correctly*/
*Estimate the baseline model (Table 12.3, Model 1).
xi : glm count i.t i.p i.s , family(poisson)
/*Create a scalar: baseline deviance (bd). I will use this to get the
ratio of the deviance for each subsequent model to the deviance for
the baseline model.*/
scalar bd = e(deviance)
/*Get goodness-of-fit statistics for this model. Since I am going to
invoke the same commands many times, I have written an -ado- file -gof.ado-,
to get all the statistics I need for Table 12.3 that are not shown in the
Stata output.*/
gof
*Now I get the corresponding statistics for the remaining models (Table 12.3).
/*Note that Stata now has a built in BIC function. However, for our purposes
the BIC estimates from the -glm- command are misleading because they treat
the number of cells in the table rather than the total number of cases used
in the analysis as the sample. However, it is possible to override the
default count. For the first two models in the next set of models estimated,
I have used the -glm- postestimation command, -estat- to estimate BIC,
substituting the correct N, the number of cases in the table rather than the
number of cells. -estat- yields estimates of BIC that are different from
the estimates I derive from -gof- (which follow the formula provided by
Raftery 1995). However, as you can see, the difference between BICs for the
two models are identical regardless of which version of BIC is estimated.*/
*First get the total number of cases in the table.;
egen freq = total(count)
tab freq
*Then estimate BIC as a -glm- postestimation command for the first two models.
xi : glm count i.t i.p*i.s , family(poisson)
estat ic , n(92)
gof
xi : glm count i.p i.t*i.s , family(poisson)
estat ic , n(92)
gof
xi : glm count i.s i.t*i.p , family(poisson)
gof
xi : glm count i.t*i.p i.t*i.s , family(poisson)
gof
xi : glm count i.t*i.p i.p*i.s , family(poisson)
gof
xi : glm count i.t*i.s i.p*i.s , family(poisson)
gof
xi : glm count i.t*i.p i.t*i.s i.p*i.s , family(poisson)
gof
|