Page 1 of 1

Hints for "for" loop in nested hierarchy

Posted: Tue Oct 22, 2019 7:36 pm
by Chthoniid
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.

Re: Hints for "for" loop in nested hierarchy

Posted: Tue Oct 22, 2019 9:12 pm
by EViews Gareth
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.

Re: Hints for "for" loop in nested hierarchy

Posted: Wed Oct 23, 2019 1:49 pm
by Chthoniid
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

Re: Hints for "for" loop in nested hierarchy

Posted: Thu Oct 24, 2019 6:22 pm
by Chthoniid
Got it all figured