Hints for "for" loop in nested hierarchy
Posted: 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.
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.