Thursday, April 9, 2026

A tip to debug your nl/nlsur operate evaluator program


When you’ve got a bug in your evaluator program, nl will produce, likely, the next error:

your program returned 198
confirm that your program is a operate evaluator program
r(198);

The error signifies that your program can’t be evaluated.

The easiest way to identify any points in your evaluator program is to run it interactively. You simply must outline your pattern (often observations the place not one of the variables are lacking), and a matrix with values on your parameters. Let me present you an instance with nlces2. That is the code to suit the CES manufacturing operate, from the documentation for the nl command:


cscript
program nlces2
model 12
syntax varlist(min=3 max=3) if, at(identify)
native logout : phrase 1 of `varlist'
native capital : phrase 2 of `varlist'
native labor : phrase 3 of `varlist'
// Retrieve parameters out of at matrix
tempname b0 rho delta
scalar `b0' = `at'[1, 1]
scalar `rho' = `at'[1, 2]
scalar `delta' = `at'[1, 3]
tempvar kterm lterm
generate double `kterm' = `delta'*`capital'^(-1*`rho') `if'
generate double `lterm' = (1-`delta')*`labor'^(-1*`rho') `if'
// Fill in dependent variable
substitute `logout' = `b0' - 1/`rho'*ln(`kterm' + `lterm') `if'
finish

webuse manufacturing, clear
nl ces2 @ lnoutput capital labor, parameters(b0 rho delta) ///
               preliminary(b0 0 rho 1 delta 0.5)

Now, let me present you the best way to run it interactively:


webuse manufacturing, clear
*generate a variable to limit my pattern to observations
*with non-missing values in my variables
egen u = rowmiss(lnoutput capital labor)

*generate a matrix with parameters the place I'll consider my operate
mat M = (0,1,.5)
gen nloutput_new = 1 
nlces2 nloutput_new capital labor if u==0, at(M)  

This may consider this system solely as soon as, utilizing the parameters in matrix M. Discover that I generated a brand new variable to make use of as my dependent variable. It’s because this system nlces2, when run by itself, will modify the dependent variable.
If you run this program by itself, you’ll get hold of a extra particular error message. You may add debugging code to this program, and you can even use the hint setting to see how every step is executed. Sort assist hint to study this setting.

One other potential supply of error (which can generate error r(480) when run from nl) is when an evaluator operate produces lacking values for observations within the pattern. If so, you will note these lacking values within the variable nloutput_new, i.e., within the variable you entered as dependent when operating your evaluator by itself. You may then add debugging code, for instance, utilizing codebook or summarize to look at the completely different components that contribute to the substitution carried out within the dependent variable.

For instance, after the road that generates `kterm’, I may write

summarize `kterm' if u == 0

to see if this variable accommodates any lacking values in my pattern.

This technique may also be used to debug your operate evaluator packages for nlsur. In an effort to protect your dataset, it is advisable use copies for all of the dependent variables in your mannequin.



Related Articles

Latest Articles