Codigos para STATA
Codigos para STATA
Codigos para STATA
com
arima postestimation — Postestimation tools for arima
Postestimation commands
The following postestimation commands are of special interest after arima:
Command Description
estat acplot estimate autocorrelations and autocovariances
estat aroots check stability condition of estimates
irf create and analyze IRFs
psdensity estimate the spectral density
1
2 arima postestimation — Postestimation tools for arima
predict
statistic Description
Main
xb predicted values for mean equation—the differenced series; the default
stdp standard error of the linear prediction
y predicted values for the mean equation in y —the undifferenced series
mse mean squared error of the predicted values
residuals residuals or predicted innovations
yresiduals residuals or predicted innovations in y , reversing any time-series operators
These statistics are available both in and out of sample; type predict . . . if e(sample) . . . if wanted only for
the estimation sample.
Predictions are not available for conditional ARIMA models fit to panel data.
options Description
Options
dynamic(time constant) how to handle the lags of yt
t0(time constant) set starting point for the recursions to time constant
structural calculate considering the structural component only
time constant is a # or a time literal, such as td(1jan1995) or tq(1995q1); see
Conveniently typing SIF values in [D] Datetime.
often called a one-step prediction), or we can use the data up to a particular time, after which the
predicted value of the dependent variable is used recursively to make later predictions (dynamic()).
Either way, we can consider or ignore the ARMA disturbance component (the component is considered
by default and is ignored if you specify structural).
All calculations can be made in or out of sample.
Main
xb, the default, calculates the predictions from the model. If D.depvar is the dependent variable,
these predictions are of D.depvar and not of depvar itself.
stdp calculates the standard error of the linear prediction xb. stdp does not include the variation
arising from the disturbance equation; use mse to calculate standard errors and confidence bands
around the predicted values.
y specifies that predictions of depvar be made, even if the model was specified in terms of, say,
D.depvar.
mse calculates the MSE of the predictions.
residuals calculates the residuals. If no other options are specified, these are the predicted innovations
t ; that is, they include the ARMA component. If structural is specified, these are the residuals
µt from the structural equation; see structural below.
yresiduals calculates the residuals in terms of depvar, even if the model was specified in terms of,
say, D.depvar. As with residuals, the yresiduals are computed from the model, including any
ARMA component. If structural is specified, any ARMA component is ignored, and yresiduals
are the residuals from the structural equation; see structural below.
Options
dynamic(time constant) specifies how lags of yt in the model are to be handled. If dynamic() is
not specified, actual values are used everywhere that lagged values of yt appear in the model to
produce one-step-ahead forecasts.
dynamic(time constant) produces dynamic (also known as recursive) forecasts. time constant
specifies when the forecast is to switch from one step ahead to dynamic. In dynamic forecasts,
references to yt evaluate to the prediction of yt for all periods at or after time constant; they
evaluate to the actual value of yt for all prior periods.
For example, dynamic(10) would calculate predictions in which any reference to yt with t < 10
evaluates to the actual value of yt and any reference to yt with t ≥ 10 evaluates to the prediction of
yt . This means that one-step-ahead predictions are calculated for t < 10 and dynamic predictions
thereafter. Depending on the lag structure of the model, the dynamic predictions might still refer
some actual values of yt .
You may also specify dynamic(.) to have predict automatically switch from one-step-ahead to
dynamic predictions at p + q , where p is the maximum AR lag and q is the maximum MA lag.
t0(time constant) specifies the starting point for the recursions to compute the predicted statistics;
disturbances are assumed to be 0 for t < t0(). The default is to set t0() to the minimum t
observed in the estimation sample, meaning that observations before that are assumed to have
disturbances of 0.
t0() is irrelevant if structural is specified because then all observations are assumed to have
disturbances of 0.
t0(5) would begin recursions at t = 5. If the data were quarterly, you might instead type
t0(tq(1961q2)) to obtain the same result.
4 arima postestimation — Postestimation tools for arima
The ARMA component of ARIMA models is recursive and depends on the starting point of the
predictions. This includes one-step-ahead predictions.
structural specifies that the calculation be made considering the structural component only, ignoring
the ARMA terms, producing the steady-state equilibrium predictions.
margins
statistic Description
xb predicted values for mean equation—the differenced series; the default
y predicted values for the mean equation in y —the undifferenced series
stdp not allowed with margins
mse not allowed with margins
residuals not allowed with margins
yresiduals not allowed with margins
Statistics not allowed with margins are functions of stochastic quantities other than e(b).
For the full syntax, see [R] margins.
by typing
. use https://www.stata-press.com/data/r16/wpi1
. arima D.ln_wpi, ar(1) ma(1 4)
(output omitted )
where
∆ ln(wpit−j ) − xbt−j t−j >0
n
t−j =
b
0 otherwise
meaning that predict newvar, xb calculates predictions by using the metric of the dependent variable.
In this example, the dependent variable represented changes in ln(wpit ), and so the predictions are
likewise for changes in that variable.
If we instead use
. predict y, y
Stata computes yt as yt = xbt + ln(wpit−1 ) so that yt represents the predicted levels of ln(wpit ). In
general, predict newvar, y will reverse any time-series operators applied to the dependent variable
during estimation.
If we want to ignore the ARMA error components when making predictions, we use the structural
option,
. predict xbs, xb structural
which generates xbst = βb0 because there are no regressors in this model, and
. predict ys, y structural
consumpt = β0 + β1 m2t + µt
µt = ρµt−1 + θt−1 + t
First, we refit the model by using data up through the first quarter of 1978, and then we will evaluate
the one-step-ahead and dynamic forecasts.
. use https://www.stata-press.com/data/r16/friedman2
. keep if time<=tq(1981q4)
(67 observations deleted)
. arima consump m2 if tin(, 1978q1), ar(1) ma(1)
(output omitted )
6 arima postestimation — Postestimation tools for arima
(Because our dependent variable contained no time-series operators, we could have instead used
predict chat, xb and accomplished the same thing.) We will also make dynamic forecasts,
switching from observed values of consump to forecasted values at the first quarter of 1978:
. predict chatdy, dynamic(tq(1978q1)) y
(52 missing values generated)
The following graph compares the forecasted values to the observed values for the first few years
following the estimation sample:
Personal consumption
2000 1800
Billions of dollars
1400 1600
1200
The one-step-ahead forecasts never deviate far from the observed values, though over time the
dynamic forecasts have larger errors. To understand why that is the case, rewrite the model as
This form shows that the forecasted value of consumption at time t depends on the value of consumption
at time t − 1. When making the one-step-ahead forecast for period t, we know the actual value of
consumption at time t − 1. On the other hand, with the dynamic(tq(1978q1)) option, the forecasted
value of consumption for period 1978q1 is based on the observed value of consumption in period
1977q4, but the forecast for 1978q2 is based on the forecast value for 1978q1, the forecast for 1978q3
is based on the forecast value for 1978q2, and so on. Thus, with dynamic forecasts, prior forecast
errors accumulate over time. The following graph illustrates this effect.
arima postestimation — Postestimation tools for arima 7
Forecast error
0 −50
Forecast − Actual
−150 −100
−200
Example 2
Consider a model of the quarterly U.S. money supply, as measured by M1, from Enders (2004).
Enders (2004, 93–97) discusses why seasonal shopping patterns cause seasonal effects in M1. The
variable lnm1 contains data on the natural log of the money supply. We fit seasonal and nonseasonal
ARIMA models and compare the IRFs calculated from both models.
We fit the following nonseasonal ARIMA model
The code below fits the above model and saves a set of IRF results to a file called myirf.irf.
8 arima postestimation — Postestimation tools for arima
OPG
DS4.lnm1 Coef. Std. Err. z P>|z| [95% Conf. Interval]
ARMA
ar
L1. .3551862 .0503011 7.06 0.000 .2565979 .4537745
L4. -.3275808 .0594953 -5.51 0.000 -.4441895 -.210972
Note: The test of the variance against zero is one sided, and the two-sided
confidence interval is truncated at zero.
. irf create nonseasonal, set(myirf) step(30)
(file myirf.irf created)
(file myirf.irf now active)
(file myirf.irf updated)
The code below fits this nonseasonal ARIMA model and saves a set of IRF results to the active IRF
file, which is myirf.irf.
. arima DS4.lnm1, ar(1) mar(1,4) noconstant nolog
ARIMA regression
Sample: 1961q2 - 2008q2 Number of obs = 189
Wald chi2(2) = 119.78
Log likelihood = 588.6689 Prob > chi2 = 0.0000
OPG
DS4.lnm1 Coef. Std. Err. z P>|z| [95% Conf. Interval]
ARMA
ar
L1. .489277 .0538033 9.09 0.000 .3838245 .5947296
ARMA4
ar
L1. -.4688653 .0601248 -7.80 0.000 -.5867076 -.3510229
Note: The test of the variance against zero is one sided, and the two-sided
confidence interval is truncated at zero.
. irf create seasonal, step(30)
(file myirf.irf updated)
We now have two sets of IRF results in the file myirf.irf. We can graph both IRF functions side
by side by calling irf graph.
arima postestimation — Postestimation tools for arima 9
.5
−.5
0 10 20 30 0 10 20 30
step
95% CI impulse−response function (irf)
Graphs by irfname, impulse variable, and response variable
The trajectories of the IRF functions are similar: each figure shows that a shock to lnm1 causes a
temporary oscillation in lnm1 that dies out after about 15 time periods. This behavior is characteristic
of short-memory processes.
See [TS] psdensity for an introduction to estimating spectral densities using the parameters estimated
by arima.
Reference
Enders, W. 2004. Applied Econometric Time Series. 2nd ed. New York: Wiley.
Also see
[TS] arima — ARIMA, ARMAX, and other dynamic regression models
[TS] estat acplot — Plot parametric autocorrelation and autocovariance functions
[TS] estat aroots — Check the stability condition of ARIMA estimates
[TS] irf — Create and analyze IRFs, dynamic-multiplier functions, and FEVDs
[TS] psdensity — Parametric spectral density estimation after arima, arfima, and ucm
[U] 20 Estimation and postestimation commands