Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: adjust prevalence (solution)

From   "Jan Brogger" <[email protected]>
To   "Statalist" <[email protected]>
Subject   st: adjust prevalence (solution)
Date   Wed, 28 Aug 2002 12:02:34 +0200

If you have two populations with different prevalences of an outcome,
but that also have different prevalences of covariates (confounders) -
how do you compare these fairly? 
Logistic regression will adjust for the differences, and will give you
an adjusted odds ratio for the differences between populations. But how
about prevalences ? The traditional method is via standardization but
this cannot handle continuous variables which is a weakness. The
-adjust- command and variants will adjust the prevalences so that they
are comparable, but the population that it adjusts to is a not so simple
meta-population with funny values for covariates [shown in previous
post]. How to adjust to one of the populations ? 

Let prevA be the unadjusted prevalence in population A, and prevB be the
unadjusted  prevalence in population B. We want prevalences adjusted to
population A. Naturally, the prevalence in population A is adjusted to
itself, and hence unchanged. But how to get the prevalence in population
B ? It seems intuitive to me that the right way is simply to use the
adjusted odds ratio. Convert the unadjusted prevalence in population B
to an odds, multiply by the adjusted odds ratio, and convert back to a
prevalence - the adjusted prevalence. This makes sense. If you really
believe that the adjusted odds ratio is the true odds ratio, due to the
removal of confounding by other covarites, then the adjusted prevalence
in population B represent that prevalence you would have observed if
population B had the same distribution of covariates as population A.

This program will calculate adjusted prevalences with the above method.
It was a quick hack. Can anybody help in getting confidence intervals
from this program, too ? It needs documentation (short) but I don't
write SMCL.

*! 1.0.0 Jan Brogger [email protected] 28aug2002
capture program drop adjust2
program define adjust2 , rclass
	version 7.0
	syntax , by(varname) coeff(string)

	qui {
		tempname eb matcoeff 
		tab `by'
		if `r(r)'!=2 {
			di as err "Error in adjust: by variable `by'
must have only two levels."
		*First, get the two levels of the -by- variable
		summ `by'
		local levelA `r(min)'
		local levelB `r(max)'
		*Convert the target population prevalence to an odds
		summ `e(depvar)' if `by'==`levelA' , meanonly
		local prevA=`r(mean)'
		local adjprevA=`prevA' 
		local oddsA=`prevA'/(1-`prevA')

		*Get the unadjusted prevalence of population B
		summ `e(depvar)' if `by'==`levelB' , meanonly
		local prevB=`r(mean)'
		*Get the odds ratio
		matrix `eb'=e(b)
		mat `matcoeff'=`eb'["y1","`coeff'"]
		local coeff2=`matcoeff'[1,1]
		local oddsratio=exp(`coeff2')
		*Adjust the odds with the odds ratio and convert back
		local oddsB=`oddsA'*`oddsratio' 
		local adjprevB=`oddsB'/(`oddsB'+1) 


	*Display this nicely

	di as text "Unadjusted" _col(40) "Adjusted"
	di "prevalences" _col(20) "Odds ratio" _col(40) "prevalences"
	di as res "`levelA'" _col(10) "`levelB'" _col(40) "`levelA'"
_col(50) "`levelB'" 
	di as text _dup(55) "-"
	di as res %4.3f `prevA' _col(10) %4.3f  `prevB' _col(20) %4.3f
`oddsratio' /*
		*/ _col(40) %4.3f `adjprevA' _col(50) %4.3f `adjprevB'

	return local unadjprevA = `prevA'
	return local unadjprevB = `prevB'
	return local oddsratio =  `oddsratio'
	return local adjprevA = `adjprevA'
	return local adjprevB = `adjprevB'


*Theoretical example
*The adjusted prevalences should be the same
*whereas the crude are not
*This is due to (extreme) confounding by gender

input time sex asthma freq
0 0 0 450
0 0 1 50
0 1 0 300
0 1 1 200
1 0 0 810
1 0 1 90
1 1 0 60
1 1 1 40
expand freq
tab sex time , col nofreq
bysort time: tab asthma sex , col nofreq
logistic asthma time sex
*adjust sex , by(time) pr format(%16.15f)
adjust2 , by(time) coeff(time)
ret li

Yours sincerely,

Jan Brogger, Institute of Medicine, University of Bergen, Norway

*   For searches and help try:

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