Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Steve Samuels <sjsamuels@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Stata vs SAS Survey Risk Ratios |

Date |
Thu, 4 Apr 2013 20:46:43 -0400 |

Quite right. The -margins- with expression(log(predict(pr))) gets the arithmetic mean of the log predictions, which is the log of the geometric mean of the original predictions. There's an argument to be made, I think, that if you are interested in RRs, you should operate on the log probabilities. In any case, here's the corrected version based on the original probabilities. Steve *************CODE BEGINS************* capture program drop _all program antilog local bound invnorm(.975)*sqrt(el(r(V),1,1)) local lparm el(r(b),1,1) local ll exp(`lparm' - `bound') local ul exp( `lparm' + `bound') di _col(1) "parm = " %8.4g exp(`lparm') /// _col(20) "ll =" %8.4g `ll' /// _col(40) "ul =" %8.4g `ul' end sysuse auto, clear recode rep78 1/2=5 svyset _n svy: logistic foreign turn i.rep78 margins rep78, post /* RR 4 vs 3 */ qui nlcom log(_b[4.rep78])-log(_b[3.rep78]) antilog /* RR 5 vs 3 */ qui nlcom log(_b[5.rep78]) -log(_b[3.rep78]) antilog *************CODE ENDS******************* On Apr 4, 2013, at 5:01 PM, Joshua Josephs wrote: Dear Steve, Thanks for your reply. I went through your code and found something Im puzzled by. When you first get the margins command it says the predicted probability for level3 of rep78 is .155153. You then ask for the next margins command to give you the log predicted probability and it gives -3.672796 which is not the log of .155153. Thanks, Josh -----Original Message----- From: "Steve Samuels" [sjsamuels@gmail.com] Date: 04/04/2013 01:53 PM To: "" <statalist@hsphsun2.harvard.edu> Subject: Re: st: Stata vs SAS Survey Risk Ratios No survey command in Stata uses maximum likelihood, but many solve pseudo-likelihood equations. -svy: glm- with family(binomial) link(log) options would give risk ratios directly, but convergence is sometimes difficult. I would use -svy: logistic- myself: *************CODE BEGINS************* sysuse auto, clear recode rep78 1/2=5 svyset _n svy: logistic foreign turn i.rep78 margins rep78, coeflegend post /* RR 4 vs 3 */ nlcom _b[4.rep78]/_b[3bn.rep78] /* RR 5 vs 3 */ nlcom _b[5.rep78]/_b[3bn.rep78] /* Notice Lower limits above <0. This happens because -nlcom- uses the delta method, which doesn't know about the boundaries. Try again using knowledge that RR>0 */ capture program drop _all program antilog local bound invnorm(.975)*r(se) local lparm r(estimate) local ll exp(`lparm' - `bound') local ul exp( `lparm' + `bound') di _col(1) "parm = " %8.4g exp(`lparm') /// _col(20) "ll =" %8.4g `ll' /// _col(40) "ul =" %8.4g `ul' end svy: logistic foreign turn i.rep78 margins rep78, expression(log(predict(pr))) post /* RR 4 vs 3 */ qui lincom _b[4.rep78]-_b[3bn.rep78] antilog /* RR 5 vs 3 */ qui lincom _b[5.rep78]-_b[3bn.rep78] antilog *****************CODE ENDS ************** On Apr 4, 2013, at 10:48 AM, Joshua Josephs wrote: Dear StataListers, Im trying to find out exactly what Stata does compared to SAS in calculating risk ratios from survey data. In SAS you calculate a survey logistic regression and then use average predicted margins to get the risk ratios. In Stata you use the svy glm command which uses maximum likelihood. Im trying to find out if Statas method provides the appropriate estimates and confidence intervals. Any help is appreciated, Joshua Josephs * * 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/

**References**:**Re: st: Stata vs SAS Survey Risk Ratios***From:*"Joshua Josephs" <backpacker24@excite.com>

- Prev by Date:
**st: LM (score) test for omitted variable after probit** - Next by Date:
**st: relation between 2 coefficients in a regression analysis** - Previous by thread:
**Re: st: Stata vs SAS Survey Risk Ratios** - Next by thread:
**st: Bar graph with frequency** - Index(es):