'uses of gradients
'checking NLS estimates by an artifical regression
'see Davidson-MacKinnon 1993, chapter 6
'version 4
'last revised 10/27/2000 h.

'change path to program path
%path = @runpath
cd "{%path}"

'create workfile
workfile gallant1 u 1 30

'read data from plain text file
read(b2) amstat.dat t y x1 x2 x3

'starting values
c(1) = -0.04866
c(2) =  1.03884
c(3) = -0.73792
c(4) = -0.51362

'replicate Gallant (1987) fig 5a (p.35)
equation eq1.ls(c=1e-9,m=1000,showopts,deriv=aa) y = c(1)*x1 + c(2)*x2 + c(4)*exp(c(3)*x3)
show eq1.output

'get residuals
eq1.makeresid res

'get derivative series
eq1.makederivs(n=grd1)

'run Gauss-Newton regression
'all coefs, t-stats, and R2 should be within convergence 
'tolerance if NLS converged
equation eq2.ls res grd1
show eq2.output

