Programming: Programming with LIMDEP & NLOGIT
Command Language
LIMDEP and NLOGIT’s command language may be used to write routines and programs for:
- New estimators
- Test statistics
- Manipulate model results
- Standardize groups of calculations
- Simulate model and estimator behavior
Features of the Programming Language
The programming language includes:
- All model estimation commands
- Computational tools
- Matrix algebra - subscripting in matrices
- Scalar scientific calculator
- Variable transformations and creating new variables
- Control statements and looping
- Procedures with adjustable parameters (subroutines)
- PROCEDURE (argument, ..., ...)
- EXECUTE procedure
- Bootstrapping
- Repeated execution of procedures
- Libraries of procedures
Numerical Analysis Tools
Numerical analysis tools are provided for analyzing functions of a variable and functions of the data:
- Function evaluation
- Function plotting
- Compute derivatives and save as gradient vector
- Integration by quadrature
- Integration by trapezoids
- Integration by simulation
- Matrix algebra
- Characteristic roots
- Roots of dynamic equations
- Character vectors
- Singular value decomposition
- Scientific calculator: dozens of functions
- Values of and asymptotic variances for nonlinear functions
Example: Poisson Model with a Fixed Value Restriction
The following is an iterative procedure to fit a Poisson regression while constraining one of the parameters to equal one (used when the ‘exposure’ period differs by observation).
?===================================================================== ? Set up the matrix procedure. We strip off the last element of ? b to obtain the vector beta. delta is the update vector, ? initialized at 0, so the first iteration uses the starting values. ?===================================================================== NAMELIST ; x = one,a,c,d,e,c67,c72,c77,p77 $ POISSON ; Lhs = num ; Rhs = x,logmth $ MATRIX ; beta = B(1:9) ; delta = [9|0] $ CALC ; conv = 1 $ ?===================================================================== ? 1. Update beta. ? 2. Compute expected values and residuals, imposing constraint ? on slope on log(months)=1. ? 3. Iterate using Newton's method ? Exit rule, conv must be initialized above because it is checked ? at entry to the iteration, not at exit. ?===================================================================== PROCEDURE MATRIX ; beta = beta - delta $ update coefficient vector CREATE ; ey = Exp(x'beta + logmth) ; uy = ey - num $ MATRIX ; g = x'uy ? first derivatives vector ; h = ? negative of 2nd derivatives ; delta = h * g $ update vector CALC ; List ; conv = g'delta $ convergence measure ENDPROCEDURE ?===================================================================== ? Execute procedure until convergence, then display final results. ?===================================================================== EXECUTE ; until conv < .00001 $ MATRIX ; Stat(beta,h,X) $ This program produces the following listing prior to the statistical output: CONV = .84415590973720680D+03 CONV = .16345624762698120D+03 CONV = .12305922124358570D+02 CONV = .11423883549203680D+00 CONV = .13468418817524850D-04 CONV = .25224428518082010D-12 CONV < .00001