Hallo Statalist,

i am trying to find out the effect of the macro variables on the credit Rating in stress scenarios, or more precisely how many classes decreases the rating in stress scenarios (changing the macro variables).

The data include (CounterpartyNr , Rating Method, and Rating from 2005 to 2020). For my Panel data i'm trying to run xtologit (ordered logit regression)
I identified the orders as follows:

0 for an increase in Rating class
1 for no change in Rating class
2 for one Rating class decrease
3 for two Rating classes decrease
4 for three Rating classes decrease
5 for more than 3 Rating classes decrease
Where the Ratings are in numbers from 1 to 20 where 1 is the best one

Code:
ID Rating Year Order
1 3 2005
1 5 2006 3
1 1 2007 0
2 10 2005
2 11 2006 2
3 15 2005
3 18 2006 4
3 9 2007 0
3 8 2008 0
the problem is that the first observation of each group has no value in this order

so my question is
do you think this ordering is wrong for my analysis Or is it a solution when i assume that the first observation of each group should take the order 1 (no change)

Code:
xtset CounterpartyNr Year
bysort CounterpartyNr: drop if _N == 1
sort NaceCode CounterpartyNr
egen id = group( NaceCode CounterpartyNr)
sort id Year
bysort id: gen change =Rating-Rating[_n-1]
gen Order = 0 if change < 0
replace Order = 1 if change == 0
replace Order = 2 if change == 1
replace Order = 3 if change == 2
replace Order = 4 if change == 3
replace Order = 5 if (change > 3 & change != .)
asdoc xtoprobit Order RealGDP ExchangeRate Gov.DebttoGDP Unemploymentrate Inflation
asdoc tabulate Order
asdoc sum RealGDP ExchangeRate Gov.DebttoGDP Unemploymentrate Inflation