Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: RE: chi-square-test in matrix or crosstab


From   "Wetzel Martin" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: chi-square-test in matrix or crosstab
Date   Wed, 30 Jun 2010 10:41:55 +0200

Thanks for your both answers!

I did not realize the power of tabi.
But now I fixed my problem: To make a chi-square-test with an already computed table (in matrix or in data format) I generate a macro which contains the table separated with backslash. This is readable from Stata's "tabi".

**********************
sysuse auto.dta, clear
tab2 rep78 foreign, matcell(A)

local r = rowsof(A)					// count rows of matrix
local c = colsof(A)					// count cols of matrix

forvalues k = 1 / `r' {				// "a11 a12 a13 \ a21 a22 a23 \ a31 a32 a33"
	forvalues j = 1 / `c' {
		di "`k' - `j'"
		local n = A[`k',`j']
		local tchi "`tchi' `n'"

		if `j' == `c' & `k' != `r' { 	// backslash after last col but not in last row
			local tchi "`tchi' \"
		}
	}
} 

di "`tchi'"
tabi "`tchi'", chi 					// Chi²-Test
**********************

Martin Wetzel





© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index