Summing over a column by another variable

For questions regarding programming in the EViews programming language.

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

Lynn_NL
Posts: 3
Joined: Wed Jun 01, 2011 3:11 am

Summing over a column by another variable

Postby Lynn_NL » Wed Jun 01, 2011 5:54 am

I'm trying to sum one series by another variable.

I have data on incomes for each month for each panelmember (so I have a panel member identifier, a month identifier and a value on income). What I would like to have is a panelmember's yearly income. So I would like to sum the incomes over 12 months per panelmember.

My data is not structured as a paneldataset (nor do I wish to do so, because it would mess up some of my other program code). Is there an easy way to do this in Eviews?

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Summing over a column by another variable

Postby EViews Glenn » Wed Jun 01, 2011 8:22 am

Summing by panel member is easy. Aggregating across months to give yearly totals is less so since that operation requires date information unless you have a year series (which you don't explicitly say that you do). How is your dataset structured? How many cross-sections and years?

Lynn_NL
Posts: 3
Joined: Wed Jun 01, 2011 3:11 am

Re: Summing over a column by another variable

Postby Lynn_NL » Wed Jun 01, 2011 10:16 am

Hi Glenn,

Thanks for the quick reply!

Unfortunately, I don't have a year variable. I only have a month variable that runs from month 1 to month 21. And I have 50 panel members (cross-sections). So my dataset has 21*50=1050 observations

I don't need to have a yearly income for each year that I have available. It would suffice if I could just obtain their year income for the first 12 months (that would mean 50 income values, one for each panel member). So what I could do is create a sample range which includes only all observations smaller than month 13. The following should work right?
sample months12 @all if month<14

In that case, I think I should be able to aggregate all incomes by panelmember (or cross-section). Could you maybe explain how I can do that?

Thanks again for your help!

EViews Glenn
EViews Developer
Posts: 2682
Joined: Wed Oct 15, 2008 9:17 am

Re: Summing over a column by another variable

Postby EViews Glenn » Wed Jun 01, 2011 2:06 pm

Try this...

Code: Select all

series year = @recode(month>=1 and month<=12, 1, 2) series xbyearandid = @sumsby(x, year, id)
I'm recoding your month variable to the "first twelve months" and the remaining months. There are other ways to perform this recoding. Then we compute the sums by both the coded year and the id variable.

Lynn_NL
Posts: 3
Joined: Wed Jun 01, 2011 3:11 am

Re: Summing over a column by another variable

Postby Lynn_NL » Sat Jun 04, 2011 7:06 am

Works like a charm :D Thank you!


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 1 guest