Hi,
I've a data set with two observations each for 12 different sport matches - one obs per team.
var match_id
var team
var win: win dummy
var prob: ex ante probability of team i winning match j.
What I'm interested in is identifying consecutive wins of a team and the probability of that run (i.e. the product of the ex ante probabilities of the matches consecutively won prior to match j)
I generate the var counter giving me prior consecutive wins as follows.
sort team match_id
gen counter=0
by team: replace counter = counter[_n-1]+1 if win[_n-1] == 1
Now my question: How do I calculate the product of the x = counter last values of prob?
E.g. for the third obs below I'd like to calculate prob[_n-2] * prob[_n-1]; for the fourth obs prob[_n-3]*prob[_n-2]*prob[_n-1] and so on.
My approach would have been to run a for loop for every observation counting from x=1 to x=counter and multiplying prob[_n-x] each time. But I'm struggling there and not really sure if that's the right idea.
Thanks a lot for your help!
I've a data set with two observations each for 12 different sport matches - one obs per team.
var match_id
var team
var win: win dummy
var prob: ex ante probability of team i winning match j.
What I'm interested in is identifying consecutive wins of a team and the probability of that run (i.e. the product of the ex ante probabilities of the matches consecutively won prior to match j)
I generate the var counter giving me prior consecutive wins as follows.
sort team match_id
gen counter=0
by team: replace counter = counter[_n-1]+1 if win[_n-1] == 1
Now my question: How do I calculate the product of the x = counter last values of prob?
E.g. for the third obs below I'd like to calculate prob[_n-2] * prob[_n-1]; for the fourth obs prob[_n-3]*prob[_n-2]*prob[_n-1] and so on.
My approach would have been to run a for loop for every observation counting from x=1 to x=counter and multiplying prob[_n-x] each time. But I'm struggling there and not really sure if that's the right idea.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input byte match_id str5 team byte win double prob float counter 1 "Alpha" 1 .8 0 3 "Alpha" 1 .65 1 5 "Alpha" 1 .85 2 7 "Alpha" 1 .6 3 9 "Alpha" 1 .6 4 11 "Alpha" 1 .75 5 1 "Beta" 0 .2 0 4 "Beta" 1 .1 0 6 "Beta" 0 .3 1 7 "Beta" 0 .4 0 10 "Beta" 1 .8 0 12 "Beta" 0 .3 1 2 "Delta" 0 .6 0 4 "Delta" 0 .9 0 5 "Delta" 0 .15 0 8 "Delta" 0 .5 0 10 "Delta" 0 .2 0 11 "Delta" 0 .25 0 2 "Gamma" 1 .4 0 3 "Gamma" 0 .35 1 6 "Gamma" 1 .7 0 8 "Gamma" 1 .5 1 9 "Gamma" 0 .4 2 12 "Gamma" 1 .07 0 end
Comment