Cumulative sum by series - how do it quickly?

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Steve, EViews Moderator, EViews Jason

adrian_d
Posts: 44
Joined: Wed Jan 29, 2014 6:08 am

Cumulative sum by series - how do it quickly?

Postby adrian_d » Thu Feb 12, 2015 1:42 am

Hello,
in Eviews there are many functions to make cumulative sums and to make statsby, but I cannot solve the kind of "cumulative by" problem. The problem is to have a series with counted occurence of specific values of the other series, within each ID variable separately.
Please find attached the workfile, it is unstructured/undated workfile, and there:
- CONVERSION_ID is our variable, that we want to group by
- INTERACTION_CHANNEL is the variable with categories, that we want to calculate occurence of, within the Conversion IDs
- INTERACTION_DATE_TIME is the exact date of each instance of interaction channel - maybe it will be helpful to have it
- OCCURENCE is what we want to achieve - I fill in the values manually, to ilustrate you how it should look like.

Is it possible to automize it smartly in Eviews (v. 8.1) ?

thanks
adrian
Attachments
cumulative sum problem.wf1
(10.53 KiB) Downloaded 843 times

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

Re: Cumulative sum by series - how do it quickly?

Postby EViews Gareth » Thu Feb 12, 2015 8:53 am

Probably an easier way, but:

Code: Select all

vector ids = @uniquevals(conversion_id) svector chns = @uniquevals(interaction_channel) for !i=1 to @rows(ids) for !j=1 to @rows(chns) %chn = chns(!j) smpl if conversion_id = ids(!i) and interaction_channel=%chn series temp = 1 series occ = @cumsum(temp) delete temp next next smpl @all

adrian_d
Posts: 44
Joined: Wed Jan 29, 2014 6:08 am

Re: Cumulative sum by series - how do it quickly?

Postby adrian_d » Thu Feb 12, 2015 9:12 am

Probably an easier way, but:

Code: Select all

vector ids = @uniquevals(conversion_id) svector chns = @uniquevals(interaction_channel) for !i=1 to @rows(ids) for !j=1 to @rows(chns) %chn = chns(!j) smpl if conversion_id = ids(!i) and interaction_channel=%chn series temp = 1 series occ = @cumsum(temp) delete temp next next smpl @all
Okay, it's quite similar to what I've tried, not too quick when I have thousands of conversion ids, but thanks. Maybe it would be good idea to take such a function into consideration in the upcoming Eviews updates.

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

Re: Cumulative sum by series - how do it quickly?

Postby EViews Gareth » Thu Feb 12, 2015 2:01 pm

EViews Glenn came up with a, possibly, faster solution:

Code: Select all

series id = @trend+1 pagestruct(create) conversion_id interaction_channel series occ=@trend+1 pagestruct(none) sort id

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

Re: Cumulative sum by series - how do it quickly?

Postby EViews Glenn » Thu Feb 12, 2015 7:04 pm

I think you need to recode at the end to handle the blanks in interaction_channel:

Code: Select all

occ = @recode(interaction_channel="", NA, occ)

adrian_d
Posts: 44
Joined: Wed Jan 29, 2014 6:08 am

Re: Cumulative sum by series - how do it quickly?

Postby adrian_d » Fri Feb 13, 2015 2:18 am

Yeah, making this pagestruct and @trend is great, thank you very much guys!

kche260532
Posts: 4
Joined: Thu Aug 19, 2021 10:45 pm

Re: Cumulative sum by series - how do it quickly?

Postby kche260532 » Fri Aug 20, 2021 4:38 pm

Hi EViews team,

Sorry to have a follow up question on a post 6 years ago. I got an exact issue that ardian_d came across. Gareth and Glenn's solutions both work well on the issue until more recently I got a big dataset that involves 3 million observations. Eviews couldn't do the "pagestruct" as the group variable consists of 1.2 million groups. That exceeds the limit of "pagestruct"; whereas the loop from Gareth will take me around 13 days to complete the looping. For the time being, I try R; and use dplyr mydata %>% group_by(group, obs) %>% mutate(myorder = 1:n()) to complete the task. But I would be grateful if I can have a solution to program that in Eviews, to save some hiccups in switching in between software.


Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 2 guests