title: glm and relative risk -replicate Stata code in R
body: <p>Could anyone help me replicate these relative risk calculations (and its confidence interval) in R?</p>
  
  <p>A similar procedure used in Stata is described <a href="http://www.ats.ucla.edu/stat/stata/faq/relative_risk.htm" rel="nofollow">here</a>. Could anyone show me how to do this in R (my data has clusters and strata but I've taken a simpler example)? I've tried the relrisk.est function but I'd rather use the survey package as this handles very complex designs. I'd also like to compare Stata and R estimates.I'm using Poisson as suggested <a href="http://r.789695.n4.nabble.com/relative-risk-regression-with-survey-data-td2538241.html" rel="nofollow">here</a>. </p>
  
  <pre><code>###STATA CODE
  use http://www.ats.ucla.edu/stat/stata/faq/eyestudy 
  tabulate carrot lenses
  *same as R binomial svyglm below
  xi: glm lenses carrot, fam(bin) 
  *switch reference code
  char carrot[omit] 1
  xi: glm lenses i.carrot, fam(poisson) link(log) nolog robust eform
  
  ###R
  library(foreign)
  library(survey)
  D&lt;-read.dta("http://www.ats.ucla.edu/stat/stata/faq/eyestudy.dta")
  table(D$lenses,D$carrot)
  D$wgt&lt;-rep(1,nrow(D))
  Dd&lt;-svydesign(id=~1,data=D,weights=~wgt)
  #change category and eform....?
  svyglm(lenses~carrot,Dd,family=binomial)
  svyglm(lenses~carrot,Dd,family=quasipoisson(log))
  </code></pre>