parsimonious representation

Use this forum to post questions about syntax problems or general programming issues. Questions on implementing a particular aspect of econometrics should go in "Econometrics Issues" below.
b_lobo
Posts: 14
Joined: Mon Sep 02, 2013 6:38 pm

parsimonious representation

Unread post by b_lobo »

Two questions related to a portion of code below:
1. How would I write the constraints and compute statements parsimoniously using perhaps %dot(A,B)? I've tried %dot(w(i),bx(n(i)))==z, but that doesn't seem to be right
2. How can I generate statistics on the series PRETZB, PBETAZB and PDURZB by "j" (i.e. quarters)? Note that there would be 126 observations each quarter


compute z = 1.0 ; * beta constraint
*
do draw=1,126
compute n = mycombos(draw) ; * this draws from the 252/126 combinations
do j=1,30 ; * looping through quarters

dec vect bx(10) dx(10) rx(10) w(10) ; * there are 10 cross-sections (x)
ewise bx(i) = b(i+(10*(j-1)))
ewise dx(i) = d(i+(10*(j-1)))
ewise rx(i) = r(i+(10*(j-1)))

NONLIN(parmset=base) w1 w2 w3 w4 w5 w6 w7 w8 w9 w10
NONLIN(parmset=constraint) w1+w2+w3+w4+w5==1.0 w6+w7+w8+w9+w10==-1.0 $
w1*bx(n(1))+w2*bx(n(2))+w3*bx(n(3))+w4*bx(n(4))+w5*bx(n(5))+w6*bx(n(6))+w7*bx(n(7))+w8*bx(n(8))+w9*bx(n(9))+w10*bx(n(10))==z


COMPUTE w1=w2=w3=w4=w5=w6=w7=w8=w9=w10=0.0 ; * initial values

FIND(parmset=base+constraint,noprint,method=bfgs) ROOT w1*bx(n(1))+w2*bx(n(2))+w3*bx(n(3))+w4*bx(n(4))+w5*bx(n(5))+w6*bx(n(6))+w7*bx(n(7))+w8*bx(n(8))+w9*bx(n(9))+w10*bx(n(10))
END FIND

compute PRETZB = w1*rx(n(1))+w2*rx(n(2))+w3*rx(n(3))+w4*rx(n(4))+w5*rx(n(5))+w6*rx(n(6))+w7*rx(n(7))+w8*rx(n(8))+w9*rx(n(9))+w10*rx(n(10))
compute PBETAZB = w1*bx(n(1))+w2*bx(n(2))+w3*bx(n(3))+w4*bx(n(4))+w5*bx(n(5))+w6*bx(n(6))+w7*bx(n(7))+w8*bx(n(8))+w9*bx(n(9))+w10*bx(n(10))
compute PDURZB = w1*Dx(n(1))+w2*Dx(n(2))+w3*Dx(n(3))+w4*Dx(n(4))+w5*Dx(n(5))+w6*Dx(n(6))+w7*Dx(n(7))+w8*Dx(n(8))+w9*Dx(n(9))+w10*Dx(n(10))
*
end do j
end do draw
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: parsimonious representation

Unread post by TomDoan »

b_lobo wrote:Two questions related to a portion of code below:
1. How would I write the constraints and compute statements parsimoniously using perhaps %dot(A,B)? I've tried %dot(w(i),bx(n(i)))==z, but that doesn't seem to be right
It would be %dot(w,bx) if it weren't for the re-ordering of bx. The simplest thing to do is to write a FUNCTION with a DO loop:

Code: Select all

function mydot
local integer i
compute mydot=0.0
do i=1,10
   compute mydot=mydot+w(i)*bx(n(i))
end do i
end
then use mydot()==z

b_lobo wrote: 2. How can I generate statistics on the series PRETZB, PBETAZB and PDURZB by "j" (i.e. quarters)? Note that there would be 126 observations each quarter
As written, you're creating them as simple real variables, so they get overwritten. Instead, you would need to create them as SERIES and fill in entries in the series. Is there any particular reason that you're nesting the loops with DRAW on the outside rather than J? It sounds looping over DRAW on the inside would be more natural.
b_lobo
Posts: 14
Joined: Mon Sep 02, 2013 6:38 pm

Re: parsimonious representation

Unread post by b_lobo »

I need each draw (i.e. a unique combination) to cycle through 30 quarters. Nesting the j loop inside the draw loop became necessary when I was using %ranpermute so as to preserve the same combination through all 30 qtrs. I guess I could nest the draw loop inside the j loop if I use a set number of combinations. I'd still like to have the flexibility to run %ranpermute though.
Post Reply