nlmdl Part 1 of 6

Ron Gallant arg at ccvr1.ncsu.edu
Sun Dec 23 09:56:43 AEST 1990


#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 6)."
# Contents:  Makefile README ch1eg1 ch1eg1/amstat.dat ch1eg1/ending.bak
#   ch1eg1/model.cc ch1eg1/model.h ch1eg1/starting.dat ch5eg1
#   ch5eg1/electb.dat ch5eg1/model.h ch5eg1/starting.dat ch6eg1
#   ch6eg1/README ch6eg1/starting.dat ch6eg2 ch6eg2/ending.bak
#   ch6eg2/model.cc ch6eg2/model.h ch6eg2/start3l.dat
#   ch6eg2/starting.dat dcond.cc dsweep.cc nlmdl.cc nlmdl.h starbox.cc
#   status.h tools.h usual.h
# Wrapped by arg at sparc on Sat Dec 22 15:25:07 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(1483 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
XCC       = g++
XCFLAGS   = -O
XRMDIR    = ..
XNLDIR    = ..
XMDLDIR   = .
XLDFLAGS  = -lm
X
Xnlmdl	: nlmdl.o status.o model.o \
X		realmat.o dcond.o dsweep.o starbox.o
X	$(CC) -o nlmdl nlmdl.o status.o model.o \
X		realmat.o dcond.o dsweep.o starbox.o $(LDFLAGS) 
X
Xnlmdl.o	: $(NLDIR)/nlmdl.cc $(NLDIR)/nlopr.cc \
X		$(MDLDIR)/model.h $(NLDIR)/nlmdl.h $(NLDIR)/status.h  \
X		$(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h
X	$(CC) $(CFLAGS) -c -I$(MDLDIR) -I$(NLDIR) -I$(RMDIR) $(NLDIR)/nlmdl.cc 
X
Xmodel.o	: $(MDLDIR)/model.cc \
X		$(MDLDIR)/model.h $(NLDIR)/nlmdl.h $(NLDIR)/status.h  \
X		$(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h
X	$(CC) $(CFLAGS) -c -I$(MDLDIR) -I$(NLDIR) -I$(RMDIR) $(MDLDIR)/model.cc 
X
Xstatus.o	: $(NLDIR)/status.cc \
X		$(NLDIR)/status.h \
X		$(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h 
X	$(CC) $(CFLAGS) -c -I$(MDLDIR) -I$(NLDIR) -I$(RMDIR) $(NLDIR)/status.cc 
X
Xrealmat.o	: $(RMDIR)/realmat.cc \
X		$(RMDIR)/usual.h $(RMDIR)/realmat.h $(RMDIR)/tools.h
X	$(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/realmat.cc
X
Xstarbox.o	: $(RMDIR)/starbox.cc \
X		$(RMDIR)/usual.h $(RMDIR)/tools.h 
X	$(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/starbox.cc
X
Xdcond.o	: $(RMDIR)/dcond.cc \
X		$(RMDIR)/usual.h $(RMDIR)/tools.h 
X	$(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/dcond.cc
X
Xdsweep.o	: $(RMDIR)/dsweep.cc \
X		$(RMDIR)/usual.h $(RMDIR)/tools.h
X	$(CC) $(CFLAGS) -c -I$(RMDIR) $(RMDIR)/dsweep.cc
X
Xclean	:
X	rm -f *.o core
X
Xveryclean	:
X	rm -f *.o core nlmdl detail.dat ending.dat tmp.dat
END_OF_FILE
if test 1483 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(2877 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
Xnlmdl is a C++ implementation of the statistical methods in A. Ronald Gallant, 
X"Nonlinear Statistical Models," New York: John Wiley and Sons, 1987, 
XISBN 0-471-80260-3, using a matrix class realmat that is distributed with it.  
XThe matrix class may be of some independent interest.  
X
XThe program computes least squares estimates for a univariate nonlinear 
Xregression model and generalized least squares estimates for a multivariate 
Xnonlinear regression model.  Use the SUR option for both.  Other options can be 
Xset to correct variance estimates for heteroskedasticity and/or serial 
Xcorrelation.  For simultaneous nonlinear systems, possibly in implicit form, it 
Xcomputes three-stage least-squares estimates, TSLS option, and for nonlinear 
Xdynamic systems, possibly in implicit form, generalized method-of-moments 
Xestimates, GMM option.  
X
XThe documentation consists of this file, the two header files nlmdl.h and 
Xrealmat.h, and the examples in the directories ch1eg1, ch5eg1, ch6eg1, and 
Xch6eg2.  
X
XAs distributed, the code is set up for use with GNU's g++ compiler on a Unix 
Xbox.  To check using one of the examples, e.g. ch1eg1, cd to ch1eg1 and type 
Xmake -f ../Makefile.  Each directory has a file detail.bak created using 
Xnlmdl > detail.dat that you can use for comparison.  
X
XAlthough intended for use with GNU's g++ compiler, the code can be used with 
XBorland's Turbo C++ compiler.  To use Turbo C++, permute the #undef and #define 
Xfor compiler choice in usual.h, copy the contents of, e.g., ch1eg1 to the 
Xworking directory, and list every file with a .cc extension in the .PRJ file 
Xexcept nlopr.cc.  Small models, such as ch1eg1, execute correctly when compiled 
Xwith the large memory option but larger ones, such as ch5eg2, run out of memory 
Xduring execution.  I haven't tried Turbo's overlay and memory expansion 
Xfeatures to see if larger models can be accommodated.  The code hasn't been 
Xtested with other C++ compilers.  
X
XCopyright (C) 1990 by A. Ronald Gallant.
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, provided that 
Xthe above copyright notice appear in all copies and that both that copyright 
Xnotice and this permission notice appear in supporting documentation.  
X
XThis software is provided "as is" without any expressed or implied warranty.
X
X-------------------------------------------------------------------------------
XProfessor A. Ronald Gallant        Phone:  919-737-2531
XDepartment of Statistics           FAX:    919-737-7591
XNorth Carolina State University    e-mail: arg at ccvr1.cc.ncsu.edu
XCampus Box 8203                    ftp:    ccvr1.cc.ncsu.edu (128.109.212.20), 
XRaleigh NC 27695-8203 USA                  user: anonymous, directory: pub/arg 
X-------------------------------------------------------------------------------
END_OF_FILE
if test 2877 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test ! -d 'ch1eg1' ; then
    echo shar: Creating directory \"'ch1eg1'\"
    mkdir 'ch1eg1'
fi
if test -f 'ch1eg1/amstat.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch1eg1/amstat.dat'\"
else
echo shar: Extracting \"'ch1eg1/amstat.dat'\" \(1020 characters\)
sed "s/^X//" >'ch1eg1/amstat.dat' <<'END_OF_FILE'
X 1    0.98610    1     1     6.28
X 2    1.03848    0     1     9.86
X 3    0.95482    1     1     9.11
X 4    1.04184    0     1     8.43
X 5    1.02324    1     1     8.11
X 6    0.90475    0     1     1.82
X 7    0.96263    1     1     6.58
X 8    1.05026    0     1     5.02
X 9    0.98861    1     1     6.52
X10    1.03437    0     1     3.75
X11    0.98982    1     1     9.86
X12    1.01214    0     1     7.31
X13    0.66768    1     1     0.47
X14    0.55107    0     1     0.07
X15    0.96822    1     1     4.07
X16    0.98823    0     1     4.61
X17    0.59759    1     1     0.17
X18    0.99418    0     1     6.99
X19    1.01962    1     1     4.39
X20    0.69163    0     1     0.39
X21    1.04255    1     1     4.73
X22    1.04343    0     1     9.42
X23    0.97526    1     1     8.90
X24    1.04969    0     1     3.02
X25    0.80219    1     1     0.77
X26    1.01046    0     1     3.31
X27    0.95196    1     1     4.51
X28    0.97658    0     1     2.65
X29    0.50811    1     1     0.08
X30    0.91840    0     1     6.11
END_OF_FILE
if test 1020 -ne `wc -c <'ch1eg1/amstat.dat'`; then
    echo shar: \"'ch1eg1/amstat.dat'\" unpacked with wrong size!
fi
# end of 'ch1eg1/amstat.dat'
fi
if test -f 'ch1eg1/ending.bak' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch1eg1/ending.bak'\"
else
echo shar: Extracting \"'ch1eg1/ending.bak'\" \(2523 characters\)
sed "s/^X//" >'ch1eg1/ending.bak' <<'END_OF_FILE'
XGallant, "Nonlinear Statistical Models," Chapter 1, Figure 5, p. 35-36.
XSUR                What estimation method?  Code SUR, TSLS, or GMM.
X30                 Number of observations, t = 1, ..., n.
X1                  Number of equations, i.e. dimension of e.
X0                  Number of instruments, i.e. dimension of Z.
X4                  Number of parameters, i.e. dimension of theta.
X50                 Upper limit on Gauss-Newton iterations.
X1                  Number var iterates, ivar=0 means none.
Xhomoskedastic      Code homoskedastic or heteroskedastic.
X0                  Number of moving average terms MA for var estimate.
Xnone               Code none or Parzen, none when MA>0 is unwise.
X1.000000e-13       Convergence tolerance, tol=1.0e-8 is reasonable.
X1.000000e-10       Inversion tolerance, eps=1.0e-13 is reasonable
Xfull               How much output?  Code none, minimal, or full.
X4                  Computed rank of V.
Xcorrected          Divisor of var, corrected or uncorrected.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X  -2.5889698083278231e-02          -0.02588970  theta(1)
X   1.0156796693196859e+00           1.01567967  theta(2)
X  -1.1156971398981310e+00          -1.11569714  theta(3)
X  -5.0490286151154495e-01          -0.50490286  theta(4)
X   1.1729052766553795e-03           0.00117291  var(1,1)
X   1.5936130118638265e-04           0.00015936  V(1,1)
X  -7.8715725112262180e-05          -0.00007872  V(2,1)
X  -1.7710704773277823e-04          -0.00017711  V(3,1)
X  -4.4094836963940918e-05          -0.00004409  V(4,1)
X  -7.8715725112262180e-05          -0.00007872  V(1,2)
X   9.8762401664581004e-05           0.00009876  V(2,2)
X   6.0702486057973514e-04           0.00060702  V(3,2)
X  -1.8513810538785802e-06          -0.00000185  V(4,2)
X  -1.7710704773277823e-04          -0.00017711  V(1,3)
X   6.0702486057973514e-04           0.00060702  V(2,3)
X   2.6745983237711428e-02           0.02674598  V(3,3)
X   2.3562119500099977e-03           0.00235621  V(4,3)
X  -4.4094836963940918e-05          -0.00004409  V(1,4)
X  -1.8513810538785802e-06          -0.00000185  V(2,4)
X   2.3562119500099977e-03           0.00235621  V(3,4)
X   6.5829241588721008e-04           0.00065829  V(4,4)
X  -3.1122653130181253e-13          -0.00000000  D(1)
X   1.0666063107489048e-12           0.00000000  D(2)
X   4.6999396801498302e-11           0.00000000  D(3)
X   4.1405085967972343e-12           0.00000000  D(4)
X   2.5999999999999996e+01          26.00000000  obj
END_OF_FILE
if test 2523 -ne `wc -c <'ch1eg1/ending.bak'`; then
    echo shar: \"'ch1eg1/ending.bak'\" unpacked with wrong size!
fi
# end of 'ch1eg1/ending.bak'
fi
if test -f 'ch1eg1/model.cc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch1eg1/model.cc'\"
else
echo shar: Extracting \"'ch1eg1/model.cc'\" \(1794 characters\)
sed "s/^X//" >'ch1eg1/model.cc' <<'END_OF_FILE'
X#include "model.h"
X
Xmodel::model() { }
X
Xmodel::~model() { }
X
X
Xrealmat model::e(INTEGER t)
X{
X  realmat err(1,1);
X
X  err.elem(1,1)
X    = data.elem(t,2)
X      - data.elem(t,3)*s.theta.elem(1,1)
X      - data.elem(t,4)*s.theta.elem(2,1)
X      - s.theta.elem(4,1)*exp(data.elem(t,5)*s.theta.elem(3,1));
X
X  return err;
X}
X
Xrealmat model::dele(INTEGER t) 
X{
X  realmat delerr(1,4);
X  REAL    tmp;
X
X  tmp = exp(data.elem(t,5)*s.theta.elem(3,1));
X
X  delerr.elem(1,1) = - data.elem(t,3);
X  delerr.elem(1,2) = - data.elem(t,4);
X  delerr.elem(1,3) = - s.theta.elem(4,1)*data.elem(t,5)*tmp;
X  delerr.elem(1,4) = - tmp;
X
X  return delerr;
X
X}
X
X
Xint model::initialize()
X{
X#ifdef GNU_GPP_COMPILER
X
X#ifdef USE_ATT_STYLE_IO_WITH_GNU
X  filebuf databuf;
X  if( databuf.open("amstat.dat", input) == 0 ){
X    cerr << "Error, model::model, Cannot open amstat.dat\n";
X    exit(1);
X  }
X  istream dataget(&databuf);
X#endif 
X
X#ifdef USE_GNU_STYLE_IO_WITH_GNU
X  istream dataget("amstat.dat",io_readonly,a_useonly);
X  if (!dataget) {
X    cerr << "Error, model::model\n";
X    exit(1);
X  } 
X#endif 
X
X#endif 
X
X#ifdef TURBO_CPP_COMPILER
X  ifstream dataget("amstat.dat");
X  if (!dataget) {
X    cerr << "Error, model::model\n";
X    exit(1);
X  } 
X#endif 
X
X  data.resize(30,5);
X  INTEGER i,j;
X
X  double x;
X  for (i=1; i<=30; i++) {  
X  for (j=1; j<=5;  j++) {    
X    dataget >> x; 
X    data.elem(i,j) = (REAL)x;
X  }
X  }
X
X  if(strcmp(s.detail,"full")==0) cout <<starbox("/data//_")<< data;
X
X  dataget.close();
X
X  return 1;
X}
X
Xrealmat model::Z(INTEGER t)
X{
X  realmat z(s.K,1);
X  realmat tmp(s.p,1);
X  tmp = dele(t);
X  for (INTEGER i = 1; i<=s.K; i++)
X    if (i <= s.p) 
X      z[i] = tmp[i];  // will produce SUR estimates when s.K = s.p 
X    else 
X      z[i]=pow(data.elem(t,5),i-s.p);
X  return z;
X}
X
Xint model::terminate() { return 0; }
END_OF_FILE
if test 1794 -ne `wc -c <'ch1eg1/model.cc'`; then
    echo shar: \"'ch1eg1/model.cc'\" unpacked with wrong size!
fi
# end of 'ch1eg1/model.cc'
fi
if test -f 'ch1eg1/model.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch1eg1/model.h'\"
else
echo shar: Extracting \"'ch1eg1/model.h'\" \(363 characters\)
sed "s/^X//" >'ch1eg1/model.h' <<'END_OF_FILE'
X#ifndef __FILE_MODEL_H_SEEN__
X#pragma once
X#define __FILE_MODEL_H_SEEN__ 1
X
X#include "status.h"
X
Xextern status s;
X
Xclass model
X{
X
Xprotected:
X  realmat   data;
X
Xpublic:
X            model();
X            ~model();
X
X  int       initialize();
X  int       terminate();
X
X  realmat   e(INTEGER t);    
X  realmat   dele(INTEGER t);
X  realmat   Z(INTEGER t);  
X
X};
X
X#endif
END_OF_FILE
if test 363 -ne `wc -c <'ch1eg1/model.h'`; then
    echo shar: \"'ch1eg1/model.h'\" unpacked with wrong size!
fi
# end of 'ch1eg1/model.h'
fi
if test -f 'ch1eg1/starting.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch1eg1/starting.dat'\"
else
echo shar: Extracting \"'ch1eg1/starting.dat'\" \(1097 characters\)
sed "s/^X//" >'ch1eg1/starting.dat' <<'END_OF_FILE'
XGallant, "Nonlinear Statistical Models," Chapter 1, Figure 5, p. 35-36.
XSUR                What estimation method?  Code SUR, TSLS, or GMM.
X30                 Number of observations, t = 1, ..., n.
X1                  Number of equations, i.e. dimension of e.
X0                  Number of instruments, i.e. dimension of Z.
X4                  Number of parameters, i.e. dimension of theta.
X50                 Upper limit on Gauss-Newton iterations.
X1                  Number var iterates, ivar=0 means none.
Xhomoskedastic      Code homoskedastic or heteroskedastic.
X0                  Number of moving average terms MA for var estimate.
Xnone               Code none or Parzen, none when MA>0 is unwise.
X1.000000e-13       Convergence tolerance, tol=1.0e-8 is reasonable.
X1.000000e-10       Inversion tolerance, eps=1.0e-13 is reasonable
Xfull               How much output?  Code none, minimal, or full.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X -0.04866
X  1.03884
X -0.73792
X -0.51362 
END_OF_FILE
if test 1097 -ne `wc -c <'ch1eg1/starting.dat'`; then
    echo shar: \"'ch1eg1/starting.dat'\" unpacked with wrong size!
fi
# end of 'ch1eg1/starting.dat'
fi
if test ! -d 'ch5eg1' ; then
    echo shar: Creating directory \"'ch5eg1'\"
    mkdir 'ch5eg1'
fi
if test -f 'ch5eg1/electb.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch5eg1/electb.dat'\"
else
echo shar: Extracting \"'ch5eg1/electb.dat'\" \(612 characters\)
sed "s/^X//" >'ch5eg1/electb.dat' <<'END_OF_FILE'
X                      1                     1.06     2.86      3.90
X                      2                     1.78     2.86      3.90
X                      3                     1.06     3.90      3.90
X                      4                     1.78     3.90      3.90
X                      5                     1.37     3.34      5.06
X                      6                     1.06     2.86      6.56
X                      7                     1.78     2.86      6.56
X                      8                     1.06     3.90      6.56
X                      9                     1.78     3.90      6.56
END_OF_FILE
if test 612 -ne `wc -c <'ch5eg1/electb.dat'`; then
    echo shar: \"'ch5eg1/electb.dat'\" unpacked with wrong size!
fi
# end of 'ch5eg1/electb.dat'
fi
if test -f 'ch5eg1/model.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch5eg1/model.h'\"
else
echo shar: Extracting \"'ch5eg1/model.h'\" \(423 characters\)
sed "s/^X//" >'ch5eg1/model.h' <<'END_OF_FILE'
X#ifndef __FILE_MODEL_H_SEEN__
X#pragma once
X#define __FILE_MODEL_H_SEEN__ 1
X
X#include "status.h"
X
Xextern status s;
X
Xclass model
X{
X
Xprotected:
X  realmat   data;
X
Xpublic:
X            model();
X            ~model();
X
X  int       initialize();
X  int       terminate();
X
X  realmat   e(INTEGER t);      //e    is  2 by 1
X  realmat   dele(INTEGER t);   //dele is  2 by 8
X  realmat   Z(INTEGER t);      //Z    is 17 by 1
X
X};
X
X#endif
END_OF_FILE
if test 423 -ne `wc -c <'ch5eg1/model.h'`; then
    echo shar: \"'ch5eg1/model.h'\" unpacked with wrong size!
fi
# end of 'ch5eg1/model.h'
fi
if test -f 'ch5eg1/starting.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch5eg1/starting.dat'\"
else
echo shar: Extracting \"'ch5eg1/starting.dat'\" \(1113 characters\)
sed "s/^X//" >'ch5eg1/starting.dat' <<'END_OF_FILE'
XGallant, "Nonlinear Statistical Models," Chapter 5, Figure 3, p. 324-326
XSUR                What estimation method?  Code SUR, TSLS, or GMM.
X224                Number of observations, t = 1, ..., n.
X2                  Number of equations, i.e. dimension of e.
X0                  Number of instruments, i.e. dimension of Z.
X8                  Number of parameters, i.e. dimension of theta.
X50                 Upper limit on Gauss-Newton iterations.
X1                  Number var iterates, ivar=0 means none.
Xhomoskedastic      Code homoskedastic or heteroskedastic.
X0                  Number of moving average terms MA for var estimate.
Xnone               Code none or Parzen, none when MA>0 is unwise.
X1.000000e-13       Convergence tolerance, tol=1.0e-8 is reasonable.
X1.000000e-10       Inversion tolerance, eps=1.0e-13 is reasonable
Xminimal            How much output?  Code none, minimal, or full.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X -2.90
X -1.30
X  0.82
X  0.36
X -1.50
X -1.00
X -0.03
X -0.47
END_OF_FILE
if test 1113 -ne `wc -c <'ch5eg1/starting.dat'`; then
    echo shar: \"'ch5eg1/starting.dat'\" unpacked with wrong size!
fi
# end of 'ch5eg1/starting.dat'
fi
if test ! -d 'ch6eg1' ; then
    echo shar: Creating directory \"'ch6eg1'\"
    mkdir 'ch6eg1'
fi
if test -f 'ch6eg1/README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch6eg1/README'\"
else
echo shar: Extracting \"'ch6eg1/README'\" \(92 characters\)
sed "s/^X//" >'ch6eg1/README' <<'END_OF_FILE'
X
XDo this to get the missing files:
X
X  cp ../ch5eg1/el*.dat ./
X  cp ../ch5eg1/model.* ./ 
X  
END_OF_FILE
if test 92 -ne `wc -c <'ch6eg1/README'`; then
    echo shar: \"'ch6eg1/README'\" unpacked with wrong size!
fi
# end of 'ch6eg1/README'
fi
if test -f 'ch6eg1/starting.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch6eg1/starting.dat'\"
else
echo shar: Extracting \"'ch6eg1/starting.dat'\" \(1113 characters\)
sed "s/^X//" >'ch6eg1/starting.dat' <<'END_OF_FILE'
XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 1, p. 436.
XTSLS               What estimation method?  Code SUR, TSLS, or GMM.
X224                Number of observations, t = 1, ..., n.
X2                  Number of equations, i.e. dimension of e.
X17                 Number of instruments, i.e. dimension of Z.
X8                  Number of parameters, i.e. dimension of theta.
X20                 Upper limit on Gauss-Newton iterations.
X1                  Number var iterates, ivar=0 means none.
Xhomoskedastic      Code homoskedastic or heteroskedastic.
X0                  Number of moving average terms MA for var estimate.
Xnone               Code none or Parzen, none when MA>0 is unwise.
X1.000000e-08       Convergence tolerance, tol=1.0e-8 is reasonable.
X1.000000e-10       Inversion tolerance, eps=1.0e-13 is reasonable
Xfull               How much output?  Code none, minimal, or full.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X -2.98
X -1.16
X  0.787
X  0.353
X -1.51
X -1.0
X  0.054
X -0.474
END_OF_FILE
if test 1113 -ne `wc -c <'ch6eg1/starting.dat'`; then
    echo shar: \"'ch6eg1/starting.dat'\" unpacked with wrong size!
fi
# end of 'ch6eg1/starting.dat'
fi
if test ! -d 'ch6eg2' ; then
    echo shar: Creating directory \"'ch6eg2'\"
    mkdir 'ch6eg2'
fi
if test -f 'ch6eg2/ending.bak' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch6eg2/ending.bak'\"
else
echo shar: Extracting \"'ch6eg2/ending.bak'\" \(2101 characters\)
sed "s/^X//" >'ch6eg2/ending.bak' <<'END_OF_FILE'
XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 2, p. 449-450.
XGMM                What estimation method?  Code SUR, TSLS, or GMM.
X238                Number of observations, t = 1, ..., n.
X1                  Number of equations, i.e. dimension of e.
X3                  Number of instruments, i.e. dimension of Z.
X2                  Number of parameters, i.e. dimension of theta.
X20                 Upper limit on Gauss-Newton iterations.
X1                  Number var iterates, ivar=0 means none.
Xhomoskedastic      Code homoskedastic or heteroskedastic.
X0                  Number of moving average terms MA for var estimate.
XParzen             Code none or Parzen, none when MA>0 is unwise.
X1.000000e-05       Convergence tolerance, tol=1.0e-8 is reasonable.
X1.000000e-13       Inversion tolerance, eps=1.0e-13 is reasonable
Xfull               How much output?  Code none, minimal, or full.
X2                  Computed rank of V.
Xuncorrected        Divisor of var, corrected or uncorrected.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X  -1.0335217392035390e+00          -1.03352174  theta(1)
X   9.9825572364240200e-01           0.99825572  theta(2)
X   4.0582168346665826e-01           0.40582168  var(1,1)
X   4.0643410965960231e-01           0.40643411  var(2,1)
X   3.9873658267692480e-01           0.39873658  var(3,1)
X   4.0643410965960231e-01           0.40643411  var(1,2)
X   4.0705487414860658e-01           0.40705487  var(2,2)
X   3.9936326231932223e-01           0.39936326  var(3,2)
X   3.9873658267692480e-01           0.39873658  var(1,3)
X   3.9936326231932223e-01           0.39936326  var(2,3)
X   3.9272327136336027e-01           0.39272327  var(3,3)
X   3.5800932072477121e+00           3.58009321  V(1,1)
X  -7.2126817691390913e-03          -0.00721268  V(2,1)
X  -7.2126817691390913e-03          -0.00721268  V(1,2)
X   2.0603180900457831e-05           0.00002060  V(2,2)
X  -9.1931859179544446e-08          -0.00000009  D(1)
X   1.8525999753608607e-10           0.00000000  D(2)
X   1.0569217148505041e+00           1.05692171  obj
END_OF_FILE
if test 2101 -ne `wc -c <'ch6eg2/ending.bak'`; then
    echo shar: \"'ch6eg2/ending.bak'\" unpacked with wrong size!
fi
# end of 'ch6eg2/ending.bak'
fi
if test -f 'ch6eg2/model.cc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch6eg2/model.cc'\"
else
echo shar: Extracting \"'ch6eg2/model.cc'\" \(1796 characters\)
sed "s/^X//" >'ch6eg2/model.cc' <<'END_OF_FILE'
X#include "model.h"
X
Xmodel::model() { }
X
Xmodel::~model() { }
X
X
Xrealmat model::e(INTEGER t)
X{
X  realmat et(1,1);
X  REAL    a,b,yta,yt,xt;
X  INTEGER i;
X
X  i=t+2;
X  
X  yt = (nds[i]/pop[i])/(nds[i-1]/pop[i-1]);
X  xt = (1.0+nyse[i])*(dflat[i-1]/dflat[i]);
X
X  a=s.theta[1];
X  b=s.theta[2];
X
X  yta = pow(yt,a);
X
X  et[1] = b * yta * xt - 1.0;
X
X  return et;
X}
X
Xrealmat model::dele(INTEGER t) 
X{
X  realmat derqt(1,2);
X
X  REAL    a,b,yta,yt,xt;
X  INTEGER i;
X
X  i=t+2;
X  
X  yt = (nds[i]/pop[i])/(nds[i-1]/pop[i-1]);
X  xt = (1.0+nyse[i])*(dflat[i-1]/dflat[i]);
X
X  a=s.theta[1];
X  b=s.theta[2];
X
X  yta = pow(yt,a);
X
X  derqt.elem(1,1) = b * log(yt) * yta * xt;
X
X  derqt.elem(1,2) = yta*xt;
X
X  return derqt;
X
X}
X
X
Xint model::initialize()
X{
X  INTEGER i;
X  double tmp;
X
X#ifdef  GNU_GPP_COMPILER
X#ifdef  USE_ATT_STYLE_IO_WITH_GNU
X
X  filebuf cdata_buf;
X  if (cdata_buf.open("hansen.dat",input) ==0) {
X    cerr << "Error, model::model, Cannot open hansen.dat.\n";
X    exit(1);
X  }
X  istream cdata(&cdata_buf);
X
X#endif
X
X#ifdef  USE_GNU_STYLE_IO_WITH_GNU
X
X  istream cdata("hansen.dat",io_readonly,a_useonly);
X  if ( !cdata ) {
X    cerr << "Error, model::model, Cannot open hansen.dat.\n";
X    exit(1);
X  }
X
X#endif
X
X#endif
X
X#ifdef  TURBO_CPP_COMPILER
X
X  ifstream cdata("hansen.dat");
X  if (!cdata) {
X    cerr << "Error, model::model, Cannot open hansen.dat.\n";
X    exit(1);
X  }
X
X#endif
X
X
X  for (i=1; i<=240; i++) {
X    cdata >> tmp; nds[i]=(REAL)tmp;
X    cdata >> tmp; pop[i]=(REAL)tmp;
X    cdata >> tmp; nyse[i]=(REAL)tmp;
X    cdata >> tmp; dflat[i]=(REAL)tmp;
X  }
X
X  return 1;
X}
X
Xrealmat model::Z(INTEGER t)
X{
X  INTEGER i;
X
X  i=t+2;
X
X  realmat z(3,1);
X
X  z[1]=1.0;
X  z[2]=(nds[i-1]/pop[i-1])/(nds[i-2]/pop[i-2]);
X  z[3]=(1.0+nyse[i-1])*(dflat[i-2]/dflat[i-1]);
X
X  return z;
X}
X
Xint model::terminate() { return 0; }
X
X
X
X
X
END_OF_FILE
if test 1796 -ne `wc -c <'ch6eg2/model.cc'`; then
    echo shar: \"'ch6eg2/model.cc'\" unpacked with wrong size!
fi
# end of 'ch6eg2/model.cc'
fi
if test -f 'ch6eg2/model.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch6eg2/model.h'\"
else
echo shar: Extracting \"'ch6eg2/model.h'\" \(477 characters\)
sed "s/^X//" >'ch6eg2/model.h' <<'END_OF_FILE'
X#ifndef __FILE_MODEL_H_SEEN__
X#pragma once
X#define __FILE_MODEL_H_SEEN__ 1
X
X#include "status.h"
X
Xextern status s;
X
Xclass model
X{
X
Xprotected:
X  REAL  nds[256];
X  REAL  pop[256];
X  REAL  nyse[256];
X  REAL  dflat[256];
X
Xpublic:
X            model();
X            ~model();
X
X  int       initialize();
X  int       terminate();
X
X  realmat   e(INTEGER t);      //e    is 1 by 1
X  realmat   dele(INTEGER t);   //dele is 1 by 2
X  realmat   Z(INTEGER t);      //Z    is 3 by 1
X
X};
X
X#endif
END_OF_FILE
if test 477 -ne `wc -c <'ch6eg2/model.h'`; then
    echo shar: \"'ch6eg2/model.h'\" unpacked with wrong size!
fi
# end of 'ch6eg2/model.h'
fi
if test -f 'ch6eg2/start3l.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch6eg2/start3l.dat'\"
else
echo shar: Extracting \"'ch6eg2/start3l.dat'\" \(1068 characters\)
sed "s/^X//" >'ch6eg2/start3l.dat' <<'END_OF_FILE'
XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 2, p. 449-450.
XGMM                What estimation method?  Code SUR, TSLS, or GMM.
X238                Number of observations, t = 1, ..., n.
X1                  Number of equations, i.e. dimension of e.
X3                  Number of instruments, i.e. dimension of Z.
X2                  Number of parameters, i.e. dimension of theta.
X20                 Upper limit on Gauss-Newton iterations.
X1                  Number var iterates, ivar=0 means none.
Xheteroskedastic    Code homoskedastic or heteroskedastic.
X3                  Number of moving average terms MA for var estimate.
XParzen             Code none or Parzen, none when MA>0 is unwise.
X1.000000e-05       Convergence tolerance, tol=1.0e-8 is reasonable.
X1.000000e-13       Inversion tolerance, eps=1.0e-13 is reasonable
Xfull               How much output?  Code none, minimal, or full.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X-0.4
X 0.9
END_OF_FILE
if test 1068 -ne `wc -c <'ch6eg2/start3l.dat'`; then
    echo shar: \"'ch6eg2/start3l.dat'\" unpacked with wrong size!
fi
# end of 'ch6eg2/start3l.dat'
fi
if test -f 'ch6eg2/starting.dat' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'ch6eg2/starting.dat'\"
else
echo shar: Extracting \"'ch6eg2/starting.dat'\" \(1068 characters\)
sed "s/^X//" >'ch6eg2/starting.dat' <<'END_OF_FILE'
XGallant, "Nonlinear Statistical Models," Chapter 6, Figure 2, p. 449-450.
XGMM                What estimation method?  Code SUR, TSLS, or GMM.
X238                Number of observations, t = 1, ..., n.
X1                  Number of equations, i.e. dimension of e.
X3                  Number of instruments, i.e. dimension of Z.
X2                  Number of parameters, i.e. dimension of theta.
X20                 Upper limit on Gauss-Newton iterations.
X1                  Number var iterates, ivar=0 means none.
Xhomoskedastic      Code homoskedastic or heteroskedastic.
X0                  Number of moving average terms MA for var estimate.
XParzen             Code none or Parzen, none when MA>0 is unwise.
X1.000000e-05       Convergence tolerance, tol=1.0e-8 is reasonable.
X1.000000e-13       Inversion tolerance, eps=1.0e-13 is reasonable
Xfull               How much output?  Code none, minimal, or full.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X                   Blank line.
X-0.4
X 0.9
END_OF_FILE
if test 1068 -ne `wc -c <'ch6eg2/starting.dat'`; then
    echo shar: \"'ch6eg2/starting.dat'\" unpacked with wrong size!
fi
# end of 'ch6eg2/starting.dat'
fi
if test -f 'dcond.cc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dcond.cc'\"
else
echo shar: Extracting \"'dcond.cc'\" \(2010 characters\)
sed "s/^X//" >'dcond.cc' <<'END_OF_FILE'
X/*
XName          dcond - Improves the accuracy of dsweep when the diagonal 
X                      elements of a are not of the same order of magnitude.
X
XUsage         #include "usual.h"
X              #include "tools.h"
X              void dcond(REAL *a, INTEGER n, REAL *s,INTEGER isw)
X
XPrototype in  tools.h
X
XDescription   a is a symmetric, positive definite, n by n matrix stored 
X              columnwise with no unused space and first element in a[0]; i.e.,
X              for (j=1; j<=n; j++) for (i=1; i<=n; i++) aij=a[n*(j-1)+(i-1)];
X              will traverse the matrix with aij being the element in the 
X              i-th row and j-th column.  s is a work vector of length n.
X              The intended calling sequence is:
X                dcond(a,n,s,0);
X                ier=dsweep(a,n,eps);
X                dcond(a,n,s,1);
X              The usage
X                dcond(a,n,s,0);
X              will return a correlation matrix in a and the standard errors 
X              in s when a is a variance-covariance matrix.
X
XRemark        dscond.c is dcond.f as translated by f2c (version of 3 February 
X              1990  3:36:42) with some reworking to remove dependence on f2c 
X              libraries.
X
XReturn value  None.
X
XFunctions     Library: (none)
Xcalled        Sublib:  (none)
X*/
X
X#include "usual.h"
X#include "tools.h"
X
Xvoid dcond(REAL *a, INTEGER n, REAL *s, INTEGER isw)
X{
X    /* System generated locals */
X    INTEGER a_dim1, a_offset, i_1, i_2;
X
X    /* Local variables */
X    INTEGER i, j;
X
X    /* Parameter adjustments */
X    a_dim1 = n;
X    a_offset = a_dim1 + 1;
X    a -= a_offset;
X    --s;
X
X    /* Function Body */
X    if (isw == 1) {
X        goto L20;
X    }
X    i_1 = n;
X    for (i = 1; i <= i_1; ++i) {
X        s[i] = sqrt(a[i + i * a_dim1]);
X    }
XL20:
X    i_1 = n;
X    for (i = 1; i <= i_1; ++i) {
X        i_2 = n;
X        for (j = 1; j <= i_2; ++j) {
X            if (s[i] * s[j] != 0.) {
X                a[i + j * a_dim1] /= s[i] * s[j];
X            }
X        }
X    }
X    return;
X}
END_OF_FILE
if test 2010 -ne `wc -c <'dcond.cc'`; then
    echo shar: \"'dcond.cc'\" unpacked with wrong size!
fi
# end of 'dcond.cc'
fi
if test -f 'dsweep.cc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'dsweep.cc'\"
else
echo shar: Extracting \"'dsweep.cc'\" \(2640 characters\)
sed "s/^X//" >'dsweep.cc' <<'END_OF_FILE'
X/*
XName          dsweep - Inverts a positive definite matrix in place by a 
X                       diagonal sweep.
X
XUsage         #include "usual.h"
X              #include "tools.h"
X              INTEGER dsweep(REAL *a, INTEGER n, REAL eps)
X
XPrototype in  tools.h
X
XDescription   a is a symmetric, positive definite, n by n matrix stored 
X              columnwise with no unused space and first element in a[0]; i.e.,
X              for (j=1; j<=n; j++) for (i=1; i<=n; i++) aij=a[n*(j-1)+(i-1)];
X              will traverse the matrix with aij being the element in the 
X              i-th row and j-th column.  On return a contains the inverse of a
X              stored columnwise.  eps is an input constant used as a relative 
X              tolerance in testing for degenerate rank.  A reasonable value 
X              for eps is 1.e-13. 
X
XRemark        dsweep.cc is dsweep.f translated to C++.
X
XReference     Schatzoff, M. et al.  Efficient Calculation of all Possible 
X              Regressions. Technometrics, 10. 769-79 (November 1968)
X
XReturn value  The return value ier is an error parameter coded as follows:
X              ier=0, no error, rank of a is n;  ier > 0, a is singular, rank 
X              of a is n-ier.  If ier > 0 then dsweep returns a g-inverse. 
X
XFunctions     Library: (none)
Xcalled        Sublib:  (none)
X*/
X
X#include "usual.h"
X#include "tools.h"
X
X
XINTEGER dsweep(REAL *a, INTEGER n, REAL eps)
X{
X  INTEGER i, j, k, kk, ier;
X  REAL    test, d, aik, akj, akk, tol;
X
X  a--;   // Adjust offset to allow Fortran style indexing.
X
X  tol=0.0;
X
X  for (i=1; i<=n; i++) {
X    test=a[n*(i-1)+i];
X    if(test > tol) tol=test;
X  }
X
X  tol=tol*eps;
X  ier=0;
X
X  for (k=1; k<=n; k++) {
X
X    kk=n*(k-1)+k;
X
X    akk=a[kk];
X
X    if (akk < tol) {
X
X      ier=ier+1;
X
X      for (j=k; j<=n; j++)     // zero out row k of upper triangle
X        a[n*(j-1)+k]=0.0;
X
X      for (i=1; i<=k-1; i++)  // zero out column k of upper triangle
X        a[kk-i]=0.0;
X
X    } 
X    else {  // sweep
X
X      d=1.0/akk;
X
X      for (i=1; i <= n; i++) {
X      for (j=i; j <= n; j++) {
X        if (i != k && j != k)  {
X
X          if (i<k) 
X            aik=a[n*(k-1)+i];
X          else 
X            aik=a[n*(i-1)+k];
X
X          if (k<j) 
X            akj=a[n*(j-1)+k];
X          else 
X            akj=-a[n*(k-1)+j];
X
X          a[n*(j-1)+i] -= aik*akj*d;
X        }
X      }
X      }
X
X      for (j=k; j<=n; j++)
X        a[n*(j-1)+k] *= d;
X
X      for (i=1; i<=k-1; i++)
X        a[kk-i] = -a[kk-i]*d;
X
X      a[kk]=d;
X
X    }
X  }
X
X  // copy the upper triangle to the lower
X
X  for (i=1; i <= n; i++)
X  for (j=i; j <= n; j++)
X    a[n*(i-1)+j]=a[n*(j-1)+i];
X
X  return ier;
X}
X
X
END_OF_FILE
if test 2640 -ne `wc -c <'dsweep.cc'`; then
    echo shar: \"'dsweep.cc'\" unpacked with wrong size!
fi
# end of 'dsweep.cc'
fi
if test -f 'nlmdl.cc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nlmdl.cc'\"
else
echo shar: Extracting \"'nlmdl.cc'\" \(3167 characters\)
sed "s/^X//" >'nlmdl.cc' <<'END_OF_FILE'
X/* ----------------------------------------------------------------------------
X
Xnlmdl: nlmdl.cc
X
Xnlmdl is a C++ implementation of the statistical methods in A. Ronald 
XGallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 
X1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed 
Xwith it.  The header files nlmdl.h and realmat.h describe the use of the 
Xprogram and matrix class, respectively.  
X
XCopyright (C) 1990.
X
XA. Ronald Gallant
XP.O. Box 5513 
XRaleigh NC 27650-5513 
XUSA   
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, provided 
Xthat the above copyright notice appear in all copies and that both that 
Xcopyright notice and this permission notice appear in supporting 
Xdocumentation.  
X
XThis software is provided "as is" without any expressed or implied warranty.
X
X---------------------------------------------------------------------------- */
X#include "nlmdl.h"
X
Xtypedef void (*ZERO_ARGUMENT_NL_OPR)();
Xtypedef void (*ONE_ARGUMENT_NL_OPR)(int);
X
Xstatus s; 
Xmodel  m;
X
XZERO_ARGUMENT_NL_OPR opr_mgn;
XZERO_ARGUMENT_NL_OPR opr_obj;
XONE_ARGUMENT_NL_OPR  opr_var;
XZERO_ARGUMENT_NL_OPR opr_V;
X
X#include "nlopr.cc"
X
Xint main()
X{
X  char msg[MAX_STATUS_LINE];
X
X  s.from(s.starting); 
X
X  repeat:
X
X    if(m.initialize()==0) exit(0);
X
X    s.from(s.starting);
X
X    if(strcmp(s.detail,"none") != 0) s.display(START_UP);
X    
X    if(strcmp(s.detail,"none") != 0) 
X      cout << starbox("/Starting theta//_") << s.theta; 
X
X    if(strcmp(s.method,"SUR") == 0) {
X      opr_mgn = &SUR_mgn; 
X      opr_obj = &SUR_obj; 
X      opr_var = &SUR_var; 
X      opr_V   = &SUR_V;
X    }
X    else if(strcmp(s.method,"TSLS") == 0) {
X
X      if ( strcmp(s.vartype,"heterogeneous") == 0 || s.MA>0 ) {
X        cerr << "\nError, nlmdl, Use GMM for this case, not TSLS.\n\n";
X        exit(1);
X      }
X
X      opr_mgn = &TSLS_mgn; 
X      opr_obj = &TSLS_obj; 
X      opr_var = &SUR_var; 
X      opr_V   = &TSLS_V;
X    }
X    else if(strcmp(s.method,"GMM") == 0) {
X      opr_mgn = &GMM_mgn;
X      opr_obj = &GMM_obj; 
X      opr_var = &GMM_var; 
X      opr_V   = &GMM_V;
X    }
X    else {
X      cerr << "Error, nlmdl, s.method set wrong.\n";
X      exit(1);
X    }
X
X    s.V.resize(s.p, s.p, (REAL)0 );
X
X    for (INTEGER i = 0; i <= s.p; i++) s.V.elem(i,i) = 1.0;
X
X    s.D.resize(s.p, 1, (REAL)0 );
X
X    for (INTEGER var_loop = 0; var_loop <= s.ivar; var_loop++) {
X
X      (*opr_var)(var_loop);
X
X      if(strcmp(s.detail,"full") == 0) {
X        cout << "\nvar_loop " << var_loop << "\n";
X        s.display(VAR_ITERATE);
X      }
X
X      for (INTEGER theta_loop = 0; theta_loop <= s.itheta; theta_loop++) {
X
X        (*opr_mgn)();
X
X        if(strcmp(s.detail,"full") == 0) {
X          cout << "\ntheta_loop " << theta_loop << "\n";
X          s.display(THETA_ITERATE);
X        }
X        
X        int rv = line_search(&msg[0]);
X
X        if(strcmp(s.detail,"full") == 0) cout << msg;
X        if(rv != 0) break;
X      }
X    }
X
X  (*opr_mgn)();
X  (*opr_V)();
X
X  s.to(s.ending);
X
X  if (strcmp(s.detail,"none") != 0) s.display(TERMINATION);
X
X  if(m.terminate() != 0) goto repeat;
X
X  exit(0);
X}
END_OF_FILE
if test 3167 -ne `wc -c <'nlmdl.cc'`; then
    echo shar: \"'nlmdl.cc'\" unpacked with wrong size!
fi
# end of 'nlmdl.cc'
fi
if test -f 'nlmdl.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'nlmdl.h'\"
else
echo shar: Extracting \"'nlmdl.h'\" \(5323 characters\)
sed "s/^X//" >'nlmdl.h' <<'END_OF_FILE'
X/* ---------------------------------------------------------------------------
X
Xnlmdl: nlmdl.h
X
Xnlmdl is a C++ implementation of the statistical methods in A. Ronald 
XGallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 
X1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed 
Xwith it.  The header files nlmdl.h and realmat.h describe the use of the 
Xprogram and matrix class, respectively.  
X
XCopyright (C) 1990.
X
XA. Ronald Gallant
XP.O. Box 5513 
XRaleigh NC 27650-5513 
XUSA   
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, provided 
Xthat the above copyright notice appear in all copies and that both that 
Xcopyright notice and this permission notice appear in supporting 
Xdocumentation.  
X
XThis software is provided "as is" without any expressed or implied warranty.
X
X----------------------------------------------------------------------------- 
X
XThis header describes the program nlmdl.cc for estimating theta of the model 
Xe=q(t,theta).  The user supples a file named starting.dat whose contents are 
Xdescribed by the template:
X
X  switches This line is passed to class model as a string.
X  method   What estimation method?  Code SUR, TSLS, or GMM.
X  n        Number of observations, t = 1, ..., n.
X  M        Number of equations in the system, i.e. dimension of e.
X  K        Number of instruments, i.e. dimension of Z, code K=0 with SUR.
X  p        Number of parameters, i.e. dimension of theta.
X  itheta   Upper limit on Gauss-Newton iterations.
X  ivar     Number of var iterates, ivar=0 means none.
X  vartype  Code homoskedastic or heteroskedastic.
X  MA       Number of moving average terms for var estimate, code MA=0 if e iid.
X  weights  Code none or Parzen, coding none when MA>0 is asking for trouble.
X  tol      Convergence tolerance, tol=1.0e-8 is reasonable.
X  eps      Inversion tolerance, eps=1.0e-13 is reasonable.
X  detail   How much output?  Code none, minimal, or full.
X           Blank line.
X           Blank line.
X           Blank line.
X           Blank line.
X           Blank line.
X  theta(1) Starting values for theta.  These must be supplied.
X           
X    to
X
X  theta(p) 
X  var(1)   Starting values for variance estimate.  These can be omitted.  
X           Matrix is stored columnwise.  If method = SUR or TSLS then then 
X    to     l=M and var corresponds to C(e,e').  If method = GMM then l=M*K 
X           and var corresponds to the variance of sum on t of e Kronecker 
X  var(l*l) product Z.  
X
X
XSee class status for more detail, especially status::from.  The file 
Xstarting.dat must contain at least the first line, switches.  The user also 
Xsupplies the class model as files model.h and model.cc.  The class model is 
Xdeclared in model.h which should match the following template:
X
X
X   #include "status.h"
X   external status s;
X
X   class model
X   {   
X   protected:
X     //...
X
X   public:
X            model();
X            ~model();
X   int      initialize();
X   int      terminate();
X   realmat  e(INTEGER t);      // e is M by 1
X   realmat  dele(INTEGER t);   // dele is M by p
X   realmat  Z(INTEGER t);      // Z is K by 1
X   }
X
XFor SUR, code the function Z as follows:
X
X   realmat model::Z(INTEGER t)
X   {
X     realmat z(1,1);
X     z.elem(1,1)=1.0;
X     return z;
X   }
X
XIn writing the class model, the relevant facts regarding program flow in 
Xnlmdl.cc are as follows: 
X
X  1. First, s is tentatively filled in by reading starting.dat using 
X
X       status s;
X       s.from(s.starting);
X
X     The primary purpose of this read is to get the first line from 
X     starting.dat so as to make it available to model as the string 
X     s.switches.  Nonetheless, everything in starting.dat is read and 
X     put in s.  
X
X  2. Next, initialize() of class model is called.  The function initialize() 
X     can read starting.dat, can read other data, etc.  Since all of class 
X     status's data is public, any of it can be filled in or changed by 
X     initialize().  One could, for example, fill in all of class status's 
X     data and write it using 
X
X       s.to(s.starting);
X
X     One could also switch to a different starting status file using 
X
X       s.starting="filename";
X
X     or a different ending status file using 
X
X       s.ending="filename";
X
X     If initialize() returns 0, execution stops.
X
X  3. Then, class status's data is definitively filled in by the call
X
X       s.from(s.starting);
X
X     and estimation proceeds using these settings.  
X
X  4. Finally, terminate() of class model is called; terminate() can read data, 
X     write data, etc.  If terminate() returns 0 execution stops, otherwise 
X     initialize() is called again and the cycle repeats (from Step 2).  One 
X     can use this feature to loop over a grid of starting values.
X
X
XReference:
X
XGallant, A. Ronald (1987), "Nonlinear Statistical Models,"  New York: John 
XWiley and Sons. ISBN 0-471-80260-3.
X
X--------------------------------------------------------------------------- */
X
X
X#ifndef __FILE_NLMDL_H_SEEN__
X#pragma once
X#define __FILE_NLMDL_H_SEEN__ 1
X
X#include "usual.h"      //This header is also in status.h
X#include "realmat.h"    //This header is also in status.h
X#include "tools.h"      //This header is also in status.h
X
X#include "status.h"
X#include "model.h"
X
X#endif
X
END_OF_FILE
if test 5323 -ne `wc -c <'nlmdl.h'`; then
    echo shar: \"'nlmdl.h'\" unpacked with wrong size!
fi
# end of 'nlmdl.h'
fi
if test -f 'starbox.cc' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'starbox.cc'\"
else
echo shar: Extracting \"'starbox.cc'\" \(2486 characters\)
sed "s/^X//" >'starbox.cc' <<'END_OF_FILE'
X/*
XName          starbox  - puts title in a centered box of stars.
X
XUsage         #include "usual.h"
X              #include "tools.h"
X              char* starbox(char *title, char terminator);
X
XPrototype in  tools.h
X
XDescription   title is a character string.  The string is made up of  
X              concatonated lines.  A line is made up of 0-68 characters 
X              followed by a slash (default).  Examples are:
X              cout << starbox("//line 1/line 2/line 3///");
X              cout << starbox("\n\nline 1\nline 2\nline 3\n\n\n",'\n');
X
XReturn value  Character string.
X
XFunctions     Library: strcat, strchr, strlen
Xcalled        Tools:   (none)
X              Sublib:  (none)
X*/
X
X#include "usual.h"
X#include "tools.h"
X
Xchar * starbox(char *title, char terminator)
X{
X  char      border[81],tab[81],work[256],middle[81];
X  char      *line, *begin, *end, *t;
X  int       i,pad,mpad,linesize;
X  long int  length, cum_length;
X
X  char      starbox_str_pointer[1024];
X  long int  starbox_str_length = 1024;
X
X  cum_length = 0;
X  *starbox_str_pointer = '\0';
X
X  for (i=0; i<70; i++)
X    border[i] = '*';
X  border[70] = '\n'; border[71] = '\0';
X
X  ((LINESIZE<72)||(LINESIZE>133)) ? (linesize=133) : (linesize=LINESIZE);
X  
X  pad = (linesize-72)/2+1;
X  for (i=0; i<pad; i++)
X    tab[i] = ' ';
X  tab[pad] = '\0';
X
X  work[0]='\n'; work[1]='\n'; work[2]='\0';
X  line = strcat(work,tab);
X  line = strcat(work,border);
X
X  cum_length += strlen(line);
X
X  if (cum_length < starbox_str_length)
X    strcat(starbox_str_pointer,line);
X  else 
X    return "Error, starbox, title too long.";
X
X  begin = title;
X  while ( (end=strchr(begin,terminator)) != NULL ) {
X    length = end - begin;
X    if (length > 68) return "Error, starbox, line too long.";
X    middle[0] = '*';
X    mpad = (68-length)/2+1;
X    for (i=1; i<=mpad; i++) middle[i] = ' ';
X    t = &middle[mpad];
X    while (begin < end) *t++ = *begin++;
X    begin++;
X    for (i=mpad+length; i<=68; i++) middle[i]=' ';
X    middle[69]='*'; middle[70]='\n'; middle[71]='\0';
X    work[0]='\0';
X    line = strcat(work,tab);
X    line = strcat(work,middle);
X
X
X    if (cum_length < starbox_str_length)
X      strcat(starbox_str_pointer,line);
X    else 
X      return "Error, starbox, title too long.";
X
X  }
X
X  work[0]='\0';
X  line = strcat(work,tab);
X  line = strcat(work,border);
X
X  if (cum_length < starbox_str_length)
X    strcat(starbox_str_pointer,line);
X  else 
X    return "Error, starbox, title too long.";
X
X  return starbox_str_pointer;
X
X}
X
X
X
END_OF_FILE
if test 2486 -ne `wc -c <'starbox.cc'`; then
    echo shar: \"'starbox.cc'\" unpacked with wrong size!
fi
# end of 'starbox.cc'
fi
if test -f 'status.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'status.h'\"
else
echo shar: Extracting \"'status.h'\" \(2046 characters\)
sed "s/^X//" >'status.h' <<'END_OF_FILE'
X/* ----------------------------------------------------------------------------
X
Xnlmdl: status.h
X
Xnlmdl is a C++ implementation of the statistical methods in A. Ronald 
XGallant, "Nonlinear Statistical Models," New York: John Wiley and Sons, 
X1987, ISBN 0-471-80260-3, using a matrix class realmat that is distributed 
Xwith it.  The header files nlmdl.h and realmat.h describe the use of the 
Xprogram and matrix class, respectively.  
X
XCopyright (C) 1990.
X
XA. Ronald Gallant
XP.O. Box 5513 
XRaleigh NC 27650-5513 
XUSA   
X
XPermission to use, copy, modify, and distribute this software and its 
Xdocumentation for any purpose and without fee is hereby granted, provided 
Xthat the above copyright notice appear in all copies and that both that 
Xcopyright notice and this permission notice appear in supporting 
Xdocumentation.  
X
XThis software is provided "as is" without any expressed or implied warranty.
X
X---------------------------------------------------------------------------- */
X/* status is a class used by nlmdl */
X
X#ifndef __FILE_STATUS_H_SEEN__
X#pragma once
X#define __FILE_STATUS_H_SEEN__ 1
X
X#include "usual.h"
X#include "realmat.h"
X#include "tools.h"
X
X
X
X#define MAX_STATUS_LINE    256
X#define STARTING_FILENAME  "starting.dat"
X#define ENDING_FILENAME    "ending.dat"
X
Xenum display_mode {START_UP, VAR_ITERATE, THETA_ITERATE, TERMINATION};
X
Xclass status 
X{
Xpublic:
X            status();
X            ~status();
X
X  char      switches[MAX_STATUS_LINE];
X  char      method[MAX_STATUS_LINE];
X  INTEGER   n;
X  INTEGER   M;
X  INTEGER   K;
X  INTEGER   p;
X  INTEGER   itheta;
X  INTEGER   ivar;
X  char      vartype[MAX_STATUS_LINE];
X  INTEGER   MA;
X  char      weights[MAX_STATUS_LINE];
X  REAL      tol;
X  REAL      eps;
X  char      detail[MAX_STATUS_LINE];
X  INTEGER   rank;
X  char      df[MAX_STATUS_LINE];
X  realmat   theta;
X  realmat   var;
X  realmat   V;
X  realmat   D;
X  REAL      obj;
X
X  char*     starting; 
X  char*     ending;
X
X  int       from(char* filename);
X  int       to(char* filename);
X  int       display(display_mode);
X
X};
X
X#endif
X
END_OF_FILE
if test 2046 -ne `wc -c <'status.h'`; then
    echo shar: \"'status.h'\" unpacked with wrong size!
fi
# end of 'status.h'
fi
if test -f 'tools.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'tools.h'\"
else
echo shar: Extracting \"'tools.h'\" \(290 characters\)
sed "s/^X//" >'tools.h' <<'END_OF_FILE'
X#ifndef __FILE_TOOLS_H_SEEN__
X#pragma once
X#define __FILE_TOOLS_H_SEEN__ 1
X
X#include "usual.h"
X
Xchar*    starbox(char *title, char terminator = '/');
X
Xvoid     dcond(REAL *a, INTEGER n, REAL *s, INTEGER isw);
XINTEGER  dsweep(REAL *a, INTEGER n, REAL eps);
X
X#endif /*__FILE_TOOLS_H_SEEN__*/
END_OF_FILE
if test 290 -ne `wc -c <'tools.h'`; then
    echo shar: \"'tools.h'\" unpacked with wrong size!
fi
# end of 'tools.h'
fi
if test -f 'usual.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'usual.h'\"
else
echo shar: Extracting \"'usual.h'\" \(3744 characters\)
sed "s/^X//" >'usual.h' <<'END_OF_FILE'
X#ifndef __FILE_USUAL_H_SEEN__
X#pragma once
X#define __FILE_USUAL_H_SEEN__ 1
X
X
X#undef    TURBO_CPP_COMPILER
X#define   GNU_GPP_COMPILER    1
X
X#define   USE_ATT_STYLE_IO_WITH_GNU  1 
X#undef    USE_GNU_STYLE_IO_WITH_GNU   
X
X
X/* -------------------------  References  ---------------------------------
X
XBjarne Stroustrup (1986), The C++ Programming Language. Reading Massachusetts: 
XAddison-Wesley Publishing Company.
X
X    Header files:
X
X    <complex.h>     p. 123, 173
X    <ctype.h>       p.  77, 237
X    <math.h>        p.  22, 115
X    <signal.h>      p. 126 
X    <stdargs.h>     p. 124
X    <stream.h>      p.  12, 226
X    <string.h>      p. 111
X    <vector.h>      p.  35
X
X
X
XKernigham, Brian W., and Dennis M. Ritchie (1988).  The C Programming Language, 
XSecond Edition.  Englewood Cliffs, New Jersey: Prentice Hall.
X
X
X    Appendix B. Standard Library
X
X    B1  Input and Output:                <stdio.h>                  p. 241
X    B2  Character Class Tests:           <ctype.h>                  p. 248
X    B3  String Functions:                <string.h>                 p. 249
X    B4  Mathematical Functions:          <math.h>                   p. 250
X    B5  Utility Functions:               <stdlib.h>                 p. 251
X    B6  Diagnostics                      <assert.h>                 p. 253
X    B7  Variable Argument Lists:         <stdarg.h>                 p. 254
X    B8  Non-Local Jumps                  <setjump.h>                p. 254
X    B9  Signals:                         <signal.h>                 p. 255
X    B10 Date and Time Functions          <time.h>                   p. 255
X    B11 Implementation-defined Limits:   <limits.h> and <float.h>   p. 257
X
X---------------------------------------------------------------------------*/
X
X/*--------------------------- g++ -------------------------------------------
X
XGNU's g++ follows Stroustrup.  These are the g++ equivalents together with 
Xtheir dependencies.
X
X<Complex.h>
X  <File.h> <builtin.h> <errno.h> <istream.h> <math.h> <math-68881.h>
X  <ostream.h> <std.h> <stddef.h> <stdio.h> <stream.h> <streambuf.h> 
X  <values.h>
X
X<ctype.h>
X  <stdio.h>
X
X<math.h>
X  <errno.h> <math-68881.h> <std.h> <stddef.h> <stdio.h> 
X
X<signal.h>
X  <sys/signal.h>
X
X<std.h>
X  <stdio.h> <stddef.h>
X
X<stream.h>
X  <File.h> <builtin.h> <errno.h> <istream.h> <math.h> <math-68881.h>  
X  <ostream.h> <std.h> <stddef.h> <stdio.h> <streambuf.h> <values.h>
X
X<string.h>
X  <std.h> <stddef.h> <stdio.h>
X
X<Vec.hP> & <Vec.ccP>
X  <stream.h>
X
XThe USE_ATT_STYLE_IO_WITH_GNU option uses the streambuf class which conforms 
Xto Chapter 8 of Stroustrup.  
X
XThe USE_GNU_STYLE_IO_WITH_GNU option uses the File class.  This is unreliable,
Xpiping sometimes corrupts I/O for example, but this is all there is on older
Xreleases of g++.
X
X----------------------------------------------------------------------------*/
X
X#ifdef GNU_GPP_COMPILER
X#include <stream.h>
X#endif 
X
X
X/*---------------------------- Turbo C++ ------------------------------------
X
XTurbo C++ uses a tiresome mixture of ANSI C headers and Stroustrup headers.  
XSee page 155 of the Turbo C++ Programmers Guide for a description.
X
X----------------------------------------------------------------------------*/ 
X
X#ifdef TURBO_CPP_COMPILER
X#include <iostreams.h>
X#include <fstream.h>
X#include <stdio.h>
X#include <string.h>
X#include <math.h>
X#include <stdlib.h>
X#endif  
X
X#define LINESIZE  80         // define linesize for output routines
X
Xtypedef long int  INTEGER;   // define precision of integer arithmetic
Xtypedef double    REAL;      // define precision of floating point arithmetic
X
Xtypedef void (*ONE_ARG_ERROR_HANDLER_T)(const char*);              
Xtypedef void (*TWO_ARG_ERROR_HANDLER_T)(const char*, const char*);
X
X#endif /*__FILE_USUAL_H_SEEN__*/
END_OF_FILE
if test 3744 -ne `wc -c <'usual.h'`; then
    echo shar: \"'usual.h'\" unpacked with wrong size!
fi
# end of 'usual.h'
fi
echo shar: End of archive 1 \(of 6\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 6 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 6 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0



More information about the Alt.sources mailing list