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]

From |
Steve Samuels <[email protected]> |

To |
[email protected] |

Subject |
Re: st: Calculating confidence intervals for the ratio of stratified standardised mortality rates |

Date |
Sat, 9 Nov 2013 12:23:48 -0500 |

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/

**Follow-Ups**:

**References**:

- Prev by Date:
**Re: st: FORVAL loop incomplete** - Next by Date:
**Re: st: FORVAL loop incomplete** - Previous by thread:
**Re: st: Calculating confidence intervals for the ratio of stratified standardised mortality rates** - Next by thread:
**RE: st: Calculating confidence intervals for the ratio of stratified standardised mortality rates** - Index(es):