Hints for "for" loop in nested hierarchy

For questions regarding programming in the EViews programming language.

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

Chthoniid
Posts: 24
Joined: Mon Oct 22, 2012 6:02 pm

Hints for "for" loop in nested hierarchy

Postby Chthoniid » Tue Oct 22, 2019 7:36 pm

My data is organised as following hierarchy:
1843 subjects, each with 9 sets of questions across 4 alternatives.

For each set of 4 alternatives I want to find the highest value of one variable (if it is present). So everything I do I want to do on each set of 4 alternatives.

for !i=1 to 1843
for !j= 1 to 9
for !k=1 to 4
smpl if !i=id and !j =survey_qnumber and !k=alternative
smpl if type1=1
series wildp=@maxsby(price, alternative)
next
next
next

However, this returns the highest price across all 1843 rows, not the highest price in each subset of 4 alternatives. I know my programming is pretty rusty, so if anyone can identify what I'm doing wrong and what would work instead, I'd love a few hints.

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

Re: Hints for "for" loop in nested hierarchy

Postby EViews Gareth » Tue Oct 22, 2019 9:12 pm

You'll need to be more specific as to how the data are set up in EViews.
1843 subjects, each with 9 sets of questions across 4 alternatives.

Does not describe data in EViews.
Follow us on Twitter @IHSEViews

Chthoniid
Posts: 24
Joined: Mon Oct 22, 2012 6:02 pm

Re: Hints for "for" loop in nested hierarchy

Postby Chthoniid » Wed Oct 23, 2019 1:49 pm

Ah, sorry.
I import the data from a csv file, as unstructured data.
Screenshot added.
ID is the highest level, this branches into sruvey_qnumber (1-9) and this branches into 1-4 alternatives.

My goal is to collate and aggregate each of the 4 alternative rows into one row, using select variable values across the 4 rows. So for instance, I want the maximum price (column w) for each type 1 (column H) reduced to a single row of data at the end of the program.

TIA, B
Last edited by Chthoniid on Thu Oct 24, 2019 9:21 pm, edited 2 times in total.

Chthoniid
Posts: 24
Joined: Mon Oct 22, 2012 6:02 pm

Re: Hints for "for" loop in nested hierarchy

Postby Chthoniid » Thu Oct 24, 2019 6:22 pm

Got it all figured


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 55 guests