Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[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" <Martin.Wetzel@iab.de>
To   <statalist@hsphsun2.harvard.edu>
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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index