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   Dirk Enzmann <>
Subject   Re: st: tab2 or crosstable with adjusted standardized residuals
Date   Tue, 30 May 2006 15:16:28 +0200

Thanks for the suggestions/solutions!

Indeed, I had Haberman's definition of adjusted standardized residuals in mind.

Nick's suggestions are perfect!

After making some corrections, Ulrich Kohlers suggestions works very well, too (using poisson for generating the expected counts is interesting). Here it is:

* ===================================================
* Calculating adjusted standardized residuals with Stata:

* (Ulrich Kohler's suggestion):

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:
gen res_s = res/sqrt(nhat)

* Calculate adjusted standardized residuals:
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 for: replace nb = nb[_N]
gen res_as = res/sqrt(nhat * (1-na/N) * (1-nb/N))

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

* ===================================================


Dr. Dirk Enzmann
Institute of Criminal Sciences
Dept. of Criminology
Edmund-Siemers-Allee 1
D-20146 Hamburg

phone: +49-(0)40-42838.7498 (office)
+49-(0)40-42838.4591 (Billon)
fax: +49-(0)40-42838.2344
* For searches and help try:

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