Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Calculating confidence intervals for the ratio of stratified standardised mortality rates
From
Steve Samuels <[email protected]>
To
[email protected]
Subject
Re: st: Calculating confidence intervals for the ratio of stratified standardised mortality rates
Date
Mon, 11 Nov 2013 17:12:34 -0500
You are welcome, Paul. A couple of inessential improvements:
1. For:
slr = sqrt((s1:/a1):*(s1:/a1) +(s2:/a2):*(s2:/a2))
substitute:
slr = sqrt((s1:/a1):^2 +(s2:/a2):^2)
s1, s2, a1, and a2 are matrices, and
the ":" before an arithmetic operation tells
Mata to apply the operation to every element
of the matrices.
2. For:
z = -invnormal((100 - st_numscalar("c(level)"))/200)
Substitute:
z = invnormal(.5 + st_numscalar("c(level)")/200)
Steve
On Nov 11, 2013, at 1:41 AM, Paul Mee wrote:
Steve
Thanks for the detailed answer , much appreciated
Paul
Paul Mee
Senior Data Scientist
MRC/Wits Rural Public Health and Health Transitions Research Unit (Agincourt) School of Public Health University of Witwatersrand
SA Office Number +27 (0) 13 795 5076 (tel/fax)
SA Mobile No. -+27(0)769 845170
UK Mobile No. +44 (0) 7793 366486
e-mail: [email protected]
Skype: paul.mee
This communication is intended for the addressee only. It is confidential. If you have received this communication in error, please notify us immediately and destroy the original message. You may not copy or disseminate this communication without the permission of the University. Only authorized signatories are competent to enter into agreements on behalf of the University and recipients are thus advised that the content of this message may not be legally binding on the University and may contain the personal views and opinions of the author, which are not necessarily the views and opinions of The University of the Witwatersrand, Johannesburg. All agreements between the University and outsiders are subject to South African Law unless the University agrees in writing to the contrary.
P Please don't print this e-mail unless you really need to. Thank you.
-----Original Message-----
From: Steve Samuels [mailto:[email protected]]
Sent: 09 November 2013 19:24
To: [email protected]
Subject: Re: st: Calculating confidence intervals for the ratio of stratified standardised mortality rates
I see some code specific to my test data set got into the last part.
I've revised to be specific to Paul's problem.
Steve
Here's the Mata version after all. It requires only two
-dstdize- calls and will produce the rate ratio and CI for any number of categories.
************************************
forvalues i = 1/2 {
dstdize ... by(all_data) using(), ///
if time==`i'
mata: a`i' = st_matrix("r(adj)")
mata: s`i' = st_matrix("r(se)")
}
mata:
ratio = a1:/a2
lr = log(ratio)
slr = ///
sqrt((s1:/a1):*(s1:/a1) +(s2:/a2):*(s2:/a2)) z = ///
-invnormal((100 -st_numscalar("c(level)"))/200) lower = exp(lr - z:*slr) upper = exp(lr + z:*slr) d=(ratio \ lower \ upper)'
end
clear
getmata (ratio lower upper) = d
gen all_data=_n
format ratio lower upper %8.3f
list all_data ratio lower upper
save results, replace
*********************************.
>
> Your question isn't quite clear, but I assume that you mean that you
> want a comparison of the two time periods for each category of
> "all_data". Here is code for a single category of all_data. You can
> get results for all categories with a -foreach- or -forvalues- loop.
>
> ******************************************
> dstdize ... if all_data==1, by(time) using...
>
> matrix a = r(adj)
> matrix s = r(se)
> scalar ratio = a[1,1]/a[1,2]
> scalar slr =
> sqrt((s[1,1]/a[1,1])^2 + (s[1,2]/a[1,2])^2) scalar bound =
> -slr*invnorm((1 -c(level)/100)/2)
> scalar upper = exp(log(ratio) + bound) scalar lower = exp(log(ratio)
> -bound) scalar list ratio lower upper
> ******************************************
>
> The formula for the log scale SE (slr) is based on the large sample
> result that for an estimate R the delta method estimate of variance is:
>
> var (log W)≈ var(W)/W
>
> The formula applies to each component of the log ratio, since they are
> independent.
>
> log ratio = log(adj rate 1) - log(adj rate 2)
>
> I also have a Mata-based solution that is likely faster if you have a
> lot of all_data categories and that puts the results into a data set.
> It's a bit too long to list here. If you'd like to see it, join
> stackoverflow.com and ask your question in the Stata area
> http://stackoverflow.com/questions/tagged/stata.
>
> Steve
>
On Nov 7, 2013, at 9:08 AM, Paul Mee wrote:
>
> All
>
> Apologies if this is a rather naive question but I hope someone can help me.
>
> I have been calculating age/sex standardised mortality rates
> stratified by geographical areas I used dstdize for this in stata and
> it worked fine and gave me the standardised rates and importantly
> confidence intervals which I extracted from the relevant
> macros/matrices . For reference this is the command I used
>
> dstdize total_hiv_tb_death population adj_cat, by(all_data) ///
> using("C:\work\Research\Analysis\Paper1_mortality\stata\rates\std_pop_
> 09_10.dta") level(90)
>
> No I need to calculate the ratio between the standardised mortality rates in two time periods (i.e. from different separate dstdize commands ) and calculate confidence intervals for these mortality rate ratios .
>
> Any help with how to do this in stata would be very much appreciated.
>
> Paul
>
> [email protected]
>
>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="width:100%;">
<tr>
<td align="left" style="text-align:justify;"><font face="arial,sans-serif" size="1" color="#999999"><span style="font-size:11px;">This communication is intended for the addressee only. It is confidential. If you have received this communication in error, please notify us immediately and destroy the original message. You may not copy or disseminate this communication without the permission of the University. Only authorised signatories are competent to enter into agreements on behalf of the University and recipients are thus advised that the content of this message may not be legally binding on the University and may contain the personal views and opinions of the author, which are not necessarily the views and opinions of The University of the Witwatersrand, Johannesburg. All agreements between the University and outsiders are subject to South African Law unless the University agrees in writing to the contrary. </span></font></td>
</tr>
</table>
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/