how to calculate transition probability matrix in rats

Questions and discussions on Time Series Analysis
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

how to calculate transition probability matrix in rats

Unread post by fan »

hi Tom,

I have dummy variables for both economic recessions and expansion in the U.S. for 30 years. I could like to calculate the transition probability matrix but I do not know how to do it in rats. Could you please kindly let me know what instructions I should use?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: how to calculate transition probability matrix in rats

Unread post by TomDoan »

Use SSTATS. For instance

sstats(smpl=recession{1},mean) / recession>>prr .not.recession>>prx
sstats(smpl=.not.recession{1},mean) / recession>>pxr .not.recession>>pxx

Equivalently, you can use SSTATS across the whole data range (i.e. no SMPL option) and count all four combinations of recession vs .not.recession .AND. with recession{1} vs .not.recession{1} and convert to probabilities within each lagged value.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: how to calculate transition probability matrix in rats

Unread post by fan »

TomDoan wrote:Use SSTATS. For instance

sstats(smpl=recession{1},mean) / recession>>prr .not.recession>>prx
sstats(smpl=.not.recession{1},mean) / recession>>pxr .not.recession>>pxx

Equivalently, you can use SSTATS across the whole data range (i.e. no SMPL option) and count all four combinations of recession vs .not.recession .AND. with recession{1} vs .not.recession{1} and convert to probabilities within each lagged value.
Thank you for the quick reply. I tried the suggested instructions but I could not see any output in rats. Is it because I missed something? By the way, if I would like to calculate the transition probability for different subsamples such as one for before 1970 and another for after 1970, can I still use smpl option? Thank you.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: how to calculate transition probability matrix in rats

Unread post by TomDoan »

That's correct. SSTATS does the "query" calculation, but what you do with the results is up to you. The probabilities are in the PRR, etc. variables. Yes. You can use either SMPL or the start and end parameters on SSTATS to restrict the range.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: how to calculate transition probability matrix in rats

Unread post by fan »

TomDoan wrote:That's correct. SSTATS does the "query" calculation, but what you do with the results is up to you. The probabilities are in the PRR, etc. variables. Yes. You can use either SMPL or the start and end parameters on SSTATS to restrict the range.
thank you for the reply. Can I ask one more question? In additional to the economic conditions (recessions, expansions), I also have dummy variables for political regimes(Demos. and Reps.). I would like to know how I can calculate the transition probability based on those two conditional states (economic state and political state) in rats. What instructions I should use? Many Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: how to calculate transition probability matrix in rats

Unread post by TomDoan »

Just add clauses to the SMPL to restrict to the subsample that you want.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: how to calculate transition probability matrix in rats

Unread post by fan »

TomDoan wrote:Just add clauses to the SMPL to restrict to the subsample that you want.
Thank you for the reply. I tried to add clauses to the smpl but always got error messages. Could you please kindly look at my code and point out my mistake?

Code: Select all

sstats(smpl=contraction{1},mean) (smpl=demo{1},mean) / contraction>>prr .not.contraction>>prx .not.demo>>pdr
Many Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: how to calculate transition probability matrix in rats

Unread post by TomDoan »

sstats(smpl=contraction{1}.and.demo{1},mean) / contraction>>prr .not.contraction>>prx .not.demo>>pdr

However, you might not want to convert those to means, as that will eliminate the information about the total number of items. You're better off populating a table of the four by four transition counts and adding them up and dividing later to get the various probabilities.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: how to calculate transition probability matrix in rats

Unread post by fan »

TomDoan wrote:sstats(smpl=contraction{1}.and.demo{1},mean) / contraction>>prr .not.contraction>>prx .not.demo>>pdr

However, you might not want to convert those to means, as that will eliminate the information about the total number of items. You're better off populating a table of the four by four transition counts and adding them up and dividing later to get the various probabilities.
HI, Tom. Thank you for the suggestion. To get the transition counts, I should use the following instructions:

Code: Select all

sstats(smpl=contraction{1}.and.demo{1}) / contraction.and.demo>>pdrrd .not.contraction.and.demo>>pdrxd contraction.and..not.demo>>pdrrr .not.contraction.and..not.demo>>pdrxr
sstats(smpl=.not.contraction{1}.and.demo{1}) / contraction.and.demo>>pdxrd .not.contraction.and.demo>>pdxxd contraction.and..not.demo>>pdxrr .not.contraction.and..not.demo>>pdxxr
sstats(smpl=contraction{1}.and..not.demo{1}) / contraction.and.demo>>prrrd .not.contraction.and.demo>>prxrd contraction.and..not.demo>>prrrr .not.contraction.and..not.demo>>prrxr
sstats(smpl=.not.contraction{1}.and..not.demo{1}) / contraction.and.demo>>prxrd .not.contraction.and.demo>>prxxd contraction.and..not.demo>>prxrr .not.contraction.and..not.demo>>prxxr


add up all the transition accounts to get the total transition accounts and dividing the total transition accounts for the probabilities.

Please kindly let me know whether my understanding is correct or not.
Last edited by fan on Thu Sep 03, 2015 11:20 pm, edited 1 time in total.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: how to calculate transition probability matrix in rats

Unread post by TomDoan »

Except for the missing SSTATS instruction names, that looks correct.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: how to calculate transition probability matrix in rats

Unread post by fan »

TomDoan wrote:Except for the missing SSTATS instruction names, that looks correct.
Thank you so much for the quick reply
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: how to calculate transition probability matrix in rats

Unread post by fan »

TomDoan wrote:Except for the missing SSTATS instruction names, that looks correct.
Hi Tom, How can I estimate the transition probability of the political regime switch by using the Hamilton method? Particularly, I am interested in knowing transition probability after the president served his first term and second term individually. Many Thanks
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: how to calculate transition probability matrix in rats

Unread post by TomDoan »

fan wrote: Hi Tom, How can I estimate the transition probability of the political regime switch by using the Hamilton method? Particularly, I am interested in knowing transition probability after the president served his first term and second term individually. Many Thanks
Transition probablity of what? All the examples you've had above have been transition probabilities between observable regimes. The Hamilton model is for hidden state models.
fan
Posts: 215
Joined: Wed Jun 19, 2013 5:14 pm

Re: how to calculate transition probability matrix in rats

Unread post by fan »

TomDoan wrote:
fan wrote: Hi Tom, How can I estimate the transition probability of the political regime switch by using the Hamilton method? Particularly, I am interested in knowing transition probability after the president served his first term and second term individually. Many Thanks
Transition probablity of what? All the examples you've had above have been transition probabilities between observable regimes. The Hamilton model is for hidden state models.
Hi, Tom. Thanks for the quick reply. My question actually is that given the initial condition such as the president is democratic and serving his first term, which is the probability the new president will be from the same party before knowing the election result?
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: how to calculate transition probability matrix in rats

Unread post by TomDoan »

Using what information? In the post-war period, you only have Truman, Johnson(?), Carter, Clinton, Obama. Depending upon whether you count Johnson, it's either 3/4 or 4/5. There is a literature that predicts results based upon economic trends, and it probably gets it right about as often as a coin flip.
Post Reply