Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: tab2 or crosstable with adjusted standardized residuals


From   Ulrich Kohler <[email protected]>
To   [email protected]
Subject   Re: st: tab2 or crosstable with adjusted standardized residuals
Date   Mon, 29 May 2006 11:50:58 +0200

Dirk Enzmann wrote:
> The command tab2 generates crosstables displaying different information
> in its cells (a.o. counts, row- and column-percentages). What can I do
> to have additionally a display of adjusted standardized residuals? Is it
> possible to extend the options of tab2 (or writing an ado that uses
> tab2) such that adjusted standardized residuals can be displayed?
>
> Note: Up to now I never did programming in Stata.

-tab2- is a caller of -tabulate- and can therefore not be rewritten to display 
quantities that are not part of -tabulate- itself. If you want to write a 
program you need to start from scratch, I am afraid.

I don't know whether I found the formula you had in mind, but a  starting 
point could be a solution that starts with -poisson-:

-----------------------------
sysuse auto, clear

// Make Frequence Data of 2 way table
contract rep78 for, freq(n) nomiss
fillin rep78 for
replace n = 0 if _fillin
drop _fillin

// Estimate "Independence Model"
xi: poisson n i.for i.rep78             

// Calculate Expected Frequency of Independence Model
predict nhat                 

// Calculate Residual 
gen res = n - nhat                       

// Calculate standardized residuals (check Formula?)
gen res_s = res/sqrt(nhat)               

// Calculate adjusted standardized residuals (check Formula?)
gen N = sum(N)
replace N = N[_N]
by rep78, sort: gen na = sum(n)
by rep78: replace na = na[_N]
by for, sort: gen nb = sum(n)
by rep78: replace nb = nb[_N]
gen res_as = res/sqrt(na * nb * (1-na)/N * (1-nb)/N) // <- Adjusted?

// Table with observed freq, expected freq, raw, standard., adjusted 
tabdisp rep78 for, cellvar(n nhat res res_s res_as)

Hope that helps
Uli

-- 
[email protected]
+49 (030) 25491-361
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index