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 <[email protected]>
To   [email protected]
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)

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

Dirk

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

phone: +49-(0)40-42838.7498 (office)
+49-(0)40-42838.4591 (Billon)
fax: +49-(0)40-42838.2344
email: [email protected]
www: http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
*************************************************
*
* 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