2 Stage Loop with 2 smpl commands

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

blue2011
Posts: 18
Joined: Sat Mar 26, 2011 3:16 pm

2 Stage Loop with 2 smpl commands

Postby blue2011 » Fri Apr 01, 2011 10:54 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13603
Joined: Tue Sep 16, 2008 5:38 pm

Re: 2 Stage Loop with 2 smpl commands

Postby EViews Gareth » Sat Apr 02, 2011 12:26 am

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

blue2011
Posts: 18
Joined: Sat Mar 26, 2011 3:16 pm

Re: 2 Stage Loop with 2 smpl commands

Postby blue2011 » Sat Apr 02, 2011 6:59 am

Thank you so much Gareth! The program now does what it is supposed to do.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests