Professional Documents
Culture Documents
tools in Stata
Gustavo
Sanchez
Outline
Solving
models
Subcommands
Examples with
Forecasting tools in Stata
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
Gustavo Sanchez
ARIMA
Questions?
Gustavo
Sanchez
Outline
Solving
models
Outline
Subcommands
Examples with
Examples with panel data
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo
Sanchez
Outline
Solving models for a collection of equations
Solving
models
Components
Subcommands
Stochastic equations fit using estimation commands
Examples with
Time Series Identities
Ex 1: regress
Ex 2: TS
Coefficient vectors
operators and
identities
Ex 3: VAR - Solving the model
ARIMA
Examples with
Obtain static or dynamic forecasts
Panel Data Alternative forecast scenarios
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
forecast command
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo Subcommands
Sanchez
Building the model
Outline
create
Solving
models estimates
Subcommands identity
Examples with coefvector
Time Series exogenous
Ex 1: regress
Ex 2: TS
operators and Solving the model
identities
Ex 3: VAR -
ARIMA
solve
Examples with
adjust
Panel Data
Ex 4: Panel data
Utilities
Ex 4.1:
xtreg xtabond describe
Ex 4.2:
Forecast list
scenarios
Ex 4.3: clear
Coefficient
Vector drop
Questions? query
Gustavo
Sanchez
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress Examples with Time Series
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Questions?
Note: l will be used for natural logs and d for first
difference
Source: International Monetary Fund
Gustavo Sanchez (StataCorp) May 3, 2013 6 / 33
Forecasting
tools in Stata
Gustavo
Sanchez Example 1: Time series - OLS regressions
Outline
Gustavo
Sanchez Example 1: Time series - OLS regressions
Outline
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo
Sanchez
Example 2: Working with time series operators
Outline
Include name for dependent variable
Solving
models . forecast create myfcst2
Subcommands Forecast model myfcst2 started.
. forecast estimates eq2_m1,names(Dlm1)
Examples with
Added estimation results from regress.
Time Series
Forecast model myfcst2 now contains 1 endogenous variable.
Ex 1: regress
Ex 2: TS . forecast estimates eq2_mt,names(Dlmt) advise
operators and
identities (These estimation results are no longer needed; you can drop them.)
Ex 3: VAR - Added estimation results from regress.
ARIMA Forecast model myfcst2 now contains 2 endogenous variables.
Examples with
Panel Data
Ex 4: Panel data
Add identities for log-levels
Ex 4.1:
xtreg xtabond . forecast identity lm1=L.lm1+Dlm1
Ex 4.2: Forecast model myfcst2 now contains 3 endogenous variables.
Forecast
scenarios . forecast identity lmt=L.lmt+Dlmt
Ex 4.3: Forecast model myfcst2 now contains 4 endogenous variables.
Coefficient
Vector
Questions?
Gustavo
Sanchez
Example 2: Working with time series operators
Outline
Include name for dependent variable
Solving
models . forecast create myfcst2
Subcommands Forecast model myfcst2 started.
. forecast estimates eq2_m1,names(Dlm1)
Examples with
Added estimation results from regress.
Time Series
Forecast model myfcst2 now contains 1 endogenous variable.
Ex 1: regress
Ex 2: TS . forecast estimates eq2_mt,names(Dlmt) advise
operators and
identities (These estimation results are no longer needed; you can drop them.)
Ex 3: VAR - Added estimation results from regress.
ARIMA Forecast model myfcst2 now contains 2 endogenous variables.
Examples with
Panel Data
Ex 4: Panel data
Add identities for log-levels
Ex 4.1:
xtreg xtabond . forecast identity lm1=L.lm1+Dlm1
Ex 4.2: Forecast model myfcst2 now contains 3 endogenous variables.
Forecast
scenarios . forecast identity lmt=L.lmt+Dlmt
Ex 4.3: Forecast model myfcst2 now contains 4 endogenous variables.
Coefficient
Vector
Questions?
Gustavo
Sanchez
Example 2: Working with time series operators
Outline
Add identities for the levels of the dependent variable
Solving . forecast identity m1 = exp(lm1)
models Forecast model myfcst2 now contains 5 endogenous variables.
Subcommands . forecast identity mt = exp(lmt)
Forecast model myfcst2 now contains 6 endogenous variables.
Examples with
Time Series
Ex 1: regress . forecast solve, begin(q(2010q1)) prefix(f2_)
Ex 2: TS Computing dynamic forecasts for model myfcst2.
operators and
identities
Ex 3: VAR - Starting period: 2010q1
ARIMA
Ending period: 2011q2
Examples with Forecast prefix: f2_
Panel Data
2010q1: ..............
Ex 4: Panel data
Ex 4.1:
2010q2: ..............
xtreg xtabond 2010q3: .............
Ex 4.2: 2010q4: ..............
Forecast
scenarios 2011q1: ..............
Ex 4.3: 2011q2: ..............
Coefficient
Vector Forecast 6 variables spanning 6 periods.
Questions?
Gustavo
Sanchez
Example 2: Working with time series operators
Outline
Add identities for the levels of the dependent variable
Solving . forecast identity m1 = exp(lm1)
models Forecast model myfcst2 now contains 5 endogenous variables.
Subcommands . forecast identity mt = exp(lmt)
Forecast model myfcst2 now contains 6 endogenous variables.
Examples with
Time Series
Ex 1: regress . forecast solve, begin(q(2010q1)) prefix(f2_)
Ex 2: TS Computing dynamic forecasts for model myfcst2.
operators and
identities
Ex 3: VAR - Starting period: 2010q1
ARIMA
Ending period: 2011q2
Examples with Forecast prefix: f2_
Panel Data
2010q1: ..............
Ex 4: Panel data
Ex 4.1:
2010q2: ..............
xtreg xtabond 2010q3: .............
Ex 4.2: 2010q4: ..............
Forecast
scenarios 2011q1: ..............
Ex 4.3: 2011q2: ..............
Coefficient
Vector Forecast 6 variables spanning 6 periods.
Questions?
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo
Sanchez
Example 3.2: Simulations
Outline
Solve model (dlpib, dlxt, dlipex) including simulations
Solving . forecast solve, begin(tq(2010q1)) prefix(fs_) log(off) ///
models > simulate(betas, statistic(stddev, prefix(sd_)) reps(100))
Subcommands Computing dynamic forecasts for model myfcst3.
Gustavo
Sanchez
Example 3.2: Simulations
Outline
Solve model (dlpib, dlxt, dlipex) including simulations
Solving . forecast solve, begin(tq(2010q1)) prefix(fs_) log(off) ///
models > simulate(betas, statistic(stddev, prefix(sd_)) reps(100))
Subcommands Computing dynamic forecasts for model myfcst3.
Gustavo
Sanchez
Example 3.2: Simulations
Outline
Solve model (dlpib, dlxt, dlipex) including simulations
Solving . forecast solve, begin(tq(2010q1)) prefix(fs_) log(off) ///
models > simulate(betas, statistic(stddev, prefix(sd_)) reps(100))
Subcommands Computing dynamic forecasts for model myfcst3.
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo
Sanchez
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress Examples with Panel Data
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo
Sanchez
Examples with Panel data
Outline Model for aggregate consumption
Solving
models consumoit = +pibit 1 +pibit1 2 +irateit 3 +i +it
Subcommands
Questions?
Gustavo
Sanchez
Examples with Panel data
Outline Model for aggregate consumption
Solving
models consumoit = +pibit 1 +pibit1 2 +irateit 3 +i +it
Subcommands
Questions?
Examples with
lpib Coef. Std. Err. z P>|z| [95% Conf. Interval]
Panel Data
Ex 4: Panel data lpib
Ex 4.1: L1. .8500304 .038387 22.14 0.000 .7747932 .9252675
xtreg xtabond trend .0125958 .0017827 7.07 0.000 .0091019 .0160897
Ex 4.2:
Forecast _cons 3.549008 .9035604 3.93 0.000 1.778062 5.319954
scenarios
Ex 4.3:
Coefficient Instruments for differenced equation
Vector GMM-type: L(2/.).lpib
Questions? Standard: D.trend
Instruments for level equation
Standard: _cons
. estimates store eq_lpib
Examples with lirate Coef. Std. Err. z P>|z| [95% Conf. Interval]
Panel Data
Ex 4: Panel data lirate
Ex 4.1:
xtreg xtabond L1. .8837478 .0643112 13.74 0.000 .7577002 1.009795
Ex 4.2: L2. -.4333317 .044075 -9.83 0.000 -.519717 -.3469463
Forecast _cons .8355917 .099475 8.40 0.000 .6406244 1.030559
scenarios
Ex 4.3:
Coefficient Instruments for differenced equation
Vector
GMM-type: L(2/.).lirate
Questions? Instruments for level equation
Standard: _cons
. estimates store eq_lirate
Gustavo
Example 4.1: xtreg xtabond
Sanchez
Create and solve the model
Outline
. quietly forecast create xtfcst
Solving
models
. quietly forecast estimates eq_con
. forecast estimates eq_lpib
Subcommands forecast will use the default type of prediction for xtabond. Verify this
Examples with is appropriate; see xtabond postestimation. Use the predict() option with
Time Series forecast estimates to override the default.
Ex 1: regress Added estimation results from xtabond.
Ex 2: TS Forecast model xtfcst now contains 2 endogenous variables.
operators and
identities
Ex 3: VAR -
ARIMA . forecast estimates eq_lirate
forecast will use the default type of prediction for xtabond. Verify this
Examples with
Panel Data
is appropriate; see xtabond postestimation. Use the predict() option with
Ex 4: Panel data
forecast estimates to override the default.
Ex 4.1: Added estimation results from xtabond.
xtreg xtabond
Ex 4.2:
Forecast model xtfcst now contains 3 endogenous variables.
Forecast
scenarios
Ex 4.3: . capture noisily forecast solve
Coefficient must have strongly balanced panel data
Vector
Questions?
Oops! Unbalanced panels... Use tsfill
Gustavo
Example 4.1: xtreg xtabond
Sanchez
Create and solve the model
Outline
. quietly forecast create xtfcst
Solving
models
. quietly forecast estimates eq_con
. forecast estimates eq_lpib
Subcommands forecast will use the default type of prediction for xtabond. Verify this
Examples with is appropriate; see xtabond postestimation. Use the predict() option with
Time Series forecast estimates to override the default.
Ex 1: regress Added estimation results from xtabond.
Ex 2: TS Forecast model xtfcst now contains 2 endogenous variables.
operators and
identities
Ex 3: VAR -
ARIMA . forecast estimates eq_lirate
forecast will use the default type of prediction for xtabond. Verify this
Examples with
Panel Data
is appropriate; see xtabond postestimation. Use the predict() option with
Ex 4: Panel data
forecast estimates to override the default.
Ex 4.1: Added estimation results from xtabond.
xtreg xtabond
Ex 4.2:
Forecast model xtfcst now contains 3 endogenous variables.
Forecast
scenarios
Ex 4.3: . capture noisily forecast solve
Coefficient must have strongly balanced panel data
Vector
Questions?
Oops! Unbalanced panels... Use tsfill
Gustavo
Example 4.1: xtreg xtabond
Sanchez
Create and solve the model
Outline
. quietly forecast create xtfcst
Solving
models
. quietly forecast estimates eq_con
. forecast estimates eq_lpib
Subcommands forecast will use the default type of prediction for xtabond. Verify this
Examples with is appropriate; see xtabond postestimation. Use the predict() option with
Time Series forecast estimates to override the default.
Ex 1: regress Added estimation results from xtabond.
Ex 2: TS Forecast model xtfcst now contains 2 endogenous variables.
operators and
identities
Ex 3: VAR -
ARIMA . forecast estimates eq_lirate
forecast will use the default type of prediction for xtabond. Verify this
Examples with
Panel Data
is appropriate; see xtabond postestimation. Use the predict() option with
Ex 4: Panel data
forecast estimates to override the default.
Ex 4.1: Added estimation results from xtabond.
xtreg xtabond
Ex 4.2:
Forecast model xtfcst now contains 3 endogenous variables.
Forecast
scenarios
Ex 4.3: . capture noisily forecast solve
Coefficient must have strongly balanced panel data
Vector
Questions?
Oops! Unbalanced panels... Use tsfill
Gustavo
Example 4.1: xtreg xtabond
Sanchez
Create and solve the model
Outline
. quietly forecast create xtfcst
Solving
models
. quietly forecast estimates eq_con
. forecast estimates eq_lpib
Subcommands forecast will use the default type of prediction for xtabond. Verify this
Examples with is appropriate; see xtabond postestimation. Use the predict() option with
Time Series forecast estimates to override the default.
Ex 1: regress Added estimation results from xtabond.
Ex 2: TS Forecast model xtfcst now contains 2 endogenous variables.
operators and
identities
Ex 3: VAR -
ARIMA . forecast estimates eq_lirate
forecast will use the default type of prediction for xtabond. Verify this
Examples with
Panel Data
is appropriate; see xtabond postestimation. Use the predict() option with
Ex 4: Panel data
forecast estimates to override the default.
Ex 4.1: Added estimation results from xtabond.
xtreg xtabond
Ex 4.2:
Forecast model xtfcst now contains 3 endogenous variables.
Forecast
scenarios
Ex 4.3: . capture noisily forecast solve
Coefficient must have strongly balanced panel data
Vector
Questions?
Oops! Unbalanced panels... Use tsfill
Solving
models . capture noisily forecast solve, begin(2007) end(2009)
Computing dynamic forecasts for model xtfcst.
Subcommands
Solving
models . capture noisily forecast solve, begin(2007) end(2009)
Computing dynamic forecasts for model xtfcst.
Subcommands
Gustavo
Sanchez Example 4.1: xtreg xtabond
Outline Keep panels with full (required) data for forecast period
Solving
. /* Balanced panels for forecasting period
models
> egen nomiss=rownonmiss(lconsumo lpib lirate)
Subcommands > by country: generate mycount=nomiss==3 if year>=2005
> keep if mycount==1
Examples with > xtset country year
Time Series
> keep country year consumo pib irate lconsumo lpib lirate trend
Ex 1: regress
Ex 2: TS
> by country:keep if _N==6
operators and > xtset country year
identities
Ex 3: VAR -
> */
ARIMA
Gustavo
Sanchez Example 4.1: xtreg xtabond
Outline Keep panels with full (required) data for forecast period
Solving
. /* Balanced panels for forecasting period
models
> egen nomiss=rownonmiss(lconsumo lpib lirate)
Subcommands > by country: generate mycount=nomiss==3 if year>=2005
> keep if mycount==1
Examples with > xtset country year
Time Series
> keep country year consumo pib irate lconsumo lpib lirate trend
Ex 1: regress
Ex 2: TS
> by country:keep if _N==6
operators and > xtset country year
identities
Ex 3: VAR -
> */
ARIMA
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo
Example 4.3: Panel Data - Coefficient Vector
Sanchez
Coefficient vector for lincome
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?
Gustavo
Sanchez
Outline
Solving
models
Subcommands
Examples with
Time Series
Ex 1: regress Questions?
Ex 2: TS
operators and
identities
Ex 3: VAR -
ARIMA
Examples with
Panel Data
Ex 4: Panel data
Ex 4.1:
xtreg xtabond
Ex 4.2:
Forecast
scenarios
Ex 4.3:
Coefficient
Vector
Questions?