Hi!

I am using panel data to compute transition probabilities. The data is appended for years 2000 to 2017. I have a variable emp_state that takes the value 1 if a person is in paid employment, 2 if self-employed and 3 if unemployment. I want to compute the transition probabilities of moving from one state in year t to another state in year t+1 for all years. This means a have a 3x3 transition matrix for each year. I need to compute this for a period 2000-2016. I use the following code (stata 15.1) where persnr is individual is and syear is the survey year

xtset persnr syear, yearly
gen nextyr=f.emp_state
quietly {

forval j = 1/9 {
gen f`j' = .
}

local i = 1

forval y= 2000/2017{
count if emp_state <. & nextyr <. & syear == `y'
if r(N) > 0 {
tab emp_state nextyr if syear == `y', row matcell(e_state)
replace f1 = e_state[1,1] in `i'
replace f2 = e_state[1,2] in `i'
replace f3 = e_state[1,3] in `i'
replace f4 = e_state[2,1] in `i'
replace f5 = e_state[2,2] in `i'
replace f6 = e_state[2,3] in `i'
replace f7 = e_state[3,1] in `i'
replace f8 = e_state[3,2] in `i'
replace f9 = e_state[3,3] in `i'

}
local ++i
}

gen p11 = f1 / (f1 + f2+f3)
gen p12 = f2 / (f1 + f2+f3)
gen p13 = f3 / (f1 + f2+f3)
gen p21 = f4 / (f4 + f5+f6)
gen p22 = f5 / (f4 + f5+f6)
gen p23 = f6 / (f4 + f5+f6)
gen p31 = f7 / (f7 + f8+f9)
gen p32 = f8 / (f7 + f8+f9)
gen p33 = f9 / (f7 + f8+f9)

}

gen year = 2000 + _n
format p* %4.3f
list year f* p* if f1 <.

The code seems to work fine in computing the transition probabilities however, the output looks like this

1. year fsize f1 f2 f3 f4 f5 f6 f7 f8 f9 persnr p11 p12
2001 2 965 156 1 152 10695 208 5 160 373 203.000 0.860 0.139

p13 p21 p22 p23 p31 p32 p33
0.001 0.014 0.967 0.019 0.009 0.297 0.693

I do not understand what is fsize and why is it even there? Also why is the persnr (individual id) there and only a specific number (not all ids)?
Is it possible to get the table without the fsize and persnr?
I would appreciate a lot any help.