Is there anyone who known whether it is possible to estimate a transition or migration matrices in RATS?
Thanks for your help
Atef
Aqu_nb wrote:Is there anyone who known whether it is possible to estimate a transition or migration matrices in RATS?
Thanks for your help
Atef
TomDoan wrote:Aqu_nb wrote:Is there anyone who known whether it is possible to estimate a transition or migration matrices in RATS?
Thanks for your help
Atef
Could you be more specific? Any type of Markov model has a transition matrix.
Aqu_nb wrote:TomDoan wrote:Aqu_nb wrote:Is there anyone who known whether it is possible to estimate a transition or migration matrices in RATS?
Thanks for your help
Atef
Could you be more specific? Any type of Markov model has a transition matrix.
Dear Tom,
Thanks for your reply. To be more specific what I am looking for is a way to estimate Markov chains via empirical transition matrices. Credit rating companies (such Moody’s, Standard and Poor’s and also JP Morgan) use this model to estimate credit rating transition (also called migration) matrices. Is this more clear?
I can also refer to following articals who estimate this model: Robert B. Israel, Jeffrey S. Rosenthal and Jason Z. Wei (2000). Jarrow and Turnbull (1995). Jarrow, Lando and Turnbull (1997).
I want to estimate a credit rating probability transition (migration) matrix. Transition of credit rating of one bond isuer (say AAA) from one year to the next year (say AA) given some macroeconomic conditions.
Thanks for your help
Atef
TomDoan wrote:The transition matrices that they need are for a continuous time Markov chain. How you estimate those parameters depends quite a bit on the form of the data. Are your data regularly spaced? (For instance, all start or end of year classification).
dec rect transit(nclass,nclass)
do i=1,nclass
do j=1,nclass
sstats(smpl=(firm==firm{1}.and.year==year{1}+1)) / (class==j.and.class{1}==i)>>transit(i,j)
end do j
end do i
*
* Do a fail-safed divide by the number of elements per row
*
compute [vector] rowscales=%sumr(transit)
ewise rowscales(i)=%if(rowscales(i)==0,0,1.0/rowscales(i))
compute transit=%diag(rowscales)*transitset recession = year==1981.or.year==1992.or.year==2001 sstats(smpl=(firm==firm{1}.and.year==year{1}+1.and.recession)) / (class==j.and.class{1}==i)>>transit(i,j) sstats(smpl=(firm==firm{1}.and.year==year{1}+1.and..not.recession)) / (class==j.and.class{1}==i)>>transit(i,j)TomDoan wrote:The transition matrices are relatively easy to compute; it's really a matter of adjusting the timing of the gaps between the classifications. The following assumes that you have three series - an identifier for the firm, an identifier for the year and a classification (including default as a possibility). It's assumed that the data are sorted by firm, then by year. The following will first compute the raw counts for changes from class to class. That's then divided by the number in each class at the beginning of the period:
- Code: Select all
dec rect transit(nclass,nclass)
do i=1,nclass
do j=1,nclass
sstats(smpl=(firm==firm{1}.and.year==year{1}+1)) / (class==j.and.class{1}==i)>>transit(i,j)
end do j
end do i
*
* Do a fail-safed divide by the number of elements per row
*
compute [vector] rowscales=%sumr(transit)
ewise rowscales(i)=%if(rowscales(i)==0,0,1.0/rowscales(i))
compute transit=%diag(rowscales)*transit
To do the conditional calculations, you need to create a series which tags the observations. For instance, something like:
- Code: Select all
set recession = year==1981.or.year==1992.or.year==2001
You would do the same as above, but change the sstats to
- Code: Select all
sstats(smpl=(firm==firm{1}.and.year==year{1}+1.and.recession)) / (class==j.and.class{1}==i)>>transit(i,j)
to get the transition probabilities for the recession periods and
- Code: Select all
sstats(smpl=(firm==firm{1}.and.year==year{1}+1.and..not.recession)) / (class==j.and.class{1}==i)>>transit(i,j)
for the expansions.
Aqu_nb wrote:TomDoan wrote:The transition matrices are relatively easy to compute; it's really a matter of adjusting the timing of the gaps between the classifications. The following assumes that you have three series - an identifier for the firm, an identifier for the year and a classification (including default as a possibility). It's assumed that the data are sorted by firm, then by year. The following will first compute the raw counts for changes from class to class. That's then divided by the number in each class at the beginning of the period:
- Code: Select all
dec rect transit(nclass,nclass)
do i=1,nclass
do j=1,nclass
sstats(smpl=(firm==firm{1}.and.year==year{1}+1)) / (class==j.and.class{1}==i)>>transit(i,j)
end do j
end do i
*
* Do a fail-safed divide by the number of elements per row
*
compute [vector] rowscales=%sumr(transit)
ewise rowscales(i)=%if(rowscales(i)==0,0,1.0/rowscales(i))
compute transit=%diag(rowscales)*transit
To do the conditional calculations, you need to create a series which tags the observations. For instance, something like:
- Code: Select all
set recession = year==1981.or.year==1992.or.year==2001
You would do the same as above, but change the sstats to
- Code: Select all
sstats(smpl=(firm==firm{1}.and.year==year{1}+1.and.recession)) / (class==j.and.class{1}==i)>>transit(i,j)
to get the transition probabilities for the recession periods and
- Code: Select all
sstats(smpl=(firm==firm{1}.and.year==year{1}+1.and..not.recession)) / (class==j.and.class{1}==i)>>transit(i,j)
for the expansions.
Dear Tom,
I am sorry for not replying earlier. But it is because I was on vacation. Now I am back and thanks a lot for your help with the code. In this regard I have couple of questions.
1) I have sorted data as you have suggested. And it looks like following:
firm year class
1 1995 AA
1 1996 AAA
1 1997 D
2 2001 BB
2 2002 AA
.
.
In toltal a have around 1 million observation. And my dataset is in sasdata form(file). How do I read a sas data in RATs? I can not export sas data to excel due to 1 million observations.
2) In the code you have send where do you refer to a dataset ? Is it called smpl (fx in: sstats(smpl=(firm==firm{1}.and.year==year{1}+1)) / (class==j.and.class{1}==i)>>transit(i,j))?
3) How do I see output? by that I mean the estimated matrices. Is there a code for that and for tests?
Once again Thanks a lot for your help
Regards
Atef
compute NCLASS=8TomDoan wrote:You have to set the value of NCLASS yourself. It sounds as if
- Code: Select all
compute NCLASS=8
is correct for your data. You should be able to get the entire data set using a text file (CSV, for instance), though it would be a good idea to test everything with a subset as you're currently doing.
TomDoan wrote:%sumr returns the vector of row sums. It was added with RATS 7.2; you might want to see why you don't have that, since the University has it. At any rate, you can do the same calculation with
compute [vector] rowscales=transit*%fill(nclass,1,1.0)
TomDoan wrote:display transit
will do that.
Return to Help With Programming
Users browsing this forum: No registered users and 1 guest