Page 1 of 2
how to calculate transition probability matrix in rats
Posted: Thu Aug 27, 2015 2:53 pm
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?
Re: how to calculate transition probability matrix in rats
Posted: Thu Aug 27, 2015 3:03 pm
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.
Re: how to calculate transition probability matrix in rats
Posted: Thu Aug 27, 2015 4:47 pm
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.
Re: how to calculate transition probability matrix in rats
Posted: Thu Aug 27, 2015 5:06 pm
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.
Re: how to calculate transition probability matrix in rats
Posted: Mon Aug 31, 2015 12:35 am
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
Re: how to calculate transition probability matrix in rats
Posted: Mon Aug 31, 2015 8:26 am
by TomDoan
Just add clauses to the SMPL to restrict to the subsample that you want.
Re: how to calculate transition probability matrix in rats
Posted: Wed Sep 02, 2015 3:10 am
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
Re: how to calculate transition probability matrix in rats
Posted: Wed Sep 02, 2015 8:17 am
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.
Re: how to calculate transition probability matrix in rats
Posted: Thu Sep 03, 2015 11:05 pm
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.
Re: how to calculate transition probability matrix in rats
Posted: Thu Sep 03, 2015 11:15 pm
by TomDoan
Except for the missing SSTATS instruction names, that looks correct.
Re: how to calculate transition probability matrix in rats
Posted: Thu Sep 03, 2015 11:21 pm
by fan
TomDoan wrote:Except for the missing SSTATS instruction names, that looks correct.
Thank you so much for the quick reply
Re: how to calculate transition probability matrix in rats
Posted: Thu Sep 10, 2015 10:34 pm
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
Re: how to calculate transition probability matrix in rats
Posted: Thu Sep 10, 2015 11:25 pm
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.
Re: how to calculate transition probability matrix in rats
Posted: Fri Sep 11, 2015 12:13 am
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?
Re: how to calculate transition probability matrix in rats
Posted: Fri Sep 11, 2015 7:48 am
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.