Page 1 of 1

2 Stage Loop with 2 smpl commands

Posted: Fri Apr 01, 2011 10:54 pm
by blue2011
Dear Forum Members

First of all, I thank you for taking your time to read my question. In my workfile, I have stocks returns, an identifier for decile and another identifier for month. What I would like to do is:

First, sort the returns in each decile (I have 10 deciles in total)
Second, compute the average monthly returns by using the identifier for month in each decile.

I came up with the following code:

matrix(10,12) decilem

for !j=1 to 10 '10 deciles in total
smpl if decile_id=!j
for !i=1 to 12 '12 months in total
smpl if month_id=!i
decilem(!j,!i)=@mean(m_returns)
next
next

When I run this code, Eviews completely ignores the deciles and spits out the monthly averages for the whole sample. I would really appreciate if you could point out to me where I am making a mistake in this code.

Thank you

Re: 2 Stage Loop with 2 smpl commands

Posted: Sat Apr 02, 2011 12:26 am
by EViews Gareth

Code: Select all

for !j=1 to 10 '10 deciles in total for !i=1 to 12 '12 months in total smpl if month_id=!i and decile_id=!j decilem(!j,!i)=@mean(m_returns) next next

Re: 2 Stage Loop with 2 smpl commands

Posted: Sat Apr 02, 2011 6:59 am
by blue2011
Thank you so much Gareth! The program now does what it is supposed to do.