Hi everyone,
I have done a transition matrix, based on this stata's previous discussion (the code is provided by Mike Lacy. Thanks to him) :
Here is the code applied to my case:
Here is a dataex:
I have two questions related to this:
Best,
Michael
Edit: Please feel free to give me some feedback about this code, as I am not sure if I have written it correctly or not! Thanks.
I have done a transition matrix, based on this stata's previous discussion (the code is provided by Mike Lacy. Thanks to him) :
Here is the code applied to my case:
Code:
// Each observation gets prior year value bysort id (date_contract_start): gen product_prior = /// product_classification_encod[_n-1] if (date_contract_end[_n-1] < date_contract_start) & !missing(powers_tariff2_less_15000w) // All years, tab regime this year vs. prior tab product_classification_encod product_prior, matcell(T) mat list T // Convert to probabilities based on column totals forval j = 1/`=colsof(T)' { // totals each column local total = 0 forval i = 1/`=rowsof(T)' { local total = `total' + T[`i', `j'] } di "total col `j' = " `total' // forval i = 1/`=rowsof(T)' { mat T[`i', `j'] = T[`i', `j']/`total' } } mat list T T[4,4] c1 c2 c3 c4 r1 .80067365 .12579277 .04383295 .08536468 r2 .00258068 .84896532 .0004873 .0000334 r3 .00323013 .00047113 .84216289 .00161144 r4 .19351554 .02477078 .11351686 .91299048
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long(id sp_zipcode) double(date_contract_start date_contract_end) long(product_classification_encod tariff_ekon_id_encod) 1001 9200 18887 21700 1 1 1001 9200 21701 22431 1 2 1001 9200 22432 22645 1 4 1001 9200 22646 22676 1 4 1001 9200 22677 22735 1 4 1001 9200 22736 23010 1 4 1001 9200 23011 23069 1 4 1001 9200 23070 . 4 4 1005 48600 18800 21639 1 1 1005 48600 21640 21651 1 1 1005 48600 21652 22066 1 2 1005 48600 22067 22431 1 2 1005 48600 22432 22456 1 4 1005 48600 22457 22645 1 4 1005 48600 22646 22676 1 4 1005 48600 22677 22735 1 4 1005 48600 22736 22888 1 4 1005 48600 22889 23010 1 4 1005 48600 23011 23041 1 4 1005 48600 23042 23130 4 4 end format %td date_contract_start format %td date_contract_end label values product_classification_encod product_classification_encod label def product_classification_encod 1 "Clasico", modify label def product_classification_encod 4 "Tarifa Justa", modify label values tariff_ekon_id_encod tariff_ekon_id_encod label def tariff_ekon_id_encod 1 "20A", modify label def tariff_ekon_id_encod 2 "20DHA", modify label def tariff_ekon_id_encod 4 "20TD", modify
- I would like to know if there is a way to construct a matrix to know when occurs the most the change from "state 1" to "state 2", the change from state "1" to "state 3", and so on with all cases.
- Is there a way to export this matrix and the one shown above suitably into LaTeX format, please?
Best,
Michael
Edit: Please feel free to give me some feedback about this code, as I am not sure if I have written it correctly or not! Thanks.