conditional forecast

Questions and discussions on Vector Autoregressions
geer
Posts: 5
Joined: Tue Aug 22, 2023 9:08 am

conditional forecast

Unread post by geer »

I am trying to use the conditional forecast example of the User's Guide, Section 7.7.2 (CONDITION.RPF). It is based on VAR model. However, the RATS displays an error message: I2. Expected Instruction Here. Do you know what's the error?

The code is listed as follows:
open data oecdsample.rat
calendar(q) 1981
data(format=rats) 1981:1 2006:4 can3mthpcp canexpgdpchs $
canexpgdpds canm1s canusxsr usaexpgdpch
*
set logcangdp = log(canexpgdpchs)
set logcandefl = log(canexpgdpds)
set logcanm1 = log(canm1s)
set logusagdp = log(usaexpgdpch)
set logexrate = log(canusxsr)
*
system(model=canmodel)
variables logcangdp logcandefl logcanm1 logexrate can3mthpcp logusagdp
lags 1 to 4
det constant
end(system)
estimate
*
compute fstart=2007:1,fend=2009:4
*
@condition(model=canmodel,steps=12,results=condfore) 2
# logusagdp 2007:4 logusagdp(2006:4)+.05
# logusagdp 2008:4 logusagdp(2006:4)+.10

Thanks in advance
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: conditional forecast

Unread post by TomDoan »

That works fine. If you tried to copy out of the manual, that won't necessarily work--PDF can replace characters to improve appearance. All examples are in your Examples folder as an actual RATS program (that is, straight text) file).
geer
Posts: 5
Joined: Tue Aug 22, 2023 9:08 am

Re: conditional forecast

Unread post by geer »

My conditional forecast code is as follows:
OPEN DATA "C:\Users\geer\Desktop\four.csv"
CALENDAR(M) 2007:8
DATA(FORMAT=PRN,NOLABELS,ORG=COLUMNS) 2007:08 2009:07 DEMAND OUTPUT PRICE IPRICE
SYSTEM(MODEL=VAR1)
VARIABLES DEMAND OUTPUT PRICE IPRICE
LAGS 1
DET
END(SYSTEM)
ESTIMATE 2007:08 2009:07
*
compute fstart=2009:8,fend=2009:8
@condition(model=VAR1,steps=1,results=condfore) 1
# PRICE 2009:8 5

I have the data from 2007:8 to 2009:07, and I also know the data of PRICE on 2009:8 (It equals to 5). I want to forecast the other three variables on 2009:8 based on conditional forecast. model. Do you know where is the error of this code? It cannot worked in the last two teps.(@condition(model=VAR1,steps=1,results=condfore) 1 # PRICE 2009:8 5)

Thank you!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: conditional forecast

Unread post by TomDoan »

Edit---Show Last Error will show you the line that caused the error. I don't see any problems with that---I don't know if pasting it into a forum window fixes the problem. If you can't figure out the problem, attach the program and data file so I can run what you are running.
geer
Posts: 5
Joined: Tue Aug 22, 2023 9:08 am

Re: conditional forecast

Unread post by geer »

Thanks Tom. It works now, maybe I did something wrong before.

And can I use RATS do loop statement based on conditional forecast? For example, If I want to use the data from the first 24 periods to predict the 25th period, and push forward one period each time for prediction. What type of program can I use? I think maybe I should modify the code "# PRICE 2009:8 5", but I don't know how to do it to to achieve the purpose of looping.

Thanks a lot!
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: conditional forecast

Unread post by TomDoan »

I assume you want to re-estimate the model each time. How is your forecast condition entering into this? Is it always PRICE(2009:8)=5, or does the constrained period also move with the estimation window.

What you posted only HAS 24 data points. Do you have more than that?
geer
Posts: 5
Joined: Tue Aug 22, 2023 9:08 am

Re: conditional forecast

Unread post by geer »

Yes, there are more data points in my data.

I want to re-estimate the model each time. For example, in the first estimation, I estimate the model from 2007:8 to 2009:7 and forecast the values of variables on 2009:8. And in the second estimation, I re-estimate the model from 2007:9 to 2009:8 (always 24 periods) and forecast the values of variables on 2009:9. At each time the window moves forward one period and the model will be re-estimated and re-forecasted. The PRICE variable is not always equal to 5, it will change over time as shown in attached table.
Attachments
four.csv
(6.11 KiB) Downloaded 1632 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: conditional forecast

Unread post by TomDoan »

What you're planning to do (if I understand correctly) can be simplified by setting that up as a recursive model (for the other three variables conditional on current and lagged PRICE). Because it's just one step out, there isn't time for the shocks to demand, output and iprice to affect price.

Code: Select all

OPEN DATA "four.csv"
CALENDAR(M) 2007:8
DATA(FORMAT=PRN,ORG=COLUMNS) 2007:08 2020:10 DEMAND OUTPUT PRICE IPRICE
*
SYSTEM(MODEL=VAR1)
VARIABLES DEMAND OUTPUT IPRICE
LAGS 1
DET PRICE{0 1}
END(SYSTEM)
*
do sampleEnd=2009:7,2020:9
   estimate(noprint) * sampleEnd
   forecast(model=var1,steps=1,results=condfore)
end do sampleEnd
geer
Posts: 5
Joined: Tue Aug 22, 2023 9:08 am

Re: conditional forecast

Unread post by geer »

Thank you for your help! Maybe I have not thoroughly understood your code. Can I put the PRICE variable in a table and re-estimate and re-forecast the models? It means that if I could do the recursive program through each rows? Because PRICE variable is not a constant.
And if I'd like to do a 3-step forecast, how can I modify this code?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: conditional forecast

Unread post by TomDoan »

What is the source of the conditioning values for PRICE? Are you using the actual values (i.e. acting as if you can observe those ahead of the other three variables)?

If you are doing three steps, then you need to go back to using the @CONDITION procedure (unless you are conditioning on the observed PRICE(T+1),PRICE(T+2) and PRICE(T+3)).
Post Reply