* * Illustrative example of GMM estimation from pages 410-412 * * Generate data from a t distribution * all 500 compute x=10.0 set y = %ran(1.0)/sqrt(%ranchisqr(x)/x) * * Maximum likelihood estimation * nonlin nu compute nu=30.0 frml logt = log(%tdensity(y,nu)) maximize logt * * 2nd and 4th moment conditions * frml mom2 = y**2-nu/(nu-2) frml mom4 = y**4-3*nu**2/((nu-2)*(nu-4)) * * Method of moments with just the variance condition. Because this * is just identified, the weighting doesn't matter. For this simple * example, the instrument set is just the constant. * instruments constant nlsystem(instruments) / mom2 * * Computing the same estimate indirectly. This should get exactly the * same result as above. * compute mu2=%dot(y,y)/500 disp 'Method of moments estimator' 2*mu2/(mu2-1) * * Now using both the 2nd and 4th moment conditions. By default, this * will give the optimal weighting matrix. Without other options, this * will be computed using 14.1.18, that is, the formula for no serial * correlation. The S matrix is adjusted with each iteration as described * on the bottom of page 413. * nlsystem(instruments) / mom2 mom4 * * Testing overidentifying restrictions. The %UZWZU variable produced by * NLSYSTEM is the left side of 14.1.27, and so has an asymptotic x**2 * distribution with degrees of freedom equal to the number of overidentifying * restrictions, here 2-1=1. Note that this is also computed as the J-statistic * in the regression output. * cdf(title='Test of Overidentifying Restrictions') chisqr %uzwzu 1 * * Using a suboptimal weighting matrix (2x2 identity). Note that the overall * weighting matrix for the conditions is given by the SWMATRIX option. There's * a separate WMATRIX option for adjusting the behavior of the instruments only. * * If you use a suboptimal weighting matrix, you need to use the ROBUSTERRORS * option to get a properly calculated covariance matrix. If you don't, the * standard errors will likely be nonsense. * dec symm swmatrix(2,2) compute swmatrix=%identity(2) nlsystem(swmatrix=swmatrix,instruments,robusterrors) / mom2 mom4 * * Same thing with data that isn't from a t. If you only use the * 2nd moment condition, you can't test (from the estimation) the * failure of the assumptions, since the model is just identified. * Using both conditions gives a testable implication. * compute nu=30.0 set y = %rangamma(10.0)*%if(%uniform(-1.0,1.0)<0,-1,1) instruments constant nlsystem(instruments) / mom2 nlsystem(instruments) / mom2 mom4 cdf(title='Test of Overidentifying Restrictions') chisqr %uzwzu 1