Page 1 of 1

Calculating Average Duration in a MS Model

Posted: Mon Jan 23, 2017 9:38 am
by alexecon
I would like to calculate the average duration of a particular regime in a two-state Markov-switching model. Presumably, this can work as follows:
1) Set all 'smoothed' regime probabilities under 0.5 equal to 0 and all probabilities of 0.5 or above equal to 1
2) Count the number of times a 1 (or, more often, a group of 1s) is preceded and followed by 0
3) Name this number "x"
4) Count the total number of 1s
5) Name this number "y"
5) Compute average duration as y/x
Is this the way to go about it? If yes, how does one implement 2) in the list?
Thank you.

Re: Calculating Average Duration in a MS Model

Posted: Mon Jan 23, 2017 10:18 am
by TomDoan
sstats mystart+1 myend myregime==1.and.myregime{1}==0>>x myregime==1>>y
disp "Average duration" y/x

where mystart, myend and myregime are all whatever's appropriate to your model. The count for x might differ by 1 from the strict definition in step 2 if the sample ends with a 1 since it only counts the number of times a 1 is preceded by a 0. Of necessity, all strings of 1's have to end with a 0 except at the end of the sample.