Models and estimation
Start with the expanded example for each command. Open the variants for options and alternative R approaches. Read the qualifications before adapting the code.
betareg
Fit beta regression with a cloglog mean link
Stata
betareg share x, link(cloglog)R Package:betareg
betareg::betareg(share~x,data=data,link="cloglog",type="ML",link.phi="log")Differs from Stata Uses ordinary ML with a log link for precision, matching Stata slink(log). Without link.phi=“log”, betareg reports constant phi on the identity scale while Stata reports ln(phi). Responses must lie strictly inside (0,1).
Fit beta regression with a logit mean link
Stata
betareg share x, link(logit)R Package:betareg
betareg::betareg(share~x,data=data,link="logit",type="ML",link.phi="log")Differs from Stata Uses ordinary ML with a log link for precision, matching Stata slink(log). Without link.phi=“log”, betareg reports constant phi on the identity scale while Stata reports ln(phi). Responses must lie strictly inside (0,1).
Fit beta regression with a probit mean link
Stata
betareg share x, link(probit)R Package:betareg
betareg::betareg(share~x,data=data,link="probit",type="ML",link.phi="log")Differs from Stata Uses ordinary ML with a log link for precision, matching Stata slink(log). Without link.phi=“log”, betareg reports constant phi on the identity scale while Stata reports ln(phi). Responses must lie strictly inside (0,1).
Model beta-regression precision using a covariate
Stata
betareg share x, scale(z) slink(log)R Package:betareg
betareg::betareg(share~x|z,data=data,link="logit",link.phi="log",type="ML")Differs from Stata Uses a log link for precision; align Stata scale-link parameterization before numerical comparison.
binreg
Fit binomial regression on the or scale
Stata
binreg b i.g, orR Package:stats
stats::glm(b ~ factor(g),data=data,family=stats::binomial(link="logit"))Differs from Stata Risk-ratio and risk-difference models can encounter boundary and convergence problems; inspect fitted probabilities.
Fit binomial regression on the rd scale
Stata
binreg b i.g, rdR Package:stats
stats::glm(b ~ factor(g),data=data,family=stats::binomial(link="identity"))Differs from Stata Risk-ratio and risk-difference models can encounter boundary and convergence problems; inspect fitted probabilities.
Fit binomial regression on the rr scale
Stata
binreg b i.g, rrR Package:stats
stats::glm(b ~ factor(g),data=data,family=stats::binomial(link="log"))Differs from Stata Risk-ratio and risk-difference models can encounter boundary and convergence problems; inspect fitted probabilities.
boxcox
Profile the Box-Cox response transformation parameter
Stata
boxcox y x z, model(lhsonly)R Package:MASS
MASS::boxcox(y ~ x+z,data=data,lambda=seq(-1,1,by=0.1),plotit=FALSE)Profiles a grid of response-transform parameters; this does not implement all Stata boxcox predictor-transform models.
bsqreg
Bootstrap quantile-regression inference
Stata
bsqreg y x z, reps(99)R Package:quantreg
{ fit <- quantreg::rq(y~x+z,data=data,tau=0.5); summary(fit,se="boot",R=99) }Differs from Stata Uses 99 bootstrap replications for quantile-regression inference. R and Stata random streams and resampling implementations differ, so bootstrap standard errors will not be identical.
cloglog
Fit cloglog regression
Stata
cloglog b x zR Package:stats
stats::glm(b ~ x + z,data=data,family=stats::binomial(link="cloglog"))Differs from Stata R uses the complementary log-log link. Match the event category and complete cases; the GLM result object and convergence tolerances differ from Stata cloglog.
Fit cloglog without an intercept
Stata
cloglog b x z, noconstantR Package:stats
stats::glm(b ~ x + z - 1,data=data,family=stats::binomial(link="cloglog"))Differs from Stata R uses the complementary log-log link. Match the event category and complete cases; the GLM result object and convergence tolerances differ from Stata cloglog.
cnsreg
Fit OLS with two coefficients constrained to equality
Stata
constraint define 1 x = z
cnsreg y x z, constraints(1)R Package:stats
{ fit <- stats::lm(y~I(x+z),data=data); c(intercept=unname(stats::coef(fit)[1]),x=unname(stats::coef(fit)[2]),z=unname(stats::coef(fit)[2])) }Fixed workflow. First define constraint 1 x = z in Stata. Reparameterization imposes this fixed linear constraint; covariance reporting needs the corresponding coefficient transformation.
constraint
Represent a linear equality constraint as a matrix
Stata
constraint define 1 x = zR Package:stats
L <- matrix(c(0,1,-1),nrow=1,dimnames=list(NULL,c("intercept","x","z")))Fixed workflow: L beta = 0 encodes equal x and z coefficients. A fitting routine must enforce the constraint.
eivreg
Correct a simple regression slope for known predictor reliability
Stata
eivreg y x, reliability(x 0.8)R Package:stats
{ slope <- stats::cov(data$x,data$y)/(0.8*stats::var(data$x)); c(intercept=mean(data$y)-slope*mean(data$x),x=slope) }Coefficient-only workflow for one error-prone predictor with known reliability and classical independent measurement error; no EIV standard errors are supplied.
fracreg
Fit fractional logit regression with sandwich inference
Stata
fracreg logit share xR Package:sandwich
{ fit <- stats::glm(share ~ x,data=data,family=stats::quasibinomial(link="logit")); lmtest::coeftest(fit,vcov.=sandwich::vcovHC(fit,type="HC0"),df=Inf) }Differs from Stata Quasi-binomial fit avoids a noninteger-success warning. Sandwich inference is explicit; finite-sample corrections can differ.
Fit fractional probit regression with sandwich inference
Stata
fracreg probit share xR Package:sandwich
{ fit <- stats::glm(share ~ x,data=data,family=stats::quasibinomial(link="probit")); lmtest::coeftest(fit,vcov.=sandwich::vcovHC(fit,type="HC0"),df=Inf) }Differs from Stata Quasi-binomial fit avoids a noninteger-success warning. Sandwich inference is explicit; finite-sample corrections can differ.
glm
Fit a binomial complementary-log-log GLM
Stata
glm b x z, family(binomial) link(cloglog)R Package:stats
stats::glm(b ~ x + z, data=data, family=stats::binomial(link="cloglog"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
12 more examples and alternatives
Fit a binomial logit-link GLM
Stata
glm b x z, family(binomial) link(logit)R Package:stats
stats::glm(b ~ x + z, data=data, family=stats::binomial())Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a binomial probit-link GLM
Stata
glm b x z, family(binomial) link(probit)R Package:stats
stats::glm(b ~ x + z, data=data, family=stats::binomial(link="probit"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a Poisson log-link GLM
Stata
glm count x z, family(poisson) link(log)R Package:stats
stats::glm(count ~ x + z, data=data, family=stats::poisson())Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a Poisson identity-link GLM
Stata
glm count x, family(poisson) link(identity)R Package:stats
stats::glm(count ~ x, data=data, family=stats::poisson(link="identity"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit grouped-binomial events and trials
Stata
glm events x, family(binomial trials) link(logit)R Package:stats
stats::glm(cbind(events,trials-events) ~ x,data=data,family=stats::binomial())Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a gamma log-link model for positive outcomes
Stata
glm y x z, family(gamma) link(log)R Package:stats
stats::glm(y ~ x + z, data=data, family=stats::Gamma(link="log"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a Gaussian identity-link GLM
Stata
glm y x z, family(gaussian) link(identity)R Package:stats
stats::glm(y ~ x + z, data=data, family=stats::gaussian())Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a Gaussian log-link GLM
Stata
glm y x z, family(gaussian) link(log)R Package:stats
stats::glm(y ~ x + z, data=data, family=stats::gaussian(link="log"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a gamma identity-link model
Stata
glm y x, family(gamma) link(identity)R Package:stats
stats::glm(y ~ x, data=data, family=stats::Gamma(link="identity"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit a gamma inverse-link model
Stata
glm y x, family(gamma) link(inverse)R Package:stats
stats::glm(y ~ x, data=data, family=stats::Gamma(link="inverse"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit an inverse Gaussian identity-link model
Stata
glm y x, family(igaussian) link(identity)R Package:stats
stats::glm(y ~ x, data=data, family=stats::inverse.gaussian(link="identity"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
Fit an inverse Gaussian log-link model
Stata
glm y x, family(igaussian) link(log)R Package:stats
stats::glm(y ~ x, data=data, family=stats::inverse.gaussian(link="log"))Differs from Stata The family and link are explicit. R and Stata can use different dispersion scaling and reference tests even when fitted means agree; align the sample and scale option before comparing standard errors.
hetregress
Fit a normal mean model with multiplicative heteroskedasticity
Stata
hetregress y x, het(z)R Package:nlme
nlme::gls(y~x,data=data,weights=nlme::varExp(form=~z),method="ML")Differs from Stata nlme models SD as exp(thetaz), so the coefficient on z in Stata log variance is 2theta.
intreg
Fit normal regression to interval-valued outcomes
Stata
intreg lower upper x zR Package:survival
survival::survreg(survival::Surv(lower,upper,type="interval2")~x+z,data=data,dist="gaussian")Differs from Stata Uses survreg as a Gaussian interval-likelihood engine for a cross-sectional outcome, without a time-to-event interpretation.
iqreg
Estimate slopes of the interquartile range
Stata
iqreg y x z, quantiles(25 75)R Package:quantreg
{ fit <- quantreg::rq(y ~ x+z,data=data,tau=c(0.25,0.75)); stats::coef(fit)[,2]-stats::coef(fit)[,1] }Coefficient workflow only; obtain standard errors by jointly resampling both quantile fits.
logistic
Report logistic odds ratios
Stata
logistic b x zR Package:stats
{ fit <- stats::glm(b ~ x+z,data=data,family=stats::binomial()); exp(stats::coef(fit)) }Differs from Stata Exponentiates the binomial logit coefficients to odds ratios. Returns point estimates only, without the confidence intervals and tests printed by Stata logistic.
logit
Fit logit regression
Stata
logit b x zR Package:stats
stats::glm(b ~ x + z,data=data,family=stats::binomial(link="logit"))Differs from Stata R uses a binomial GLM with the logit link and returns coefficients on the log-odds scale. Match binary coding and complete cases; Stata iteration diagnostics and stored result structure differ.
1 more examples and alternatives
Fit logit without an intercept
Stata
logit b x z, noconstantR Package:stats
stats::glm(b ~ x + z - 1,data=data,family=stats::binomial(link="logit"))Differs from Stata R uses a binomial GLM with the logit link and returns coefficients on the log-odds scale. Match binary coding and complete cases; Stata iteration diagnostics and stored result structure differ.
mlexp
Maximize an explicitly defined normal likelihood
Stata
mlexp (lnnormalden(y,{mu},exp({lnsigma})))R Package:stats
stats::optim(c(mu=mean(data$y),log_sigma=log(stats::sd(data$y))),function(par) -sum(stats::dnorm(data$y,mean=par[1],sd=exp(par[2]),log=TRUE)),method="BFGS",hessian=TRUE)Differs from Stata R optimizes log sigma to enforce positivity; translate the scale parameter back using exp().
mlogit
Fit multinomial logit with a chosen reference outcome
Stata
mlogit g x z, baseoutcome(4)R Package:nnet
nnet::multinom(stats::relevel(factor(g), ref = "4") ~ x+z,data=data,trace=FALSE)Differs from Stata Relevels outcome category 4 to the first R factor level, matching baseoutcome(4). Coefficient labels and optimization criteria differ; keep the same observations and category support.
nbreg
Fit NB2 negative-binomial regression
Stata
nbreg count x zR Package:MASS
MASS::glm.nb(count ~ x+z,data=data)Differs from Stata Both use NB2 variance mu+alpha*mu^2; MASS theta is 1/alpha.
nl
Fit a nonlinear saturating response curve
Stata
nl (y = {a=1} + {b=2}*x/({c=1}+x))R Package:stats
stats::nls(y ~ a+b*x/(c+x),data=data,start=list(a=1,b=2,c=1))Differs from Stata Fits this explicit nonlinear mean function from the supplied starting values. nls and Stata nl use different convergence controls and can reach different local solutions.
Fit a nonlinear exponential mean curve
Stata
nl (y = {a=2}*exp({b=0.2}*x))R Package:stats
stats::nls(y ~ a*exp(b*x),data=data,start=list(a=2,b=0.2))Differs from Stata Fits this explicit nonlinear mean function from the supplied starting values. nls and Stata nl use different convergence controls and can reach different local solutions.
ologit
Fit ordered ologit regression
Stata
ologit y x zR Package:MASS
MASS::polr(y ~ x+z,data=data,method="logistic",Hess=TRUE)Differs from Stata MASS uses cumulative link intercepts; compare cutpoint and slope sign conventions.
oprobit
Fit ordered oprobit regression
Stata
oprobit y x zR Package:MASS
MASS::polr(y ~ x+z,data=data,method="probit",Hess=TRUE)Differs from Stata MASS uses cumulative link intercepts; compare cutpoint and slope sign conventions.
poisson
Fit Poisson rates with exposure
Stata
poisson count x z, exposure(exposure)R Package:stats
stats::glm(count ~ x+z+offset(log(exposure)),data=data,family=stats::poisson())Differs from Stata Uses the explicit log offset where shown; exposure must be strictly positive. R returns a glm object or exponentiated coefficients, rather than the Stata estimation table; align overdispersion and robust variance options.
2 more examples and alternatives
Report Poisson incidence-rate ratios
Stata
poisson count x z, irrR Package:stats
{ fit <- stats::glm(count~x+z,data=data,family=stats::poisson()); exp(stats::coef(fit)) }Differs from Stata Uses the explicit log offset where shown; exposure must be strictly positive. R returns a glm object or exponentiated coefficients, rather than the Stata estimation table; align overdispersion and robust variance options.
Fit Poisson regression without an intercept
Stata
poisson count x z, noconstantR Package:stats
stats::glm(count ~ x+z-1,data=data,family=stats::poisson())Differs from Stata Uses the explicit log offset where shown; exposure must be strictly positive. R returns a glm object or exponentiated coefficients, rather than the Stata estimation table; align overdispersion and robust variance options.
probit
Fit probit regression
Stata
probit b x zR Package:stats
stats::glm(b ~ x + z,data=data,family=stats::binomial(link="probit"))Differs from Stata R uses the probit binomial GLM. Match binary coding and complete cases; the GLM result object and convergence tolerances differ from Stata probit.
1 more examples and alternatives
Fit probit without an intercept
Stata
probit b x z, noconstantR Package:stats
stats::glm(b ~ x + z - 1,data=data,family=stats::binomial(link="probit"))Differs from Stata R uses the probit binomial GLM. Match binary coding and complete cases; the GLM result object and convergence tolerances differ from Stata probit.
qreg
Fit conditional quantile 25 regression
Stata
qreg y x z, quantile(25)R Package:quantreg
quantreg::rq(y ~ x+z,data=data,tau=0.25)Differs from Stata Fits the selected conditional quantile. rq and Stata qreg use different optimization and default covariance estimators; coefficient agreement does not establish standard-error parity.
1 more examples and alternatives
Fit conditional quantile 75 regression
Stata
qreg y x z, quantile(75)R Package:quantreg
quantreg::rq(y ~ x+z,data=data,tau=0.75)Differs from Stata Fits the selected conditional quantile. rq and Stata qreg use different optimization and default covariance estimators; coefficient agreement does not establish standard-error parity.
regress
Fit a quadratic regression
Stata
regress y c.x##c.xR Package:stats
stats::lm(y ~ x + I(x^2), data=data)Differs from Stata OLS coefficient correspondence requires the same complete-case sample, contrasts and weights. R returns an lm object; Stata coefficient tables and stored estimates have a different structure.
11 more examples and alternatives
Include two continuous main effects and their interaction
Stata
regress y c.x##c.zR Package:stats
stats::lm(y ~ x * z, data=data)Differs from Stata OLS coefficient correspondence requires the same complete-case sample, contrasts and weights. R returns an lm object; Stata coefficient tables and stored estimates have a different structure.
Fit separate linear slopes by group
Stata
regress y c.x##i.gR Package:stats
stats::lm(y ~ x * factor(g), data=data)Differs from Stata OLS coefficient correspondence requires the same complete-case sample, contrasts and weights. R returns an lm object; Stata coefficient tables and stored estimates have a different structure.
Adjust regression for a categorical predictor
Stata
regress y i.g c.xR Package:stats
stats::lm(y ~ factor(g) + x, data=data)Differs from Stata OLS coefficient correspondence requires the same complete-case sample, contrasts and weights. R returns an lm object; Stata coefficient tables and stored estimates have a different structure.
Fit analytic-weighted least squares
Stata
regress y x [aweight=w]R Package:stats
stats::lm(y ~ x, data=data, weights=w)Differs from Stata Weights are proportional inverse variances. Check scale and residual degrees of freedom before comparing software.
Fit linear regression in a specified subgroup
Stata
regress y x z if b == 1R Package:stats
stats::lm(y ~ x + z, data=data, subset=b == 1)Differs from Stata OLS coefficient correspondence requires the same complete-case sample, contrasts and weights. R returns an lm object; Stata coefficient tables and stored estimates have a different structure.
Report standardized linear regression slopes
Stata
regress y x z, betaR Package:stats
{ fit <- stats::lm(y ~ x + z, data=data); stats::coef(fit)[c("x","z")] * vapply(data[c("x","z")], stats::sd, numeric(1)) / stats::sd(data$y) }Differs from Stata OLS coefficient correspondence requires the same complete-case sample, contrasts and weights. R returns an lm object; Stata coefficient tables and stored estimates have a different structure.
Fit linear regression through the origin
Stata
regress y x z, noconstantR Package:stats
stats::lm(y ~ x + z - 1, data=data)Differs from Stata OLS coefficient correspondence requires the same complete-case sample, contrasts and weights. R returns an lm object; Stata coefficient tables and stored estimates have a different structure.
Use one-way clustered standard errors with cluster degrees of freedom
Stata
regress y x z, vce(cluster g)R Package:sandwich
{ fit <- stats::lm(y ~ x + z, data = data, subset = !is.na(g)); lmtest::coeftest(fit, vcov. = sandwich::vcovCL(fit, cluster = ~g, type = "HC1"), df = length(unique(stats::expand.model.frame(fit, ~g)$g)) - 1L) }Differs from Stata Only three clusters in this demonstration fixture; substantive applications need adequate independent clusters.
Report HC2 heteroskedasticity-robust OLS inference
Stata
regress y x z, vce(hc2)R Package:sandwich
{ fit <- stats::lm(y~x+z,data=data); lmtest::coeftest(fit, vcov.=sandwich::vcovHC(fit,type="HC2")) }Differs from Stata Coefficient estimates are OLS; covariance correction is selected explicitly.
Report HC3 heteroskedasticity-robust OLS inference
Stata
regress y x z, vce(hc3)R Package:sandwich
{ fit <- stats::lm(y~x+z,data=data); lmtest::coeftest(fit, vcov.=sandwich::vcovHC(fit,type="HC3")) }Differs from Stata Coefficient estimates are OLS; covariance correction is selected explicitly.
Report HC1 heteroskedasticity-robust OLS inference
Stata
regress y x z, vce(robust)R Package:sandwich
{ fit <- stats::lm(y~x+z,data=data); lmtest::coeftest(fit, vcov.=sandwich::vcovHC(fit,type="HC1")) }Differs from Stata Coefficient estimates are OLS; covariance correction is selected explicitly.
rreg
Fit a resistant bisquare regression
Stata
rreg y x zR Package:MASS
MASS::rlm(y ~ x+z,data=data,psi=MASS::psi.bisquare,init="lts",maxit=100)Workflow equivalent: Stata rreg uses its own screening and iteration sequence, so coefficients need not match.
sqreg
Fit several conditional quantiles together
Stata
sqreg y x z, quantiles(25 50 75)R Package:quantreg
quantreg::rq(y ~ x+z,data=data,tau=c(0.25,0.5,0.75))This fits coefficients; Stata sqreg also bootstraps their joint covariance. Use a shared-resample bootstrap for joint inference.
tobit
Fit a left-censored normal Tobit model
Stata
tobit y x z, ll(0)R Package:AER
AER::tobit(y~x+z,data=data,left=0)Differs from Stata Uses the explicit left and/or right censoring limits. AER returns a survreg-based Gaussian censored model; scale parameter reporting and coefficient-table inference differ from Stata.
2 more examples and alternatives
Fit a two-limit censored normal model
Stata
tobit y x z, ll(0) ul(2)R Package:AER
AER::tobit(y~x+z,data=data,left=0,right=2)Differs from Stata Uses the explicit left and/or right censoring limits. AER returns a survreg-based Gaussian censored model; scale parameter reporting and coefficient-table inference differ from Stata.
Fit a right-censored normal Tobit model
Stata
tobit y x z, ul(2)R Package:AER
AER::tobit(y~x+z,data=data,left=-Inf,right=2)Differs from Stata Uses the explicit left and/or right censoring limits. AER returns a survreg-based Gaussian censored model; scale parameter reporting and coefficient-table inference differ from Stata.
zinb
Fit a zero-inflated NB2 count model
Stata
zinb count x, inflate(z)R Package:pscl
pscl::zeroinfl(count~x|z,data=data,dist="negbin",link="logit")Differs from Stata Negative-binomial theta is reciprocal to Stata alpha in the NB2 component.
zip
Fit zero-inflated Poisson with logit zero inflation
Stata
zip count x, inflate(z)R Package:pscl
pscl::zeroinfl(count~x|z,data=data,dist="poisson",link="logit")Differs from Stata Fits the stated zero-inflated Poisson model with separate count and inflation equations. Match the inflation link, offsets and complete cases; optimizers and coefficient labels differ.
Fit zero-inflated Poisson with probit zero inflation
Stata
zip count x, inflate(z) probitR Package:pscl
pscl::zeroinfl(count~x|z,data=data,dist="poisson",link="probit")Differs from Stata Fits the stated zero-inflated Poisson model with separate count and inflation equations. Match the inflation link, offsets and complete cases; optimizers and coefficient labels differ.