Hi all,

I would like to plot in a graph the transition matrix from employment to employment (EtoE), unemployment to employment (UtoE), unemployment to unemployment (UtoU), etc. over the period 2010 t0 2014.

I would like to have the year in the x-axis and the transition probability on the y-axis. Below is the code that I wrote:

Code:
set more off
forvalues i=2010/2014{
gen em1`i'=labor==1 if year==`i'
gen em2`i'=labor==2 if year==`i'
gen em3`i'=labor==3 if year==`i'
}
forvalues i=2010/2013{
local j=`i'+1
gen UtoN`i'=(em2`i'==1 & em3`j'==1) if em2`i'==1
gen UtoE`i'=(em2`i'==1 & em1`j'==1) if em2`i'==1
gen UtoU`i'=(em2`i'==1 & em2`j'==1) if em2`i'==1
gen NtoE`i'=(em3`i'==1 & em1`j'==1) if em3`i'==1
gen NtoU`i'=(em3`i'==1 & em2`j'==1) if em3`i'==1
gen NtoN`i'=(em3`i'==1 & em3`j'==1) if em3`i'==1
gen EtoU`i'=(em1`i'==1 & em2`j'==1) if em1`i'==1
gen EtoN`i'=(em1`i'==1 & em3`j'==1) if em1`i'==1
gen EtoE`i'=(em1`i'==1 & em1`j'==1) if em1`i'==1
}

collapse (mean) UtoN2010-EtoE2013, by(gender state)
reshape long UtoN UtoE UtoU NtoE NtoU NtoN EtoU EtoN EtoE, i(gender state) j(year)
graph twoway ( (line UtoE year,lpattern(dash) lcolor(red)) (line UtoU year,lpattern(dash) lcolor(black))(line EtoE year, lcolor(black)), ///
legend(label(1 "U->E") label(2 "U->U") label(3 "E->E")) by(state))
When I run this code, I obtained 0 for all the probability of transition. Can someone tell me where I made mistake?

My data looks like the following:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int ID double(year labor gender state)
11112 2010 3 1 1
11112 2011 1 1 1
11112 2012 3 1 2
11112 2013 2 1 1
11112 2014 1 1 1

11113 2010 2 1 1
11113 2011 2 1 1
11113 2012 1 1 2
11113 2013 2 1 2
11113 2014 1 1 1

11114 2010 1 1 2
11114 2011 3 1 2
11114 2012 3 1 1
11114 2013 2 1 1
11114 2014 1 1 1

11115 2010 2 0 1
11115 2011 2 0 1
11115 2012 1 0 1
11115 2013 3 0 2
11115 2014 1 0 1

11116 2010 1 0 2
11116 2011 1 0 2
11116 2012 3 0 2
11116 2013 2 0 2
11116 2014 3 0 2
end
label values labor Employment
label def Employment 1 "Employed", modify
label def Employment 2 "Unemployed", modify
label def Employment 3 "Inactive", modify
label values gender Female
label def Female 1 "Female", modify
label def Female 0 "Male", modify
label values state Region
label def Region 1 "North", modify
label def Region 2 "South", modify
Thanks in advance for your help.