* do-file for additional exercise 4.3 (VHM 802)

version 17 /* works also with versions 14-16 */
set more off
cd "r:\"

use hs04_3, clear
encode city, gen(City)
* note use of frequency weights (in square brackets [])
logit disease i.City i.alcoholic [fweight=n]
logit disease i.City i.alcoholic [fweight=n], or
estat gof, table /* Pearson goodness-of-fit test */
estat gof, group(8) /* Hosmer-Lemeshow test is pretty useless with 3 groups */
* alternatively we may test the interaction (~ lack-of-fit) directly
logit disease i.City##i.alcoholic [fweight=n]
testparm i.City#i.alcoholic /* Wald test */
estimates store full
logit disease i.City i.alcoholic [fweight=n]
lrtest full, stats /* likelihood-ratio test */

* analysis with grouped data format (fewer options for analysis)
use hs04_3grp, clear
encode city, gen(City)
glm diseased i.City i.alcoholic, fam(binomial total)
estimates store fullgrouped
glm diseased i.City##i.alcoholic, fam(binomial total)
lrtest fullgrouped, stats /* same likelihood-ratio test */
