Page 1 of 2
VAR Forecast from Difference to Levels
Posted: Thu Dec 27, 2012 5:00 pm
by rmvoller
I have ran the following VAR model on two differenced series:
Code: Select all
System(model=dvar)
variables dx dy
lags 1 to 4
det constant
end(system)
estimate * 2011:1
forecast(model=dvar,from=2011:2,to=2012:3,result=forecast,stderrs=s,print)
When I restrict the time series by a few periods for the in sample forecast I am able to to convert the differenced forecast to levels with the following code:
Code: Select all
set xforecast = forecast(1) + x{1}
But when I run the Var model on the full data series I am unable to convert the differenced forecasts by using the above formula. Below is the code for the Var over the full series. How could I convert my differenced forecast into levels?
Code: Select all
System(model=dvar)
variables dx dy
lags 1 to 4
det constant
end(system)
estimate
forecast(model=dvar,from=2012:3,to=2016:4,result=forecast,stderrs=s,print)
How could I convert my differenced forecast into levels?
Thanks in advance
Re: VAR Forecast from Difference to Levels
Posted: Wed Jan 02, 2013 6:47 pm
by TomDoan
There are many different ways to do that. The simplest is probably:
set(first=forecast(1)+x{1}) accx 2012:3 2016:4 = accx{1}+forecast(1)
Re: VAR Forecast from Difference to Levels
Posted: Thu Apr 11, 2013 11:29 am
by Agty
Hello everybody,
I have exactly the same problem as the one rmvoller posted on december 28, 2012. I've tried thousands of times the solution gave by Tom Doan, unsuscessfully with any kind of message errors. My quaterly four variables of interest are VCREDITSEns, TxImmo, IndPrixAncien and RDB. I have made forecasts of those variables in first differences (with the following code) and I am unable to move from Differences to Levels. Can someone tell me how to adapt TomDoan code to achieve this? I thank in advance.
*
smpl de f
system(model=dvar)
variables dVCREDITSEns dTxImmo dIndPrixAncien dRDB
lags 1 to 2
det constant
end(system)
*
estimate
errors(model=dvar,steps=8)
FORECAST(MODEL=dvar,FROM=2013:01,TO=2018:04,result=forecast,stderrs=s,PRINT)
Re: VAR Forecast from Difference to Levels
Posted: Thu Apr 11, 2013 1:32 pm
by TomDoan
Something like this:
Code: Select all
cal(q) 2000:1
all 2012:4
set VCREDITSEns = %ran(1.0)
set TxImmo = %ran(1.0)
set IndPrixAncien = %ran(1.0)
set RDB = %ran(1.0)
*
dofor i = VCREDITSEns TxImmo IndPrixAncien RDB
set %s("d"+%l(i)) = i{0}-i{1}
end dofor s
*
system(model=dvar)
variables dVCREDITSEns dTxImmo dIndPrixAncien dRDB
lags 1 to 2
det constant
end(system)
estimate
errors(model=dvar,steps=8)
FORECAST(MODEL=dvar,FROM=2013:01,TO=2018:04,result=dforecast,stderrs=s,PRINT)
*
dec vect[series] forecast(4)
set(first=dforecast(1)+vcreditsens{1}) forecast(1) 2013:1 2018:4 = dforecast(1)+forecast(1){1}
set(first=dforecast(2)+tximmo{1}) forecast(2) 2013:1 2018:4 = dforecast(2)+forecast(2){1}
set(first=dforecast(3)+indprixancien{1}) forecast(3) 2013:1 2018:4 = dforecast(3)+forecast(3){1}
set(first=dforecast(4)+rdb{1}) forecast(4) 2013:1 2018:4 = dforecast(4)+forecast(4){1}
Re: VAR Forecast from Difference to Levels
Posted: Wed May 21, 2014 9:28 pm
by timduy
Is there by chance a simple way to do the same for the standard errors - to create confidence intervals in levels?
Re: VAR Forecast from Difference to Levels
Posted: Wed May 21, 2014 10:31 pm
by TomDoan
timduy wrote:Is there by chance a simple way to do the same for the standard errors - to create confidence intervals in levels?
See the ACCUMULATE option on MCVARDODraws:
*
* @MCVARDoDraws(model=VAR model to analyze,other options)
*
* Computes impulse response functions for a VAR using Monte Carlo
* simulation. This assumes the model is an OLS VAR estimated using the
* ESTIMATE instruction. This uses a Cholesky factorization, though it
* can be modified fairly easily to do any just-identified factorization.
*
* Options:
* MODEL=model to analyze [required]
* STEP=number of response steps[48]
* DRAWS=number of Monte Carlo draws[1000]
* ACCUMULATE=list of variables (by position) to accumulate [none]
Re: VAR Forecast from Difference to Levels
Posted: Mon Mar 14, 2016 6:08 pm
by timduy
Tom:
So, circling back to this and realizing that I am just not seeing the link between @MCVARDoDraws and building up the confidence intervals in levels. Simple VAR model:
Code: Select all
CAL(M) 1947:1
DATA(FORMAT=FRED) * * USREC PCEPI PCEPILFE
ALL 2020:4
*
SOURCE "/Applications/RATS 8.3/Procedures/REGACTFIT.src"
SOURCE "/Applications/RATS 8.3/Procedures/VARIRF.src"
SOURCE "/Applications/RATS 8.3/Procedures/MCVARDoDraws.src"
SOURCE "/Applications/RATS 8.3/Procedures/MONTEVAR.src"
* @MCVARDoDraws(model=VAR model to analyze,other options)
SOURCE "/Applications/RATS 8.3/Procedures/MCVARDoDraws.src"
*
LOG PCEPI
LOG PCEPILFE
*
DIFF PCEPILFE / CORE
DIFF PCEPI / HEADLINE
*
*ESTIMATE PREFERRED MODEL***
***
SYSTEM(MODEL=COREVAR)
VARIABLES CORE HEADLINE
LAGS 1 TO 6
DET CONSTANT
END(SYSTEM)
*
ESTIMATE 1984:1 *
*
***
FORECAST(MODEL=COREVAR,NOSTATIC, RESULTS=COREFOR, STDERRS=COREERRORS, FROM=2014:4,TO=2016:12)
***
That will forecast the differences for the two variables, which I can build into level forecasts. Then I use:
Code: Select all
@MCVARDoDraws(model=COREVAR,ACCUMULATE=||1,2||)
Which yields 4 IRF's...but I am thinking in the background is the standard errors for the IRF's which can then be turned into the level forecasts standard errors? Or is that off base?
Thanks for the help!
Re: VAR Forecast from Difference to Levels
Posted: Tue Mar 15, 2016 3:37 pm
by TomDoan
To get the calculation of the standard errors of forecast of the accumulated data, you need to use "integrating" identities.
equation(identity,coeffs=||1.0,1.0||) icoreeq icore
# icore{1} core
equation(identity,coeffs=||1.0,1.0||) iheadeq iheadline
# iheadline{1} headline
FORECAST(MODEL=COREVAR+icoreeq+iheadeq,NOSTATIC, RESULTS=COREFOR, STDERRS=COREERRORS, FROM=2014:4,TO=2016:12)
That will forecast both the original and integrated series and compute standard errors of forecast for all of them. While the IRF's have all the information for computing the multiple step forecast standard errors, putting the information together isn't simple.
Re: VAR Forecast from Difference to Levels
Posted: Wed Mar 16, 2016 11:13 am
by timduy
Thanks - it would have taken me awhile to get there.
I think I came up with another workaround. I defined a cointegrating vector as:
Code: Select all
EQUATION(COEFFS=||0.0,0.0||) CIRELAT2
#PCEPI PCEPILFE
and then ran the error correction model:
Code: Select all
SYSTEM(MODEL=COREVAR)
VARIABLES PCEPI PCEPILFE
LAGS 1 TO 6
DET CONSTANT
ECT CIRELAT2
END(SYSTEM)
ESTIMATE 1984:1 *
which collapses to a VAR in differences but with level forecasts. Just need to make sure to set the lag length appropriately to match the initial VAR model.
Re: VAR Forecast from Difference to Levels
Posted: Wed Mar 16, 2016 11:21 am
by TomDoan
Thanks. I believe just
ECT
by itself will do the same thing so you don't have to define the zeroed out equation. That, of course, doesn't give you the forecasts of the differenced variables in case you want both, but if you just want the integrated results, then the empty ECT will work fine.
Re: VAR Forecast from Difference to Levels
Posted: Mon Jul 12, 2021 6:29 am
by ac_1
Hi Tom,
My aim is to estimate a VAR in DIFFERENCES and back out LEVELS forecasts and LEVELS standard errors, hence plot PI's for the forecasts of the ORIGINAL series.
From the above, which appears reasonable:
Code: Select all
seed 13939
cal(q) 2000:1
all 2012:4
* generate ORIGINAL series in LEVELS
set VCREDITSEns = %ran(1.0)
set TxImmo = %ran(1.0)
set IndPrixAncien = %ran(1.0)
set RDB = %ran(1.0)
prin / VCREDITSEns TxImmo IndPrixAncien RDB
* calculate DIFFERENCE series
dofor i = VCREDITSEns TxImmo IndPrixAncien RDB
set %s("d"+%l(i)) = i{0}-i{1}
end dofor s
prin / dVCREDITSEns dTxImmo dIndPrixAncien dRDB
* estimate VAR for DIFFERENCE series
system(model=dvar)
variables dVCREDITSEns dTxImmo dIndPrixAncien dRDB
lags 1 to 2
det constant
end(system)
estimate
errors(model=dvar,steps=8); * decomposition of variance for VAR
FORECAST(MODEL=dvar,FROM=2013:01,TO=2018:04,result=dforecast,stderrs=s,PRINT)
prin / dforecast(1) dforecast(2) dforecast(3) dforecast(4)
prin / s(1) s(2) s(3) s(4)
* Back-out forecasts in LEVELS for ORIGINAL series in LEVELS, having estimated VAR for DIFFERENCE series
dec vect[series] forecast(4)
set(first=dforecast(1)+vcreditsens{1}) forecast(1) 2013:1 2018:4 = dforecast(1)+forecast(1){1}
set(first=dforecast(2)+tximmo{1}) forecast(2) 2013:1 2018:4 = dforecast(2)+forecast(2){1}
set(first=dforecast(3)+indprixancien{1}) forecast(3) 2013:1 2018:4 = dforecast(3)+forecast(3){1}
set(first=dforecast(4)+rdb{1}) forecast(4) 2013:1 2018:4 = dforecast(4)+forecast(4){1}
prin / forecast(1) forecast(2) forecast(3) forecast(4)
I want to back-out forecast SE's in LEVELS for ORIGINAL series in LEVELS, having estimated VAR for DIFFERENCE series, as follows
Code: Select all
equation(identity,coeffs=||1.0,1.0||) idVCREDITSEnseq idVCREDITSEns
# idVCREDITSEns{1} dVCREDITSEns
equation(identity,coeffs=||1.0,1.0||) idTxImmoeq idTxImmo
# idTxImmo{1} dTxImmo
equation(identity,coeffs=||1.0,1.0||) idIndPrixAncieneq idIndPrixAncien
# idIndPrixAncien{1} dIndPrixAncien
equation(identity,coeffs=||1.0,1.0||) idRDBeq idRDB
# idRDB{1} dRDB
FORECAST(MODEL=dvar+idVCREDITSEnseq+idTxImmoeq+idIndPrixAncieneq+idRDBeq,NOSTATIC,RESULTS=COREFOR,STDERRS=COREERRORS,FROM=2013:1,TO=2018:04)
Equivalence's:
Code: Select all
* forecast's of DIFFERENCE series, same as dforecast(1), dforecast(2), dforecast(3), dforecast(4)
prin / COREFOR(1) COREFOR(2) COREFOR(3) COREFOR(4)
There is nothing in. Why?
Code: Select all
prin / COREFOR(5) COREFOR(6) COREFOR(7) COREFOR(8)
Are these the forecast SE's for the ORIGINAL series in LEVELS?
Code: Select all
prin / COREERRORS(5) COREERRORS(6) COREERRORS(7) COREERRORS(8)
Or these?
Code: Select all
prin / COREERRORS(1) COREERRORS(2) COREERRORS(3) COREERRORS(4)
However neither of these are equivalent to the forecast SE's for the DIFFERENCE series
thanks,
Amarjit
Re: VAR Forecast from Difference to Levels
Posted: Mon Jul 12, 2021 10:36 am
by TomDoan
You have identities which say that (for instance) idRDB = idRDB{1}+dRDB. However, you don't define idRDB. Shouldn't that be RDB? That's the relationship isn't it?
Re: VAR Forecast from Difference to Levels
Posted: Mon Jul 12, 2021 12:34 pm
by ac_1
TomDoan wrote:You have identities which say that (for instance) idRDB = idRDB{1}+dRDB. However, you don't define idRDB. Shouldn't that be RDB? That's the relationship isn't it?
Thanks. I have changed the identities to:
Code: Select all
equation(identity,coeffs=||1.0,1.0||) VCREDITSEnseq VCREDITSEns
# VCREDITSEns{1} VCREDITSEns
equation(identity,coeffs=||1.0,1.0||) TxImmoeq TxImmo
# TxImmo{1} TxImmo
equation(identity,coeffs=||1.0,1.0||) IndPrixAncieneq IndPrixAncien
# IndPrixAncien{1} IndPrixAncien
equation(identity,coeffs=||1.0,1.0||) RDBeq RDB
# RDB{1} RDB
FORECAST(MODEL=dvar+VCREDITSEnseq+TxImmoeq+IndPrixAncieneq+RDBeq,NOSTATIC,RESULTS=COREFOR,STDERRS=COREERRORS,FROM=2013:1,TO=2018:04)
There are values in:
Code: Select all
prin / COREFOR(5) COREFOR(6) COREFOR(7) COREFOR(8)
There are zeroes in:
Code: Select all
prin / COREERRORS(5) COREERRORS(6) COREERRORS(7) COREERRORS(8)
And forecast SE's in:
Code: Select all
prin / COREERRORS(1) COREERRORS(2) COREERRORS(3) COREERRORS(4)
Which I think are for the ORIGINAL series in LEVELS. Right?
Re: VAR Forecast from Difference to Levels
Posted: Mon Jul 12, 2021 12:45 pm
by TomDoan
ac_1 wrote:
Code: Select all
equation(identity,coeffs=||1.0,1.0||) VCREDITSEnseq VCREDITSEns
# VCREDITSEns{1} VCREDITSEns
equation(identity,coeffs=||1.0,1.0||) TxImmoeq TxImmo
# TxImmo{1} TxImmo
equation(identity,coeffs=||1.0,1.0||) IndPrixAncieneq IndPrixAncien
# IndPrixAncien{1} IndPrixAncien
equation(identity,coeffs=||1.0,1.0||) RDBeq RDB
# RDB{1} RDB
Those aren't right. What happened to the "D" series on the RHS?
Note, by the way, that with RATS v10 you can use FRML's for the identities. (This thread was started several years before version 10 was out).
Re: VAR Forecast from Difference to Levels
Posted: Mon Jul 12, 2021 1:08 pm
by ac_1
TomDoan wrote:ac_1 wrote:
Code: Select all
equation(identity,coeffs=||1.0,1.0||) VCREDITSEnseq VCREDITSEns
# VCREDITSEns{1} VCREDITSEns
equation(identity,coeffs=||1.0,1.0||) TxImmoeq TxImmo
# TxImmo{1} TxImmo
equation(identity,coeffs=||1.0,1.0||) IndPrixAncieneq IndPrixAncien
# IndPrixAncien{1} IndPrixAncien
equation(identity,coeffs=||1.0,1.0||) RDBeq RDB
# RDB{1} RDB
Those aren't right. What happened to the "D" series on the RHS?
Note, by the way, that with RATS v10 you can use FRML's for the identities. (This thread was started several years before version 10 was out).
Apologies. Are these correct?
Code: Select all
equation(identity,coeffs=||1.0,1.0||) VCREDITSEnseq VCREDITSEns
# VCREDITSEns{1} dVCREDITSEns
equation(identity,coeffs=||1.0,1.0||) TxImmoeq TxImmo
# TxImmo{1} dTxImmo
equation(identity,coeffs=||1.0,1.0||) IndPrixAncieneq IndPrixAncien
# IndPrixAncien{1} dIndPrixAncien
equation(identity,coeffs=||1.0,1.0||) RDBeq RDB
# RDB{1} dRDB
FORECAST(MODEL=dvar+VCREDITSEnseq+TxImmoeq+IndPrixAncieneq+RDBeq,NOSTATIC,RESULTS=COREFOR,STDERRS=COREERRORS,FROM=2013:1,TO=2018:04)