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?
Summing over a column by another variable
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
EViews Glenn
- EViews Developer
- Posts: 2682
- Joined: Wed Oct 15, 2008 9:17 am
Re: Summing over a column by another variable
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?
Re: Summing over a column by another variable
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!
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
Try this...
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.
Code: Select all
series year = @recode(month>=1 and month<=12, 1, 2)
series xbyearandid = @sumsby(x, year, id)Re: Summing over a column by another variable
Works like a charm :D Thank you!
Who is online
Users browsing this forum: No registered users and 2 guests
