bayesian VAR with Gibbs

Questions and discussions on Vector Autoregressions
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

bayesian VAR with Gibbs

Unread post by sanjeev »

I am trying to run the GibbsVAR code for my VAR. I have exogenous variables other than the constant in my VAR. each time i try to run the code i get the following error message,

## MAT3. Matrix with Dimensions 52 x 52 Involved in Left out of table Operation. Need Size of CMOM to be Regressors + Equations
The Error Occurred At Location 63, Line 6 of loop/block.

If however I run the code without the exogenous variables, the code runs. I will be grateful for any help.
Thanks in advance.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: bayesian VAR with Gibbs

Unread post by TomDoan »

This sets up the prior based upon the assumption that the CONSTANT is the only deterministic variable (that's the +1 in the first working line). You have to change that to allow for the added exogenous variables. Do you know how you're handling the prior on those?

Code: Select all

*
* Create the prior mean and (square root of) precision. The olssee
* values are used to scale the precision. The prior mean is 1 for the
* first own lag in each equation, and 0 otherwise. The constant is given
* a mean of zero with a zero precision (that is, a flat prior).
*
compute ncoef=lags*nvar+1
dec rect minnmean(ncoef,nvar) minnprec(ncoef,nvar)
*
do i=1,nvar
   do j=1,nvar
      do l=1,lags
         compute minnmean((j-1)*lags+l,i)=(i==j.and.l==1)
         compute minnprec((j-1)*lags+l,i)=olssee(j)/olssee(i)*%if(i==j,1.0/tight,1.0/(other*tight))
      end do l
   end do j
   compute minnmean(ncoef,i)=0.0,minnprec(ncoef,i)=0.0
end do i
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

Re: bayesian VAR with Gibbs

Unread post by sanjeev »

Thanks for the change required in the code. I am using the mixed estimation technique with standard priors. Therefore the priors on the exogenous variables are non informative. I will welcome suggestions on the same. Thanks in advance
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: bayesian VAR with Gibbs

Unread post by TomDoan »

This is setting the mean and precision of the constant (only DETERMINISTIC in this model) to zero. You would have to do that for all the variables. Probably the easiest thing is to zero out the whole minnmean and minnprec matrices (with %zeros) before setting the lag information for the lag coefficients.

compute minnmean(ncoef,i)=0.0,minnprec(ncoef,i)=0.0
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

Re: bayesian VAR with Gibbs

Unread post by sanjeev »

Thanks for the response. Am I correct in my understanding that the prior used by the Gibbsvar program is the Normal Diffuse, ie the same as the mixed estimation the only difference being that the Gibbsvar considers the full model? In case that is the case is it possible to alter the priors to Normal Wishart independent?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: bayesian VAR with Gibbs

Unread post by TomDoan »

GIBBSVAR does do Normal-Diffuse. The whole point is that it's not the same as mixed estimation---mixed estimation basically adjusts the prior to be proportional to the residual variance, which is computationally convenient, but not realistic.

If you have a prior for the Wishart (most people don't), then you just incorporate that into the draw for sigmad inside the loop.
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

Bayesian VAR with GibbsVar

Unread post by sanjeev »

I am running the bayesian VAR using Gibbs full Var program. I am informed that my matrix is non invertible.

## MAT14. Non-invertible Matrix. Using Generalized Inverse for SYMMETRIC.
The Error Occurred At Location 63, Line 6 of loop/block
. I will be grateful for any help. I am also attaching the data and the programme file.
Attachments
newdatawithchangedvols1dror.xls
(118 KiB) Downloaded 754 times
exchangerategibbs.RPF
(3.57 KiB) Downloaded 1073 times
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: bayesian VAR with Gibbs

Unread post by TomDoan »

I'm not sure what this is supposed to do, but it clearly isn't right for a four variable VAR:

do i=1,2
compute minnmean(ncoef,i)=0.0,minnprec(ncoef,i)=0.0
end do i
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

Re: bayesian VAR with Gibbs

Unread post by sanjeev »

I was trying to give flat priors on the exogenous variables with an informative prior on the endogenous variables, which evidently failed. However if I run the programme without these commands I still get the same error. Will be grateful for any help.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: bayesian VAR with Gibbs

Unread post by TomDoan »

I believe I mentioned above that the easiest way to handle that was to zero out the whole matrix before setting the priors:

compute ncoef=lags*nvar+2
dec rect minnmean(ncoef,nvar) minnprec(ncoef,nvar)
compute minnmean=%const(0.0)
compute minnprec=%const(0.0)

That do loop is in the wrong place and is zeroing out the wrong elements.

You also have the problem that you need to extend your dummy out to the end of the forecast period.
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

Re: bayesian VAR with Gibbs

Unread post by sanjeev »

Thanks I was able to incorporate the exog. variables in to Gibbs VAR with your help. There are two other issues that I wanted to bring to your notice. If I want to use general priors using the Gibbsvar code , is it possible to do the same since I want to give different importance to different variables in my bayesian VAR estimation? Secondly is it sensible to compare the forecasts of the full VAR model (using Gibbsvar), where the forreasts are simulated forecasts with the point forecasts that we get using the mixed estimation technique?
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

Re: bayesian VAR with Gibbs

Unread post by sanjeev »

You did mention that it I am taking an inverted Wishart as a prior I will have to account for that in the loop sigmad in the gibbsvarcode. Is the following the correct change in the code.

end do i
do i=1,2
compute minnmean(ncoef,i)=0.0,minnprec(ncoef,i)=0.0
end do i
ewise minnprec(i,j)=minnprec(i,j)^2
compute hprior=%diag(%vec(minnprec))
compute bprior=minnmean
*
compute fwish = %decomp(inv(%nobs*%sigma))
compute wishdof = %nobs - %nreg
compute sigmad = %ranwisharti(fwish,wishdof)[/b]

cmom(model=varmodel)
*
Thanks for your patience and help.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: bayesian VAR with Gibbs

Unread post by TomDoan »

First of all

do i=1,2
compute minnmean(ncoef,i)=0.0,minnprec(ncoef,i)=0.0
end do i

should be gone. It doesn't do what you wanted and isn't necessary.


For an informative Wishart prior, you need to add to RSSMAT the scale parameter for the I-Wishart prior and change the degrees of freedom in the %RANWISHARTI call.

compute rssmat=%sigmacmom(%cmom,bdraw)
*
* Draw sigma given b
*
compute sigmad=%ranwisharti(%decomp(inv(rssmat)),%nobs)
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: bayesian VAR with Gibbs

Unread post by TomDoan »

sanjeev wrote:Thanks I was able to incorporate the exog. variables in to Gibbs VAR with your help. There are two other issues that I wanted to bring to your notice. If I want to use general priors using the Gibbsvar code , is it possible to do the same since I want to give different importance to different variables in my bayesian VAR estimation?
Sure, but you have to provide an alternative mean and precision matrix for the system.
sanjeev wrote: Secondly is it sensible to compare the forecasts of the full VAR model (using Gibbsvar), where the forreasts are simulated forecasts with the point forecasts that we get using the mixed estimation technique?
The average of the simulations can be compared to the point forecasts.
sanjeev
Posts: 191
Joined: Mon Jun 18, 2012 6:51 am

Re: bayesian VAR with Gibbs

Unread post by sanjeev »

How many simulations should be averaged over for the comparison with point forecasts. Thanks for the prompt reply as always.
Post Reply