Page 1 of 1

Modified UhligAccept

Posted: Tue Mar 29, 2011 10:39 am
by jonasdovern
I modified the UhligAccept function to be able to provide different number of periods for the constrains for different variables.

I know that this is done also in a lot of papers that are around; thus, it might be helpful for some RATS users.

Code: Select all

**************************************************************************
* UhligAccept2(q,first,last,constrained) returns a 1 (accept) or 0
* (reject) for the weight vector <<q>> (applied to the impulse responses
* in the global RECT[SERIES] impulses). <<first>> and <<last>> are the
* range of responses constrained (1 = impact response). <<constrained>>
* is a VECT[INTEGER] with the variable positions being constrained. Use
* +slot for a positivity constraint and -slot for a negativity
* constraint. That is, if you want the first 4 responses to be positive
* on the 2nd variable and the first 3 negative on the 3rd, you would use the function
*
* UhligAccept2(q,||1,1||,||4,3||,||2,-3||)
*
* If this returns 0, you would reject the draw, as not meeting the
* constraints.
*
function UhligAccept2 q first last constrained
type integer   UhligAccept2
type vector    *q
type vec[int]  first last
type vect[int] constrained
*
local integer      i k
local vector       ik
dec   rect[series] impulses
*
if %rows(first)<>%rows(constrained).or.%rows(last)<>%rows(constrained) {
	disp "Error. Dimensions do not match!"
	return
}
do i=1,%rows(constrained)
	do k=first(i),last(i)
   		compute ik=%xt(impulses,k)*q
      	if constrained(i)<0
         	compute value= ik(-constrained(i))
      	else
         	compute value=-ik(constrained(i))
      	if value>0.0 {
         	*
         	* If we fail on the first slot being checked, just flip the sign
         	* of q and ik and continue.
         	*
         	if k==first(i).and.i==1
            	compute q=-1.0*q,ik=-1.0*ik
         	else {
            	compute UhligAccept2=0
            	return
         	}
      	}
   	end do k
end do i
compute UhligAccept2=1
end
**************************************************************************