Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

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

Re: st: Stata vs SAS Survey Risk Ratios

From   "Joshua Josephs" <>
Subject   Re: st: Stata vs SAS Survey Risk Ratios
Date   Thu, 04 Apr 2013 17:01:17 -0400

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. 

-----Original Message-----
From: "Steve Samuels" []
Date: 04/04/2013 01:53 PM
To: "" <>
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'

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]
/* RR 5 vs 3 */
qui lincom _b[5.rep78]-_b[3bn.rep78]
*****************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:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index