Page 1 of 1
Problem with @CONDITION
Posted: Mon Oct 28, 2013 9:04 am
by Ozmando
Dear Users,
I am trying to run a code in Rats 8.2 but get the following message after 2100 iterations:
"## OP9. Options MODEL and parameter list of equations May Not Be Used Together
## OP3. This Instruction Does Not Have An Option DEC
>>>> @condition(decomp=<<<<"
The code was originally written using Rats 6.0.
I was wondering if anyone can help with this please.
Regards,
Oz
PS: Would have been easier to post the code; but got it from somebody and do not have permission to make it public. Sorry for this.
Re: Help with error please
Posted: Mon Oct 28, 2013 10:59 am
by TomDoan
Those are two different errors. For the second, on 8.2 the DECOMP option on @CONDITION is replaced by FACTOR, so you just have to replace DECOMP= with FACTOR=. For the first, it sounds as if you have an instruction
SYSTEM(MODEL=...) list of equations
If you're using MODEL, you don't want the "list of equations".
Re: Help with error please
Posted: Mon Oct 28, 2013 5:07 pm
by Ozmando
TomDoan wrote:Those are two different errors. For the second, on 8.2 the DECOMP option on @CONDITION is replaced by FACTOR, so you just have to replace DECOMP= with FACTOR=. For the first, it sounds as if you have an instruction
SYSTEM(MODEL=...) list of equations
If you're using MODEL, you don't want the "list of equations".
Hi Tom, Thanks for your reply.
I have done the changes but now get this error:
## OP9. Options MODEL and parameter list of equations May Not Be Used Together
## SX22. Expected Type INTEGER, Got MODEL Instead
>>>>r=chole) varmodel1 <<<<
With regard to ##OP9: this is the portion of the code:
system(model=varmodel1) 1 to nvar
variables usinf usinfr useg usgdpg jpinf jpinfr jpeg jpgdpg $
geinf geinfr geeg gegdpg ukinf ukinfr ukeg ukgdpg $
frinf frinfr freg frgdpg itinf itinfr iteg itgdpg $
cainf cainfr caeg cagdpg
lags 1 to nlags
det constant
end(system)
Many thanks,
oz
Re: Help with error please
Posted: Mon Oct 28, 2013 5:13 pm
by TomDoan
You want just
system(model=varmodel1)
for the first line.
On the @CONDITION procedure call, you want to use MODEL=VARMODEL1 as one of the options. The parameter should be the number of constraints, not the model name.
Re: Help with error please
Posted: Wed Oct 30, 2013 7:25 am
by Ozmando
TomDoan wrote:You want just
system(model=varmodel1)
for the first line.
On the @CONDITION procedure call, you want to use MODEL=VARMODEL1 as one of the options. The parameter should be the number of constraints, not the model name.
Hi Tom,
Many thanks again. With your suggestion one of the problem is now solved. But still struggling with the one related to @CONDITION
Will look through the RATS programming manual but this is the actual portion of the code:
@condition(factor=chole) varmodel1 nstep tempend+1 sigm 2 condfore
# usgdpg tempend+1 usgdpg(tempend)+1.
* # usgdpg tempend+2 usgdpg(tempend)+.5
* # usgdpg tempend+3 usgdpg(tempend)+.25
* # usgdpg tempend+4 usgdpg(tempend)
# useg tempend+1 useg(tempend)+1.
* # useg tempend+2 usgdpg(tempend)+.5
forecast(model=varmodel1,results=forecasts) nvar nstep tempend+1
Many thanks,
oz
Re: Help with error please
Posted: Wed Oct 30, 2013 10:53 am
by TomDoan
The version 6 procedure for this was called CNDITION (without the O) and had a different syntax---it used parameters rather than options. If you just have the one program, I would probably just re-do the procedure call to use the more modern syntax. Otherwise, use this instead:
Code: Select all
*
* CNDITION.SRC
* Computes conditional forecasts. See Section 10.14 of the Manual
*
* Syntax:
*
* @CNDITION( options ) model steps start VCV Matrix constraints forecasts
* # series entry value (one for each constraint)
*
* or
*
* @CNDITION(GENERAL,other options ) model steps start VCV Matrix constraints forecasts
* # vector with linear combination of endogenous variables (one pair for each constraint)
* # entry value
*
* model = VAR model used for forecasts
* steps = number of forecast steps
* start = start period of forecast
* VCV Matrix = SYMMETRIC covariance matrix of residuals. The rows must
* correspond to equations in order
* constraints = number of constraints on future values
* forecasts = VECT[SERIES] containing the constrained forecasts. This
* is returned by the procedure.
*
* Supplementary Cards, first type (one for each constraint)
* series = endogenous variable constrained
* entry = entry of constraint
* value = target value
*
* Supplementary Cards, second type (one of each for each constraint)
* vector ... = VECTOR or real numbers/expressions with linear combination of
* endogenous variables to constrain
* entry = entry of constraint
* value = target value for the linear combination
*
* Options
* general/[nogeneral] use GENERAL to use constraints on linear combinations of series, rather
* than on individual variables
* shocks = VECT[SERIES] with the orthogonalized shocks used
* decomp = factorization matrix [Choleski factor of VCV matrix]
* simulate/[nosimulate] if simulated, draws randomly from the constrained density
*
* Revision Schedule
* 12/03 SIMULATE option added
* 01/05 GENERAL option added
*
procedure cndition model nfore nbeg vmat nconstr fcstout
type model model
type integer nfore nbeg nconstr
type vect[series] *fcstout
type symmetric vmat
*
option switch simulate 0
option rect decomp
option vect[series] *shocks
option switch general 0
*
local integer nvar
local index step var
local vector value
local integer i j nsteps nfree constr consentr enumber
local rect capr uover vover vdecomp overr
local vect lowr u v
local rect[series] impfunc
local vect[integer] depvars
local vect[vect] lcomb
local symm rrrr
*
* Process supplementary cards for PROCEDURE.
*
dimension step(nconstr) var(nconstr) value(nconstr) lcomb(nconstr)
*
compute nvar=%modelsize(model)
compute nsteps=0
do i=1,nconstr
if .not.general
enter var(i) step(i) value(i)
else {
dim lcomb(i)(nvar)
enter lcomb(i)
enter step(i) value(i)
}
compute step(i)=step(i)-nbeg+1
if step(i)>nsteps ; compute nsteps=step(i)
end do i
*
* Replace VAR(I) with the equation which has VAR(I) as its dependent
* variable.
*
compute depvars=%modeldepvars(model)
if .not.general {
do i=1,nconstr
compute enumber=0
do j=1,nvar
if var(i)==depvars(j) {
compute enumber=j
break
}
end do j
if enumber==0 {
display 'Constraints Must Use One of the Endogenous Variables'
display 'Please Check Constraint Number' I
return
}
compute var(i)=enumber
end do i
}
if %defined(decomp)
compute vdecomp=decomp
else
compute vdecomp=%decomp(vmat)
forecast(model=model,results=fcstout) * nsteps nbeg
impulse(model=model,results=impfunc,noprint,decomp=vdecomp) * nsteps *
compute nfree=nvar*nsteps
dimension capr(nfree,nconstr) vdecomp(nvar,nvar)
dimension u(nfree) v(nfree) lowr(nconstr)
do constr=1,nconstr
if .not.general
compute lowr(constr)=value(constr)-fcstout(var(constr))(step(constr)+nbeg-1)
else
compute lowr(constr)=value(constr)-%dot(lcomb(constr),%xt(fcstout,step(constr)+nbeg-1))
overlay capr(1,constr) with overr(nsteps,nvar)
compute consentr=1+step(constr)
if .not.general
ewise overr(i,j)=%if(i<consentr,impfunc(var(constr),j)(consentr-i),0.0)
else
ewise overr(i,j)=%if(i<consentr,%dot(lcomb(constr),%xcol(%xt(impfunc,consentr-i),j)),0.0)
end do constr
*
* Compute optimal orthogonalized V
*
compute v=capr*inv( tr(capr)*capr )*lowr
overlay u(1) with uover(nsteps,nvar)
overlay v(1) with vover(nsteps,nvar)
*
* If simulations are requested, do a draw from the constrained
* density for the orthogonal shocks
*
if simulate {
compute rrrr=%identity(nsteps*nvar)-capr*inv(tr(capr)*capr)*tr(capr)
compute v=v+%ranmvnormal(%decomp(rrrr))
}
*
* Transform to non-orthogonal U
*
compute uover=vover*tr(vdecomp)
*
* Save the orthogonalized shocks
*
if %defined(shocks) {
dim shocks(nvar)
do i=1,nvar
set shocks(i) nbeg nbeg+nsteps-1 = vover(t-nbeg+1,i)
end do i
}
*
* Forecast with U shocks
*
forecast(model=model,matrix=uover,results=fcstout) * nfore nbeg
end cndition
Re: Help with error please
Posted: Thu Oct 31, 2013 4:25 am
by Ozmando
TomDoan wrote:The version 6 procedure for this was called CNDITION (without the O) and had a different syntax---it used parameters rather than options. If you just have the one program, I would probably just re-do the procedure call to use the more modern syntax. Otherwise, use this instead:
Code: Select all
*
* CNDITION.SRC
* Computes conditional forecasts. See Section 10.14 of the Manual
*
* Syntax:
*
* @CNDITION( options ) model steps start VCV Matrix constraints forecasts
* # series entry value (one for each constraint)
*
* or
*
* @CNDITION(GENERAL,other options ) model steps start VCV Matrix constraints forecasts
* # vector with linear combination of endogenous variables (one pair for each constraint)
* # entry value
*
* model = VAR model used for forecasts
* steps = number of forecast steps
* start = start period of forecast
* VCV Matrix = SYMMETRIC covariance matrix of residuals. The rows must
* correspond to equations in order
* constraints = number of constraints on future values
* forecasts = VECT[SERIES] containing the constrained forecasts. This
* is returned by the procedure.
*
* Supplementary Cards, first type (one for each constraint)
* series = endogenous variable constrained
* entry = entry of constraint
* value = target value
*
* Supplementary Cards, second type (one of each for each constraint)
* vector ... = VECTOR or real numbers/expressions with linear combination of
* endogenous variables to constrain
* entry = entry of constraint
* value = target value for the linear combination
*
* Options
* general/[nogeneral] use GENERAL to use constraints on linear combinations of series, rather
* than on individual variables
* shocks = VECT[SERIES] with the orthogonalized shocks used
* decomp = factorization matrix [Choleski factor of VCV matrix]
* simulate/[nosimulate] if simulated, draws randomly from the constrained density
*
* Revision Schedule
* 12/03 SIMULATE option added
* 01/05 GENERAL option added
*
procedure cndition model nfore nbeg vmat nconstr fcstout
type model model
type integer nfore nbeg nconstr
type vect[series] *fcstout
type symmetric vmat
*
option switch simulate 0
option rect decomp
option vect[series] *shocks
option switch general 0
*
local integer nvar
local index step var
local vector value
local integer i j nsteps nfree constr consentr enumber
local rect capr uover vover vdecomp overr
local vect lowr u v
local rect[series] impfunc
local vect[integer] depvars
local vect[vect] lcomb
local symm rrrr
*
* Process supplementary cards for PROCEDURE.
*
dimension step(nconstr) var(nconstr) value(nconstr) lcomb(nconstr)
*
compute nvar=%modelsize(model)
compute nsteps=0
do i=1,nconstr
if .not.general
enter var(i) step(i) value(i)
else {
dim lcomb(i)(nvar)
enter lcomb(i)
enter step(i) value(i)
}
compute step(i)=step(i)-nbeg+1
if step(i)>nsteps ; compute nsteps=step(i)
end do i
*
* Replace VAR(I) with the equation which has VAR(I) as its dependent
* variable.
*
compute depvars=%modeldepvars(model)
if .not.general {
do i=1,nconstr
compute enumber=0
do j=1,nvar
if var(i)==depvars(j) {
compute enumber=j
break
}
end do j
if enumber==0 {
display 'Constraints Must Use One of the Endogenous Variables'
display 'Please Check Constraint Number' I
return
}
compute var(i)=enumber
end do i
}
if %defined(decomp)
compute vdecomp=decomp
else
compute vdecomp=%decomp(vmat)
forecast(model=model,results=fcstout) * nsteps nbeg
impulse(model=model,results=impfunc,noprint,decomp=vdecomp) * nsteps *
compute nfree=nvar*nsteps
dimension capr(nfree,nconstr) vdecomp(nvar,nvar)
dimension u(nfree) v(nfree) lowr(nconstr)
do constr=1,nconstr
if .not.general
compute lowr(constr)=value(constr)-fcstout(var(constr))(step(constr)+nbeg-1)
else
compute lowr(constr)=value(constr)-%dot(lcomb(constr),%xt(fcstout,step(constr)+nbeg-1))
overlay capr(1,constr) with overr(nsteps,nvar)
compute consentr=1+step(constr)
if .not.general
ewise overr(i,j)=%if(i<consentr,impfunc(var(constr),j)(consentr-i),0.0)
else
ewise overr(i,j)=%if(i<consentr,%dot(lcomb(constr),%xcol(%xt(impfunc,consentr-i),j)),0.0)
end do constr
*
* Compute optimal orthogonalized V
*
compute v=capr*inv( tr(capr)*capr )*lowr
overlay u(1) with uover(nsteps,nvar)
overlay v(1) with vover(nsteps,nvar)
*
* If simulations are requested, do a draw from the constrained
* density for the orthogonal shocks
*
if simulate {
compute rrrr=%identity(nsteps*nvar)-capr*inv(tr(capr)*capr)*tr(capr)
compute v=v+%ranmvnormal(%decomp(rrrr))
}
*
* Transform to non-orthogonal U
*
compute uover=vover*tr(vdecomp)
*
* Save the orthogonalized shocks
*
if %defined(shocks) {
dim shocks(nvar)
do i=1,nvar
set shocks(i) nbeg nbeg+nsteps-1 = vover(t-nbeg+1,i)
end do i
}
*
* Forecast with U shocks
*
forecast(model=model,matrix=uover,results=fcstout) * nfore nbeg
end cndition
Hi Tom,
Thanks so much again. Need to clarify that I am using rats 8.2 (although the program that I am trying to run was written by someone using Rats 6.0). I have, therefore, changed the "
CNDITION" to the "
CONDITION". I have done all changes in the source code accordingly.
I am going through the code step by step to understand the source of the problem.
thanks,
Oz
Re: Help with error please
Posted: Sat Nov 02, 2013 5:28 am
by Ozmando
Many thanks Tom for your help.
Both @CNDITION and @CONDITION are working fine with RATS 8.2
Much appreciated.
oz