Summing elements of vector series

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.
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Summing elements of vector series

Unread post by rbelhach95 »

Dear Tom,

I have a vector series R(rep) of 5000 monthly returns, I used

Code: Select all

sample(smpl=%valid(R(rep))) R(rep) / goodsource 

to throw away the NAs. I would like to randomly sum up 12 of these goodsource returns, then replicate this process 61 times, i.e. obtain 61 annual returns
Please advise. Thank you
Rachid
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Summing elements of vector series

Unread post by TomDoan »

This will do the sum for one set of 12. You would just have to loop over the last two instructions.

Code: Select all

sample(smpl=%valid(R(rep))) R(rep) / goodsource
compute goodnobs=%nobs
boot entries 1 12 1 %nobs
sstats 1 12 goodsource(entries(t))>>sumof12
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Summing elements of vector series

Unread post by rbelhach95 »

Many thanks for your help. I have the ewise instruction in my code below, how do I loop over those two instruction? I would like sumof12 to be as shown in my code (Rtstr(i,j)) but it gives error. Thanks
Rachid

Code: Select all

com N= 5000, M= 61,  P=1000
dec rec T3 ST Call Rtstr Callav
dim T3(M,P) Rtstr(M,P) ST(M,P) Call(M,P)  Callav(M,P)
.........
sample(smpl=%valid(R(rep))) R(rep) / goodsource
compute goodnobs=%nobs
boot entries 1 12 1 %nobs
sstats 1 12 goodsource(entries(t))>>sumof12
ewise T3(i,j) = T2(j)-T1(i)
ewise Rtstr(i,j) = (r2(i)-div(i)+sumof12(i))*T3(i,j)/365
ewise ST(i,j) = %if(T3(i,j)>0, S(i)*exp(Rtstr(i,j)),%na)
ewise Call(i,j) = %if(T3(i,j)>0,exp(-r2(i)*T3(i,j)/365)*%max(0,ST(i,j)-K(j)),%na)
com Callsum = Callsum+Call
end do rep
com Callav = Callsum/N
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Summing elements of vector series

Unread post by TomDoan »

Code: Select all

sample(smpl=%valid(R(rep))) R(rep) / goodsource
compute goodnobs=%nobs
dec vect sumof12(m)
do i=1,m
   boot entries 1 12 1 goodnobs
   sstats 1 12 goodsource(entries(t))>>sumof12(i)
end do i
rbelhach95
Posts: 115
Joined: Sat Feb 09, 2013 9:30 am

Re: Summing elements of vector series

Unread post by rbelhach95 »

Thanks a lot Tom
Rachid
Post Reply