* * Example of nonlinear estimation, Example 9.7 * pages 171-172, 177 * open data tablef5-1[1].txt calendar(q) 1950 data(format=prn,org=columns) 1950:1 2000:4 year qtr realgdp realcons realinvs $ realgovt realdpi cpi_u m1 tbilrate unemp pop infl realint * * Doing the non-linear estimation by iterating on the linearized regression. * * Start with OLS with g fixed at 1. Save a copy of the %RSS for use in later * hypothesis tests * linreg realcons # constant realdpi compute rssr=%rss * compute a=%beta(1),b=%beta(2),g=1.0 * do it=1,8 set c0 = realcons+g*b*realdpi**g*log(realdpi) set bdelta = realdpi**g set gdelta = b*realdpi**g*log(realdpi) * * You can take the noprint off the linreg if you want to see * more details about the iterations * linreg(noprint) c0 # constant bdelta gdelta compute b=%beta(2),g=%beta(3) disp "Iteration" it "RSS" %rss "Gamma" g end do it * * Redo the final regression to get the output * linreg(vcv) c0 # constant bdelta gdelta * summarize(title="MPC") %beta(2)*%beta(3)*realdpi(2000:4)**(%beta(3)-1) * * Hypothesis tests-example 9.7 * * Wald test (easiest to do since we just did the unrestricted model). * test(title="Wald Test") # 3 # 1.0 * * F-test. We have rssr from the OLS regression above. * compute fstat=((rssr-%rss)/1)/%seesq cdf(title="F-Test") ftest fstat 1 %ndf * * To do the Wald test, redo the OLS regression and get the residuals * linreg realcons / resids # constant realdpi set gdelta = %beta(2)*realdpi*log(realdpi) linreg resids # constant realdpi gdelta cdf(title="LM Test") chisqr %trsq 1 * * Nonlinear regression done directly with NLLS. The NONLIN instruction names the * three parameters being estimated. We'll use the same initial guess values as * above. * nonlin a b g linreg realcons # constant realdpi compute a=%beta(1),b=%beta(2),g=1 * * The FRML instruction provides the formula for the RHS of the equation. * frml cfrml realcons = a+b*realdpi**g * * And NLLS does the estimation. We use the TRACE to see the progress of the * estimation. You'll notice that it takes longer to get to the optimum. The * "full-step" method employed in the linearized regressions sometimes (as here) * works well, but can sometimes fail to converge in a reasonable way. Note, for * instance, that the sum of squared residuals for the actual model (not the * linearized one) on page 171 goes up tremendously when you take a full step. The * method works well in this case because the first iteration comes up with a good * estimate of gamma, even though it gets poor values for alpha and beta. Given * gamma, the model is linear in alpha and beta, which is why the convergence is * quite rapid once gamma is nailed down. * * However, there are many non-linear functions which aren't so well behaved and * where such a huge "uphill" step would be very bad. The RATS NLLS instruction * is designed to move more cautiously and won't take a full step if it makes the * sum of squared residuals worse. The "Distance Scale" in the trace output shows * the number by which NLLS multiplied the full step to get the actual step it * takes. You'll note that this gets bigger as it gets closer to the converged * values. * nlls(frml=cfrml,trace) realcons