NLLS Instruction |
NLLS(options) depvar start end residuals
NLLS estimates \(\theta\) in the non-linear least squares model
(1) \({y_t} = f\left( {{{\bf{X}}_t},\theta } \right) + {u_t}\)
Before you can use it, you must:
•Set the list of free parameters using NONLIN
•Create the explanatory formula f using FRML
•Set initial values for the parameters (usually with COMPUTE or INPUT)
Parameters
depvar |
the dependent variable. You can use an asterisk (*) for this parameter if the model is \(f\left( {{{\bf{X}}_t},\theta } \right) = {u_t}\) so there is no “dependent variable.” If you use *, the regression output will exclude \(R^2\) and similar summary statistics. |
start, end |
range over which to estimate, defaults to the maximum range over which the residuals can be computed, and the instruments are defined (if you are doing instrumental variables). |
residuals |
(optional) Series for the residuals at the final estimates. |
Options
FRML=formula name (required)
Name of the formula for the function f.
PARMSET=PARMSET to use [default internal]
This option selects the PARMSET (parameter set) to be estimated. RATS maintains a single unnamed parameter set which is the one used for estimation if you don’t use PARMSET to specify a named set.
METHOD=[GAUSS]/SIMPLEX/GENETIC/ANNEALING/GA/EVALUATE
METHOD sets the estimation method to be used. The default (GAUSS) is Gauss–Newton, which requires that the formula be twice continuously differentiable and is the only choice that can compute standard errors. The others make weaker assumptions, and can compute point estimates only—they are more often used as a PMETHOD to refine initial guesses before using Gauss–Newton to finish the estimation.
EVALUATE simply evaluates the formula given the initial parameter values and produces no output.
ITERATIONS=iteration limit [100]
SUBITERATIONS=subiteration limit [30]
CVCRIT=convergence limit [.00001]
TRACE/[NOTRACE]
ITERATIONS sets the maximum number of iterations, SUBITERS sets the maximum number of subiterations, CVCRIT the convergence criterion. TRACE prints the intermediate results. For METHOD=SIMPLEX, an “iteration” is actually defined as K vertex changes, where K is the number of free parameters. This makes the number of calculations per “iteration” similar to the other methods.
PMETHOD=[GAUSS]/SIMPLEX/GENETIC/ANNEALING/GA
PITERS=number of PMETHOD iterations to perform [0]
Use PMETHOD and PITERS if you want to do preliminary iterations using one method, and then switch to another method for final estimates. For example, to do 10 simplex iterations before switching to Gauss-Newton, you can use the options PMETHOD=SIMPLEX, PITERS=10, and METHOD=GAUSS.
STARTUP=FRML evaluated at period "start"
ONLYIF=expression tested before calculating start option [not used]
You can use the START option to provide an expression which is computed once per function evaluation, before any of the regular formulas are computed. This allows you to do any time-consuming calculations that depend upon the parameters, but not upon time. It can be an expression of any type. ONLYIF calculates the expression provided; if it evaluates to a zero value, the function evaluation doesn’t continue, and the function is assigned the missing value. ONLYIF is examined before doing START, unlike REJECT (below), which is done after the START.
REJECT=FRML indicating a “rejection” zone for the parameters
If the FRML evaluates to a non-zero (“true”) value, the function is immediately assigned the missing value.
SMPL=Standard SMPL option [unused]
WEIGHT=series of weights for the data points
These are the standard options for skipping data points or reweighting observations.
[PRINT]/NOPRINT
VCV/[NOVCV]
TITLE="title for output" [“Nonlinear Least Squares” or “Nonlinear Instrumental Variables”]
These are the standard output control options.
DERIVES=(output) VECTOR[SERIES] for partial derivatives
This saves the series of partial derivatives of the residuals. The first series in the VECTOR will be the partials with respect to the first parameter displayed in the NLLS output, the second series will be the partials with respect to the second parameter, and so on.
Options for Non-Linear Least Squares
SPREAD=residual variance series/formula
SV=residual variance formula
Use one of these for weighted least squares. The difference is that SPREAD is used when the variances don’t depend upon the parameters (so simple weighted least squares can be used) and SV is used when they do (requiring maximum likelihood to account for log variance terms). The residual variances are assumed to be proportional to the given series.
JACOBIAN=FRML for the Jacobian
This option allows you to specify a FRML for the determinant of the Jacobian, for doing full-information maximum likelihood.
ROBUSTERRORS/[NOROBUSTERRORS]
LAGS=correlated lags [0]
LWINDOW=NEWEYWEST/BARTLETT/DAMPED/PARZEN/QUADRATIC/[FLAT]/PANEL/WHITE
LWFORM=VECTOR with the window form [not used]
CLUSTER=series with category values for clustered standard errors [not used]
DAMP=value of \(\gamma\) for LWINDOW=DAMPED [0.0]
When used without the INSTRUMENTS option, these permit calculation of a consistent covariance matrix allowing for heteroscedasticity (with ROBUSTERRORS) or serial correlation (with LAGS), or clustering based upon some other set of categories.
Options for Instrumental Variables
INSTRUMENTS/[NOINSTRUMENTS]
Use the INSTRUMENTS option to do two-stage least squares or GMM. You must set your instruments list first using the instruction INSTRUMENTS.
WMATRIX=weighting matrix [\({\left( {{\bf{Z'Z}}} \right)^{ - 1}}\)]
IWMATRIX=inverse weighting matrix [not used]
OPTIMALWEIGHTS/[NOOPTIMALWEIGHTS]
UPDATE=NONE/ONCE/CONTINUOUS
This controls the updating of the weighting matrix. You can directly input a weight matrix with the WMATRIX or IWMATRIX option. If you don’t, the weight matrix is initialized as the \({\left( {{\bf{Z'Z}}} \right)^{ - 1}}\) matrix which gives two-stage least squares. If you use OPTIMALWEIGHTS or UPDATE=CONTINUOUS (they’re synonyms), the weight matrices are recomputed after every iteration using the next group of options.
[ZUDEP]/NOZUDEP
LAGS=correlated lags [0]
LWINDOW=NEWEYWEST/BARTLETT/DAMPED/PARZEN/QUADRATIC/[FLAT]/PANEL/WHITE
DAMP=value of \(\gamma\) for LWINDOW=DAMPED [0.0]
LWFORM=VECTOR with the lag window form [not used]
CLUSTER=SERIES with category values for clustered calculation
Use these to select the type of correlation assumed for the \({\bf{Z'u}}\) process. Note that the default for the ZUDEP (ZU Dependence) option is different from the NLSYSTEM instruction.
ZUMEAN=VECTOR of means of moment conditions [zeros]
This allows you to supply a VECTOR (with dimensions equal to the number of instruments) with a set of known (non-zero) means for \(E\left( {{\bf{Z'u}}} \right)\). By default, RATS sets these to zero.
CENTER/[NOCENTER]
CENTER adjusts the formula for the weight matrix to subtract off the (sample) means of \({\bf{Z'u}}\), which may be non-zero for an overidentified model.
JROBUST=STATISTIC/[DISTRIBUTION]
You can use this option to adjust the J-statistic specification test when the weighting matrix used is not the optimal one.
Hypothesis tests
You can test hypotheses on the coefficients with TEST, RESTRICT and MRESTRICT and can use the Statistics—Regression Tests wizard to set those up. RATS numbers the coefficients based on their positions in the list set up by NONLIN. You may not use EXCLUDE after NLLS and can use SUMMARIZE only to expand an expression.
The hypothesis tests are based upon a quadratic approximation to the sum of squares surface at the final estimates. This is a “Wald” test.
Missing Values
RATS drops any entries which it can’t compute because of missing values. If you have a recursive formula (that is, the value for entry T relies upon some quantity computed at T-1, then you have to be careful about the choice of start and end. You can’t let RATS determine the default range because it will simply start at entry one (which generally isn’t computable), and will never find, by itself, the correct place to begin.
Variables Defined (for all)
%BETA |
coefficient VECTOR |
%CONVERGED |
=1 or 0. 1 indicates that the process converged (INTEGER) |
%CVCRIT |
final convergence criterion (REAL). This will be equal to zero if the sub-iteration limit was reached on the last iteration. |
%DURBIN |
Durbin-Watson statistic (REAL) |
%FUNCVAL |
final value of the function being optimized (REAL) |
%ITERS |
iterations completed (INTEGER) |
%LAGRANGE |
VECTOR of Lagrange multipliers if estimating with constraints |
%MEAN |
mean of dependent variable (REAL) |
%NDF |
number of degrees of freedom (INTEGER) |
%NFREE |
number of free parameters (INTEGER) |
%NOBS |
number of observations (INTEGER) |
%NREG |
number of regressors (INTEGER) |
%RESIDS |
SERIES containing the residuals |
%RHO |
first lag correlation coefficient (REAL) |
%RSS |
residual sum of squares (REAL) |
%SEESQ |
standard error of estimate squared (REAL) |
%SIGMASQ |
maximum likelihood variance estimate (REAL) |
%STDERRS |
VECTOR of coefficient standard errors |
%TSTATS |
VECTOR containing the t-stats for the coefficients |
%VARIANCE |
variance of dependent variable (REAL) |
%XX |
\({\left( {{\bf{X'X}}} \right)^{ - 1}}\) or similar where appropriate, otherwise the covariance matrix of coefficients (SYMMETRIC) |
Variables Defined (for Non-Linear Least Squares)
%LOGL |
normal log likelihood (REAL) |
%RBARSQ |
R-bar-squared (REAL) |
%RSQUARED |
R-squared (REAL) |
%TRSQ |
number of observations times raw R-squared (REAL) |
%TRSQUARED |
number of observations times the centered R-squared (REAL) |
Variables Defined (for Instrumental Variables)
%JSTAT |
test statistics for overidentification (for instrumental variables regressions) (REAL) |
%JSIGNIF |
significance level of %JSTAT (REAL) |
%NDFJ |
degrees of freedom for %JSTAT (INTEGER) |
%UZWZU |
\({\bf{u'}}{\kern 1pt} {\bf{Z}}{\kern 1pt} {\bf{W}}{\kern 1pt} {\bf{Z'u}}\) (REAL) |
%WMATRIX |
final weight matrix for GMM (SYMMETRIC) |
Examples
nonlin lgamma delta nu rho
frml ces = lgamma-nu/rho* $
log( delta * k^(-rho) + (1.-delta) * l^(-rho) )
compute lgamma=1.0, delta=0.4, nu=0.8, rho=.6
nlls(frml=ces,trace) q
nonlin a b g
linreg realcons
# constant realdpi
compute a=%beta(1),b=%beta(2),g=1
frml cfrml realcons = a+b*realdpi^g
instruments constant realcons{1} realdpi{1 2}
nlls(frml=cfrml,inst) realcons 1950:3 *
Copyright © 2025 Thomas A. Doan