Dear all,
I am working on a panel dataset, where I classified individuals into groups according to some characteristics of their variables. Then, using the command xttrans2, I got the transition probabilities and frequencies of moving from one group to each other. I have run the xttrans2 command conditional on ages, in order to get the transition probabilities from each group when an individual is 18 years old (to 19 years), when an individual is 19 years old (to 20 years) and so on.
Above there is the code I wrote: in the first part I create the groups (and call them 111, 123, ... with the forvalues loop), in the second part I use the xttrans2 command and transfer to Excel the results.
Now the question.
I would like to create and put to excel a vector for each combination of two groups (start and arrive groups) in order to be able to plot the change of those probabilities over the ages.
To give an example, I am trying to create a vector of the form (including a missing value at AGE 24):
The big issue is that not all the transition matrices created with xttrans2 have the same dimension as there are some missing values and not all the probabilities of all groups have been calculated.
I apologize for the long question, thanks in advance for any help!
Sincerely
Luca
I am working on a panel dataset, where I classified individuals into groups according to some characteristics of their variables. Then, using the command xttrans2, I got the transition probabilities and frequencies of moving from one group to each other. I have run the xttrans2 command conditional on ages, in order to get the transition probabilities from each group when an individual is 18 years old (to 19 years), when an individual is 19 years old (to 20 years) and so on.
Above there is the code I wrote: in the first part I create the groups (and call them 111, 123, ... with the forvalues loop), in the second part I use the xttrans2 command and transfer to Excel the results.
Code:
_pctile I, p(25, 50, 75) scalar I25 = r(r1) scalar I50 = r(r2) scalar I75 = r(r3) quietly sum I scalar I0 = r(min) scalar I100 = r(max) _pctile L, p(50) scalar L50 = r(r1) quietly sum L scalar L0 = r(min) scalar L100 = r(max) _pctile IL, p(33, 66) scalar IL33 = r(r1) scalar IL66 = r(r2) quietly sum IL scalar IL0 = r(min) scalar IL99 = r(max) gen group = 0 forvalues i = 25(25)100 { forvalues j = 50(50)100 { forvalues k = 33(33)99 { local ii = `i'/25 local jj = `j'/50 local kk = `k'/33 replace group = `ii'`jj'`kk' if /// I <= I`i' & I >= I`=`i' - 25' & /// L <= L`j' & L >= L`=`j' - 50' & /// IL <= IL`k' & IL >= IL`=`k' - 33' } } } forvalues i = 18/89 { preserve drop if AGE < `i' | AGE > `i' + 1 quietly xttrans2 group, freq matcell(Mf`i') quietly xttrans2 group, prob matcell(Mp`i') putexcel A1 = matrix(Mp`i', names) using Transition, modify sheet("AGE`i'", replace) keepcellformat restore }
I would like to create and put to excel a vector for each combination of two groups (start and arrive groups) in order to be able to plot the change of those probabilities over the ages.
To give an example, I am trying to create a vector of the form (including a missing value at AGE 24):
AGE | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 |
from group "111" to group "121" | 0.8 | 0.4 | 0.5 | 0.6 | 0.3 | 0.2 | . | 0.6 | 0.7 |
I apologize for the long question, thanks in advance for any help!
Sincerely
Luca
Comment