** Chapter 16.6 ** for W.H. Greene, Econometric Analysis 6th ed. ***************** * (c) Noel Roy 2003, 2008 * * 16.6 THREE ASYMPTOTICALLY EQUIVALENT TEST PROCEDURES * * This tutorial will review the following tasks in SHAZAM: * • Estimation by maximum likelihood * • Hypothesis tests by maximum likelihood * • Calculating the derivatives of an equation (DERIV command) * *=============================================================================== * * 16.6.4 An Application of the Likelihood Based Test Procedures (p. 504) * * Use the NL command to estimate a model based on the exponential * distribution (16-29) as in Example 16.4. This is the restricted model * in Table 16.1. READ (TableFC-1.prn) I Y X / SKIPLINES=1 NL 1 /NCOEF=1 LOGDEN GENRVAR EQ -LOG(BETA+X)-Y/(BETA+X) END * The option GENRVAR takes a vector of coefficients and generates a set * of scalar variables (here BETA) for later use. RENAME BETA BETAR * Keep the value of the LLF for use in a likelihood ratio test. GEN1 LLFR=$LLF * * Now use the NL command to estimate a model based on the general gamma * distribution (16-30). This is the unrestricted model in Table 16.1. * NL 1 /NCOEF=2 LOGDEN GENRVAR PCOV COV=V ZMATRIX=G EQ LOG(1/(BETA+X))*RHO-LGAM(RHO)+(RHO-1)*LOG(Y)-Y/(BETA+X) * Note the use of the LGAM function to obtain the log of the Gamma function. END * The option PCOV prints an estimate of the covariance matrix of * coefficients after convergence. Generally, this is based on an estimate * of the actual second-derivative of the log-likelihood function at the * maximum-likelihood estimates, although it may be based on a numerical * estimate rather than an analytic one (which is the case here, * since an analytic estimate would require calculation of * the second derivative of the log gamma function, which is beyond SHAZAM's * capabilities). However, this estimate is is very close to the estimate of V * reported in the textbook. * The option COV= saves the covariance matrix in the variable specified. * The option ZMATRIX= specifies a matrix to create and use to store the * derivatives of the likelihood function. This matrix can be used, for * example, to calculate the BHHH (OPG) estimator of the covariance estimate. * * Calculate the Confidence Interval Test. The option NORMAL is used to obtain * confidence intervals based on the normal distribution tather than the t. * The CONFID command must immediately follow an estimation command. CONFID RHO /NORMAL * Keep the value of the LLF for use in a likelihood ratio test. GEN1 LLFU=$LLF * * The Hessian can be evaluated at the maximum likelihood estimates by * the negative of the inverse of the estimated covariance matrix (see equation * 16-17). MATRIX HES=-INV(V) PRINT HES * * We cannot directly calculate VE in SHAZAM, since the associated Hessian * involves (see (16-31)) phi'(rho), which SHAZAM cannot calculate directly. * However, if we can accept the numerical calculation of this second * order derivative in the matrix HES, which here equals its expected value, * we can calculate the other elements of the Hessian associated with Ve directly. * * Calculate the expected values of the second-order derivatives in (16-31). GENR BETAI = 1/(BETA+X) GENR EY = RHO*(BETA+X) GENR DLDB2 = RHO*BETAI**2 - 2*EY*BETAI**3 GENR DLDBR = -BETAI ?STAT DLDB2 DLDBR /SUMS=SUMDL DIM HESe 2 2 MATRIX HESe(1,1)=SUMDL(1) MATRIX HESe(2,1)=SUMDL(2) MATRIX HESe(1,2)=HESE(2,1) MATRIX HESe(2,2)=HES(2,2) MATRIX Ve=-INV(HESe) PRINT Ve * This matches quite closely the estimate in the textbook. * * The OPG estimate of the covariance matrix VB can be obtained by taking * the matrix of derivatives of the likelihood function (saved with the ZMATRIX= * option), premultiplying by its transpose, and inverting the product (equation * 16-18). MATRIX Vb=INV(G'G) PRINT Vb * * Calculate the likelihood test statistic using the previously saved values * of the LLF in the restricted and unrestricted models. GEN1 LR=-2*(LLFR-LLFU) DISTRIB LR /TYPE=CHI DF=1 * * Calculate the Wald test statistic. The variance of RHO is the (2,2)th * element of the saved matrix V. MATRIX VARRHO=V(2,2) GEN1 W=(RHO-1)**2/VARRHO DISTRIB W /TYPE=CHI DF=1 * * Do a Lagrange Multiplier test of the unrestricted model, based on the * restricted estimates. GEN1 RHOR=1 * The value of the gradient of Rho requires evaluation of the Phi function, * which is the derivative of the log of the Gamma function LGAM. * The DERIV command will differentiate an equation with respect to * any variable and return the derivatives as another variable. * In general, the format is: * DERIV variable resultvar = equation * where variable is the variable in the equation for which the * derivative should be taken with respect to and the result of the * derivative will be placed in the variable resultvar. DERIV RHOR PHIR=LGAM(RHOR) * Now calculate the derivatives of the likelihood function (16-31) * at the restricted estimates, and place these values in the gradient * matrix GR. GENR BETARi=1/(BETAR+X) GENR GBETAR=-RHOR*BETARi+Y*BETARi**2 GENR GRHOR=LOG(BETARi)-PHIR+LOG(Y) COPY GBETAR GRHOR GR * Calculate the LM statistic as on p. 505. GENR ONE=1 MATRIX IGR=ONE'GR PRINT IGR MATRIX GrGr=GR'GR PRINT GrGr MATRIX LM=IGR*INV(GRGR)*IGR' DISTRIB LM /TYPE=CHI DF=1 STOP * *=============================================================================== * * Updated October 30, 2008