Programming and Numerical Analysis:
Programming with LIMDEP
LIMDEP’s command language may be used to write routines and programs for:
- New estimators
- Test statistics
- Manipulate model results
- Standardize groups of calculations
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
- GO TO / Label
- DO WHILE
- DO UNTIL
- DO FOR values of control variable
- Nested loops
- Procedures with adjustable parameters (subroutines)
- PROCEDURE (argument, ..., ...)
- EXECUTE procedure
- Bootstrap
- Looping and repeated execution of procedures
- EXECUTE until condition is met
- End execution if condition is met
- Libraries of procedures
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