Svend's -syntax- allows -if- and -in-, but the program
ignores them.
In addition, I suggest adding a -version- statement
and some rounding in the display. I have not
tested whether this works in Stata 7.
* touched by NJC
*! 1.0.0 Svend Juul 1 August 2007
program cs_nnt
version 8.2
syntax varlist(min=2 max=2 numeric) [if] [in]
marksample touse
qui count if `touse'
if r(N) == 0 error 2000
cs `varlist' if `touse'
local nnt = 1/r(rd)
local ub = 1/r(ub_rd)
local lb = 1/r(lb_rd)
display _n as txt " NNT = " ///
as res %3.2f `nnt' ///
as txt " (`c(level)'% CI: " ///
as res %3.2f `ub' ///
as txt "; " as res %3.2f `lb' as txt ")"
end
Nick
[email protected]
Svend Juul
> Carlo wrote:
>
> Is there any Stata 9.2 function for calculating the patient
> number needed to
> be treated (NNT) in order to prevent one case of a given
> disease? (Search do
> not support this query)
>
> - and Ron�n Conroy followed up:
> ... it would make a useful addition to the -epitab- commands
> which calculate
> absolute risk reduction, together with its associated
> confidence interval,
> for those who are not brave enough to calculate something by hand.
>
> ------------------------------------------------------------
>
> This calls for a small program. I wrote cs_nnt.ado and put it in
> c:\ado\personal.
>
> program cs_nnt
> syntax varlist(min=2 max=2 numeric) [if] [in]
> cs `varlist'
> local nnt = 1/r(rd)
> local ub = 1/r(ub_rd)
> local lb = 1/r(lb_rd)
> display _newline " NNT = " `nnt' " (`c(level)'% CI: "
> `ub' "; " `lb' ")"
> end
>
> It utilizes -cs- (see [ST] epitab); the -return list- command
> discloses among
> other things: r(rd), r(ub_rd), and r(lb_rd).
>
> Actually, the -lbw- dataset is from a case-control study, so
> don't imagine
> it can be used to estimate absolute risks, risk differences, or NNT.
> Here we forget this reservation:
>
> . webuse lbw.dta
> (Hosmer & Lemeshow data)
>
> . cs_nnt low smoke
>
> | smoked during pregnancy|
> | Exposed Unexposed | Total
> -----------------+------------------------+------------
> Cases | 30 29 | 59
> Noncases | 44 86 | 130
> -----------------+------------------------+------------
> Total | 74 115 | 189
> | |
> Risk | .4054054 .2521739 | .3121693
> | |
> | Point estimate | [95% Conf. Interval]
> |------------------------+------------------------
> Risk difference | .1532315 | .0160718
> .2903912
> Risk ratio | 1.607642 | 1.057812
> 2.443262
> Attr. frac. ex. | .377971 | .0546528
> .5907112
> Attr. frac. pop | .1921887 |
> +-------------------------------------------------
> chi2(1) = 4.92 Pr>chi2 = 0.0265
>
> NNT = 6.5260736 (95% CI: 3.4436304; 62.220882)
>
> Interpretation: For each 6.5 smokers we produce one low
> birthweight baby.
> The confidence interval tells about the uncertainty of this estimate.
>
> NNT is claimed to make communication with patients easier,
> and that may
> sometimes be the case. But things may also be made more
> difficult. Here
> we try with a non-existent association, creating the random binary
> variable -x-:
>
> . set seed 12345
> . gen x = uniform()>0.5
> . cs_nnt low x
>
> | x |
> | Exposed Unexposed | Total
> -----------------+------------------------+------------
> Cases | 34 25 | 59
> Noncases | 65 65 | 130
> -----------------+------------------------+------------
> Total | 99 90 | 189
> | |
> Risk | .3434343 .2777778 | .3121693
> | |
> | Point estimate | [95% Conf. Interval]
> |------------------------+------------------------
> Risk difference | .0656566 | -.0659201
> .1972332
> Risk ratio | 1.236364 | .8040256
> 1.901177
> Attr. frac. ex. | .1911765 | -.2437415
> .4740101
> Attr. frac. pop | .1101695 |
> +-------------------------------------------------
> chi2(1) = 0.95 Pr>chi2 = 0.3306
>
> NNT = 15.230769 (95% CI: 5.0701399; -15.169883)
>
> The confidence interval is complicated; it actually means two
> intervals:
> 5.07 to infinity
> minus infinity to -15.17
> - the negative numbers meaning that exposure to x may prevent low
> birthweight.
>
> I am not sure that -cs_nnt- deserves to be made more public than this,
> but those who want can go on playing with it.
*
* 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/