* * Example 18.5 from pp 530-531 * open data tablefd-1[1].txt data(format=prn,org=columns) 1 20 id y e * set ysq = y**2 set logy = log(y) set recy = 1/y * nonlin p lambda * * The following conditions, when summed over the data, should yield zero. Any * pair will give an exact solution, though each pair will give a DIFFERENT * solution, due to sample variation. * frml yfrml = y-p/lambda frml ysqfrml = y**2-p*(p+1)/lambda**2 frml recyfrml = 1/y-lambda/(p-1) frml logyfrml = log(y)-%digamma(p)+log(lambda) * compute p=2,lambda=1.0 * * This does the six pairs of conditions * instruments constant nlsystem(inst) / yfrml ysqfrml nlsystem(inst) / yfrml recyfrml nlsystem(inst) / yfrml logyfrml nlsystem(inst) / ysqfrml recyfrml nlsystem(inst) / ysqfrml logyfrml nlsystem(inst) / recyfrml logyfrml * * This does the same set of six estimators, but generates the table shown on page * 531. * compute p=2,lambda=1.0 report(action=define) report(atrow=1,atcol=2,span) "m1" "" "m2" "" "m-1" report(atcol=1,atrow=2,fillby=cols) "m2" "m-1" "m*" * instruments constant nlsystem(inst,noprint) / yfrml ysqfrml report(atrow=2,atcol=2) %beta nlsystem(inst,noprint) / yfrml recyfrml report(atrow=3,atcol=2) %beta nlsystem(inst,noprint) / yfrml logyfrml report(atrow=4,atcol=2) %beta nlsystem(inst,noprint) / ysqfrml recyfrml report(atrow=3,atcol=4) %beta nlsystem(inst,noprint) / ysqfrml logyfrml report(atrow=4,atcol=4) %beta nlsystem(inst,noprint) / recyfrml logyfrml report(atrow=4,atcol=6) %beta report(action=format,width=7) report(action=show,window="Method of Moments Estimators") * * This is overidentified, and is an example of GMM * nlsystem(instruments) / yfrml ysqfrml recyfrml logyfrml * * Maximum likelihood * frml loglike = p*log(lambda)-%lngamma(p)-lambda*y+(p-1)*log(y) maximize(method=bhhh) loglike