## Stata 15 help for forecast solve

```
[TS] forecast solve -- Obtain static and dynamic forecasts

Syntax

forecast solve [, { prefix(stub) | suffix(stub) } options]

options                     Description
-------------------------------------------------------------------------
Model
* prefix(string)            specify prefix for forecast variables
* suffix(string)            specify suffix for forecast variables
begin(time_constant)      specify period to begin forecasting
+ end(time_constant)        specify period to end forecasting
+ periods(#)                specify number of periods to forecast
double                    store forecast variables as doubles instead
of as floats
static                    produce static forecasts instead of dynamic
forecasts
actuals                   use actual values if available instead of
forecasts

Simulation
simulate(sim_technique, sim_statistic sim_options)
specify simulation technique and options

Reporting
log(log_level)            specify level of logging display; log_level
may be detail, on, brief, or off

Solver
vtolerance(#)             specify tolerance for forecast values
ztolerance(#)             specify tolerance for function zero
iterate(#)                specify maximum number of iterations
technique(technique)      specify solution method; may be
dampedgaussseidel #, gaussseidel,
broydenpowell, or newtonraphson
-------------------------------------------------------------------------
* You can specify prefix() or suffix() but not both.
+ You can specify end() or periods() but not both.

sim_technique               Description
-------------------------------------------------------------------------
betas                       draw multivariate-normal parameter vectors
errors                      draw additive errors from multivariate normal
distribution
residuals                   draw additive residuals based on static
forecast errors
-------------------------------------------------------------------------
You can specify one or two sim_methods separated by a space, though you
cannot specify both errors and residuals.

sim_statistic is

statistic(statistic, {prefix(string) | suffix(string)})

and may be repeated up to three times.

statistic                   Description
-------------------------------------------------------------------------
mean                        record the mean of the simulation forecasts
variance                    record the variance of the simulation
forecasts
stddev                      record the standard deviation of the
simulation forecasts
-------------------------------------------------------------------------

sim_options                 Description
-------------------------------------------------------------------------
saving(filename, ...)       save results to file; save statistics in
double precision; save results to filename
every # replications
nodots                      suppress replication dots
reps(#)                     perform # replications; default is reps(50)
-------------------------------------------------------------------------

Description

forecast solve computes static or dynamic forecasts based on the model
currently in memory.  Before you can solve a model, you must first create
a new model using forecast create and add equations and variables to it
using the commands summarized in [TS] forecast.

Options

+-------+
----+ Model +------------------------------------------------------------

prefix(string) and suffix(string) specify a name prefix or suffix that
will be used to name the variables holding the forecast values of the
variables in the model.  You may specify prefix() or suffix() but not
both.  Sometimes, it is more convenient to have all forecast
it is more convenient to have all forecast variables end with the
same set of characters.

If you specify prefix(f_), then the forecast values of endogenous
variables x, y, and z will be stored in new variables f_x, f_y, and
f_z.

If you specify suffix(_g), then the forecast values of endogenous
variables x, y, and z will be stored in new variables x_g, y_g, and
z_g.

begin(time_constant) requests that forecast begin forecasting at period
time_constant.  By default, forecast determines when to begin
forecasting automatically.

end(time_constant) requests that forecast end forecasting at period
time_constant.  By default, forecast produces forecasts for all
periods on or after begin() in the dataset.

periods(#) specifies the number of periods after begin() to forecast.  By
default, forecast produces forecasts for all periods on or after
begin() in the dataset.

double requests that the forecast and simulation variables be stored in
double precision.  The default is to use single-precision floats.

static requests that static forecasts be produced.  Actual values of
variables are used wherever lagged values of the endogenous variables
appear in the model.  By default, dynamic forecasts are produced,
which use the forecast values of variables wherever lagged values of
the endogenous variables appear in the model.  Static forecasts are

actuals specifies how nonmissing values of endogenous variables in the
forecast horizon are treated.  By default, nonmissing values are
ignored, and forecasts are produced for all endogenous variables.
When you specify actuals, forecast sets the forecast values equal to
the actual values if they are nonmissing.  The forecasts for the
other endogenous variables are then conditional on the known values
of the endogenous variables with nonmissing data.

+------------+
----+ Simulation +-------------------------------------------------------

simulate(sim_technique, sim_statistic sim_options) allows you to simulate
your model to obtain measures of uncertainty surrounding the point
forecasts produced by the model.  Simulating a model involves
repeatedly solving the model, each time accounting for the
uncertainty associated with the error terms and the estimated
coefficient vectors.

sim_technique can be betas, errors, or residuals, or you can specify
both betas and one of errors or residuals separated by a space.
You cannot specify both errors and residuals.  The sim_technique
controls how uncertainty is introduced into the model.

sim_statistic specifies a summary statistic to summarize the
forecasts over all the simulations.  sim_statistic takes the form

statistic(statistic, {prefix(string) | suffix(string)})

where statistic may be mean, variance, or stddev.  You may
specify either the prefix or the suffix that will be used to name
the variables that will contain the requested statistic.  You may
specify up to three sim_statistics, allowing you to track the
mean, variance, and standard deviations of your forecasts.

sim_options include saving(filename, [suboptions]), nodots, and
reps(#).

saving(filename, [suboptions]) creates a Stata data file (.dta
file) consisting of (for each endogenous variable in the
model) a variable containing the simulated values.

double specifies that the results for each replication be
saved as doubles, meaning 8-byte reals.  By default, they are
saved as floats, meaning 4-byte reals.

replace specifies that filename be overwritten if it exists.

every(#) specifies that results be written to disk every #th
replication.  every() should be specified only in conjunction
with saving() when the command takes a long time for each
replication.  This will allow recovery of partial results
should some other software crash your computer.  See [P]
postfile.

nodots suppresses display of the replication dots.  By default,
one dot character is displayed for each successful
replication.  If during a replication convergence is not
achieved, forecast solve exits with an error message.

reps(#) requests that forecast solve perform # replications; the
default is reps(50).

+-----------+
----+ Reporting +--------------------------------------------------------

log(log_level) specifies the level of logging provided while solving the
model.  log_level may be detail, on, brief, or off.

values of the convergence criteria for each period in each panel (in
the case of panel data) for which the model is being solved.

log(on), the default, provides an iteration log showing the current
panel and period for which the model is being solved as well as a
sequence of dots for each period indicating the number of iterations.

log(brief), when used with a time-series dataset, is equivalent to
log(on).  When used with a panel dataset, log(brief) produces an
iteration log showing the current panel being solved but does not
show which period within the current panel is being solved.

log(off) requests that no iteration log be produced.

+--------+
----+ Solver +-----------------------------------------------------------

vtolerance(#), ztolerance(#), and iterate(#) control when the solver of
the system of equations stops.  ztolerance() is ignored if either
technique(dampedgaussseidel #) or technique(gaussseidel) is
specified.  These options are seldom used.  See [M-5] solvenl().

technique(technique) specifies the technique to use to solve the system
of equations.  technique may be dampedgaussseidel #, gaussseidel,
broydenpowell, or newtonraphson, where 0 < # < 1 specifies the amount
of damping with smaller numbers indicating less damping.  The default
is technique(dampedgaussseidel 0.2), which works well in most
situations.  If you have convergence issues, first try continuing to
use dampedgaussseidel # but with a larger damping factor.  Techniques
broydenpowell and newtonraphson usually work well, but because they
require the computation of numerical derivatives, they tend to be
much slower.  See [M-5] solvenl().

Examples

---------------------------------------------------------------------------
Setup
. webuse gdpoil

Fit the VAR model and store the estimation results
. var gdp oil, lags(1 2)
. estimates store var

Extend the dataset three years to 2010

Create a forecast model and obtain baseline forecasts
. forecast create oilmodel
. forecast estimates var
. forecast solve, prefix(bl_)

Fill in oil with our hypothesized price path
. replace oil = 10 if qdate == tq(2008q1)
. replace oil = 10 if qdate == tq(2008q2)
. replace oil = 10 if qdate == tq(2008q3)
. replace oil = 0 if qdate > tq(2008q3)

Obtain forecasts conditional on the oil variable, using the prefix alt_
for these forecast variables
. forecast solve, prefix(alt_) actuals

---------------------------------------------------------------------------
Setup
. clear all
. webuse klein2
. reg3 (c p L.p w) (i p L.p L.k) (wp y L.y yr), endog(w p y) exog(t
wg g)
. estimates store klein
. forecast create kleinmodel
. forecast estimates klein
. forecast identity y = c + i + g
. forecast identity p = y - t - wp
. forecast identity k = L.k + i
. forecast identity w = wg + wp
. forecast exogenous wg
. forecast exogenous g
. forecast exogenous t
. forecast exogenous yr

Set the random-number seed so the results can be replicated
. set seed 1

Solve the model, using the prefix d_ for the forecast variables and the
prefix sd_ for the standard deviations of the forecasts
. forecast solve, prefix(d_) begin(1936) simulate(betas,
statistic(stddev, prefix(sd_)) reps(100))

---------------------------------------------------------------------------

Stored results

forecast solve stores the following in r():

Scalars
r(first_obs)        first observation in forecast horizon
r(last_obs)         last observation in forecast horizon (of first
panel if forecasting panel data)
r(Npanels)          number of panels forecast
r(Nvar)             number of forecast variables
r(vtolerance)       tolerance for forecast values
r(ztolerance)       tolerance for function zero
r(iterate)          maximum number of iterations
r(sim_nreps)        number of simulations
r(damping)          damping parameter for damped Gauss-Seidel

Macros
r(prefix)           forecast variable prefix
r(suffix)           forecast variable suffix
r(actuals)          actuals, if specified
r(static)           static, if specified
r(double)           double, if specified
r(sim_technique)    specified sim_technique
r(logtype)          on, off, brief, or detail

```