RATS 11
RATS 11

Instructions /

KALMAN Instruction

Home Page

← Previous Next →

KALMAN( options )

KALMAN executes one step of the Kalman filter algorithm on a system of equations that you have set up with SYSTEM. In its simplest use, it does sequential updating of coefficient estimates.

 

KALMAN is used specifically to estimate the coefficients of a system of linear equations over time. The instruction DLM is a more general instruction which can apply the Kalman filter in a wider range of settings.

 

The KFSET (Kalman Filter SETup) and TVARYING (time varying) subcommands of SYSTEM can be used to set information that is used by the Kalman filter to relax the assumptions used for simple coefficient updates.

 

The design of KALMAN has changed over the years with parameters replaced by easier-to-use options. The older parameters are still supported and are described at the end.

Options

PRINT/[NOPRINT]

FTESTS/[NOFTESTS]

These control the printing of the regression and F test output. The defaults are NOPRINT and NOFTESTS. If you want to display output based on the value of a conditional expression, you can use something like PRINT=(TIME==MYEND), which will show the output only when the variable TIME is equal to MYEND.

 

STARTUP=entry number or date [unused]

When you start the Kalman filter without an ESTIMATE, the first KALMAN instruction should include this option. KALMAN instructions thereafter will recompute coefficients given the next observation.

 

RTYPE=[ALL]/CURRENT/ONESTEP/RECURSIVE

This option allows you to specify how you want the residuals series filled.

 

ALL

all entries using the updated coefficient estimates.

CURRENT

just the current entry, using the updated coefficients.

ONESTEP

just the current entry, using the previous coefficients.

RECURSIVE

recursive residual, just the current entry

 

BACKWARDS/[NOBACK]

With the BACKWARDS option, the filter operates backwards for this update, adding an observation to the beginning of the sample rather than to the end. KALMAN replaces the lags in the equation with leads, and vice versa.

 

DROP=entry number or date [unused]

ADD=entry number or date [unused]

Use DROP and ADD either to drop an observation from the sample or add one. You can use DROP along with the TEMP and CHANGE options (below) to see the effect upon the coefficients of dropping a single observation.

 

RESIDUALS=VECTOR[SERIES] for residuals

This is the most convenient way to get the residuals from the equations of a VAR or other multiple equation system. The option RESIDUALS=RESVAR will create series RESVAR(1),...,RESVAR(n) which will have the residuals from the n equations in the system.

 

COEFFS=RECTANGULAR for coefficients

For a VAR, this saves the current estimated coefficients in a RECTANGULAR array. Column i of this will be the coefficients from the ith equation.

 

COHISTORY=VECTOR[SERIES] for coefficient history

This can only be used with a single equation model. There will be one series in the VECTOR[SERIES] for each coefficient. KALMAN will put its estimates into the current period in these series.

 

SMPL=SMPL series or formula[unused].

You can supply a series or a formula that can be evaluated across entry numbers. Entries for which the series or formula is zero or “false” will be skipped, while entries that are non-zero or “true” will be included in the operation.

 

TITLE="title for output" [none]

This option allows you to supply your own title to label the resulting output.

 

TEMP/[NOTEMP]

CHANGE=(output) VECTOR for coefficient changes [unused]

TEMP causes KALMAN to compute the new coefficients and (optionally) residuals, then discards the results, leaving the filter in the same state as it was before the KALMAN instruction. Use CHANGE with or without TEMP to save the change in the coefficient vector of a one equation system.

 

DISCOUNT=discount value [not used]

This allows for multiplicative (rather than additive) changes to the variance of the states. The update for the covariance matrix takes the form:

 

\({\Sigma _{\left. {t\,} \right|t - 1}} = {{\bf{A}}_t}{\Sigma _{\left. {t - 1{\kern 1pt} } \right|t - 1}}{{\bf{A'}}_t}\frac{1}{{discount}}\)

 

X=VECTOR of explanatory variables for dummy observation

Y=VECTOR of dependent variables for dummy observation

V=VECTOR of equation variance (for a dummy or regular Kalman filter observation)

These are used to implement “dummy observation priors” for a vector autoregression. These take the form Y=XB+v

where B is the matrix of VAR coefficients. KALMAN updates the coefficients, but does not alter the likelihood vector and does not change the entry pointer.

The V vector gives the variances of v; if you don’t include it, the equation variances provided on the KFSET are used. If you do not use Y, the Kalman filter error is taken to be zero, so the coefficients don’t change; only the covariance matrix of the coefficients.

 

Dummy observation priors are described in greater detail in Sims (1993).

Coefficient Updating

To use the Kalman filter for coefficient updates, define the system using the SYSTEM and related instructions, and then use ESTIMATE to initialize the Kalman filter, computing estimates over some subset of the data range. Each KALMAN instruction thereafter will add a single observation to the end of the data set.

Variables Defined

%XX

inverse(X'X) matrix (SYMMETRIC)

%NREG

number of regressors in first equation (INTEGER)

Examples

system(model=yrmp)

variables gdp cpr ipd m1

lags 1 to 4

det constant

end(system)

estimate  1948:1 2007:4

do  time=2008:1,2013:4

  kalman(print=(time==2013:4))

end do

 

ESTIMATE computes the regressions through 2007:4 and prints them with the F-tests. The loop then executes KALMAN twenty-four times (quarterly data) so that the last produces estimates using data through 2013:4. This only prints the estimates for this final period because the argument for PRINT will be zero until TIME is 2013:4.


 

 

equation kfeq y

# constant x1 x2 x3

system kfeq

end(system)

estimate(cohistory=cokalman) 1 25

do entry=26,200

   kalman(cohistory=cokalman)

end do entry

 

This Kalman filters a single equation over the period 26 to 200 and saves time series of the coefficients in series COKALMAN(1),...,COKALMAN(4).

Older Syntax (with parameters)

KALMAN( options )  residuals coeffs printflag testflag

Parameters

residuals, coeffs

first series in a block of series for the residuals and coefficients, respectively (use VECTORS of SERIES or numbered series). The new RESIDUALS and COEFFS options are generally more convenient for saving these values.

printflag, testflag

KALMAN prints output and F-tests (respectively) when these are equal to 1 (usually set with logical expressions). These override the NOPRINT and NOFTESTS options.

 


Copyright © 2025 Thomas A. Doan