*! Program used to present the results in
*! Chang and Wong (2009) Table 5
*!   ChangTab5 roa A

capture program drop ChangTab5
program define ChangTab5
version 11.2

  args x A            //   ChangTab5 roa A

  mat S = J(6,11,.)   //

  *-All firms
    cap drop q_x
    qui bysort year: quantiles `x', gen(q_x) n(5)
    qui sum q_x
	mat S[1,1] = r(N)  //
	qui tabstat `x', s(median) by(q_x) f(%4.3f) save //Tab5.Panel_A.Line1
	mat S[1,2] = (r(Stat1),r(Stat2),r(Stat3),r(Stat4),r(Stat5))
	mat S[1,8] = r(Stat5) - r(Stat1)  // Performance spread (5)-(1)
    qui ttest `x' if inlist(q_x,1,5), by(q_x)    //t-test performance
	mat S[1,10]= (r(t), r(p))  // p-value   t-value

	qui tabstat TO_force, s(mean) by(q_x) f(%4.3f) save //Tab5.Panel_A.Line2
	mat S[2,2] = (r(Stat1),r(Stat2),r(Stat3),r(Stat4),r(Stat5),r(StatTotal))
	mat S[2,9] = r(Stat5) - r(Stat1)  // Turnover spread (5)-(1)
	qui ttest TO_force if inlist(q_x,1,5), by(q_x) //t-test turnover rate
	mat S[2,10]= (r(t), r(p))

  *-Profit-making firms
    cap drop q_x
	global if "if loss==0"
    qui bysort year: quantiles `x' $if, gen(q_x) n(5)
    qui sum q_x
	mat S[3,1] = r(N)  // Profit-making
	qui tabstat `x', s(median) by(q_x) f(%4.3f) save //Tab5.Panel_A.Line1
	mat S[3,2] = (r(Stat1),r(Stat2),r(Stat3),r(Stat4),r(Stat5))
	mat S[3,8] = r(Stat5) - r(Stat1)  // Performance spread (5)-(1)
    qui ttest `x' if inlist(q_x,1,5), by(q_x)    //t-test performance
	mat S[3,10] = (r(t), r(p))  // p-value   t-value

	qui tabstat TO_force, s(mean) by(q_x) f(%4.3f) save //Tab5.Panel_A.Line2
	mat S[4,2] = (r(Stat1),r(Stat2),r(Stat3),r(Stat4),r(Stat5),r(StatTotal))
	mat S[4,9] = r(Stat5) - r(Stat1)  // Turnover spread (5)-(1)
	qui ttest TO_force if inlist(q_x,1,5), by(q_x) //t-test turnover rate
	mat S[4,10] = (r(t), r(p))

  *-Loss-making firms
    cap drop q_x
	global if "if loss==1"
    qui bysort year: quantiles `x' $if, gen(q_x) n(5)
    qui sum q_x
	mat S[5,1] = r(N)  // Loss-making
	qui tabstat `x', s(median) by(q_x) f(%4.3f) save //Tab5.Panel_A.Line1
	mat S[5,2] = (r(Stat1),r(Stat2),r(Stat3),r(Stat4),r(Stat5))
	mat S[5,8] = r(Stat5) - r(Stat1)  // Performance spread (5)-(1)
    qui ttest `x' if inlist(q_x,1,5), by(q_x)    //t-test performance
	mat S[5,10]= (r(t), r(p))  // p-value   t-value

	qui tabstat TO_force, s(mean) by(q_x) f(%4.3f) save //Tab5.Panel_A.Line2
	mat S[6,2] = (r(Stat1),r(Stat2),r(Stat3),r(Stat4),r(Stat5),r(StatTotal))
	mat S[6,9] = r(Stat5) - r(Stat1)  // Turnover spread (5)-(1)
	qui ttest TO_force if inlist(q_x,1,5), by(q_x) //t-test turnover rate
	mat S[6,10]= (r(t), r(p))


    local cc "ATO PF(5)-(1) TO(5)-(1) t p-value"
    mat colnames S = obs (1)Low (2) (3) (4) (5)High `cc'
	mat rownames S = All_`x' turnover Prof_`x' turnover Loss_`x' turnover

	dis _n(2) in yellow _dup(52) "_"
    dis  in red "Panel `A': Observations are sorted according to `x'"
	dis       in yellow _dup(52) "_"
	mat list S, format(%4.3f) nodotz noheader

end