* * Example 17.5 from pages 498-499 * open data tablef9-2[1].txt data(format=prn,org=columns) 1 25 valueadd capital labor nfirm * set y = valueadd/nfirm set k = capital/nfirm set l = labor/nfirm set logk = log(k) set logl = log(l) * * Nonlinear least squares. Because the "dependent variable" is actually a * combination of two terms, we just define the formula as the residual. If NLLS * sees a FRML without an explicitly defined dependent variable, it will just * minimize the sum of squares of the frml itself. * nonlin b1 b2 b3 theta compute b1=b2=b3=theta=0 * frml resid = log(y)+theta*y-b1-b2*logk-b3*logl nlls(frml=resid) * * Maximum likelihood estimates. We need to add the variance to the list of * parameters (if we're doing a joint estimate of all the parameters). The log * likelihood formula itself uses the resid FRML defined above as a building block * so we don't have to repeat it. * nonlin b1 b2 b3 theta sigsq frml loglike = log(1+theta*y)-log(y)+%logdensity(sigsq,resid) * * We need to initialize sigsq to a positive number or loglike won't be computable * at the initial guesses. * compute sigsq=%seesq maximize(method=bhhh,vcv) loglike * * This is a linear regression given theta to produce the second set of standard * errors. * set yadjust = log(y)+theta*y linreg yadjust # constant logk logl * * This is an alternative way to do maximum likelihood. This uses NLLS with the * JACOBIAN option to take care of those terms in the likelihood. * nonlin b1 b2 b3 theta nlls(jacobian=(1+theta*y)/y,frml=resid) * * This is the same maximum likelihood done by concentrating out the beta's and * variance, since given theta, the likelihood is just least squares. * declare real concentrate nonlin theta find maximum concentrate set yadjust = log(y)+theta*y linreg(noprint) yadjust # constant logk logl sstats / log(1+theta*y)-log(y)>>yterms compute concentrate=yterms+%logl end find