Meta-analysis

Start with the expanded example for each command. Open the variants for options and alternative R approaches. Read the qualifications before adapting the code.

meta

Declare generic effect sizes and sampling variances

Stata

meta set yi sei

R Package:metafor

metafor::escalc(measure = "GEN", yi = yi, sei = sei, data = data)

Differs from Stata Both examples take standard errors as sei; metafor stores their squares as vi. escalc creates effect-size data but does not persist a Stata-style meta declaration, labels or a default analysis model.

Cumulative fixed-effect meta-analysis by year

Stata

meta summarize, cumulative(year)

R Package:metafor

metafor::cumul(metafor::rma(yi, vi, data = data, method = "REML"), order = data$year)

Differs from Stata Assumes meta set used its default random(reml) declaration; metafor explicitly selects REML. A prior Stata common/fixed/random declaration changes the target. Match study order, missingness and heterogeneity estimation before comparing summaries.

Inverse-variance meta-analysis using FE

Stata

meta summarize, fixed

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "FE")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Between-study variance estimators and confidence procedures must be matched; some R estimator names differ from Stata’s names.

Inverse-variance meta-analysis using DL

Stata

meta summarize, random(dlaird)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "DL")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Between-study variance estimators and confidence procedures must be matched; some R estimator names differ from Stata’s names.

Inverse-variance meta-analysis using ML

Stata

meta summarize, random(mle)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "ML")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Between-study variance estimators and confidence procedures must be matched; some R estimator names differ from Stata’s names.

Inverse-variance meta-analysis using REML

Stata

meta summarize, random(reml)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "REML")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Between-study variance estimators and confidence procedures must be matched; some R estimator names differ from Stata’s names.

27 more examples and alternatives

Rank-correlation small-study-effects test

Stata

meta bias, begg

R Package:metafor

metafor::ranktest(metafor::rma(yi, vi, data = data, method = "FE"))

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Rank-correlation and small-sample p-value conventions may differ.

Egger regression asymmetry test

Stata

meta bias, egger

R Package:metafor

metafor::regtest(metafor::rma(yi, vi, data = data, method = "REML"), model = "rma", predictor = "sei")

Differs from Stata Assumes the Stata meta declaration is its default random(reml). model=“rma” regresses the effects on their standard errors with additive REML heterogeneity; model=“lm” would instead use multiplicative dispersion. Small-study effects alone do not establish publication bias.

Log odds ratios and variances

Stata

meta esize a b c d, esize(lnoratio)

R Package:metafor

metafor::escalc(measure = "OR", ai = a, bi = b, ci = c, di = d, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Use treatment/control cell ordering consistently and select continuity corrections deliberately.

Log risk ratios and variances

Stata

meta esize a b c d, esize(lnrratio)

R Package:metafor

metafor::escalc(measure = "RR", ai = a, bi = b, ci = c, di = d, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Use treatment/control cell ordering consistently and select continuity corrections deliberately.

Risk differences and variances

Stata

meta esize a b c d, esize(rdiff)

R Package:metafor

metafor::escalc(measure = "RD", ai = a, bi = b, ci = c, di = d, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Use treatment/control cell ordering consistently and select continuity corrections deliberately.

Freeman-Tukey transformed proportions

Stata

meta esize cases n, esize(ftukeyprop)

R Package:metafor

metafor::escalc(measure = "PFT", xi = cases, ni = n, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Transformation definitions and back-transformation choices, especially double-arcsine, require care.

Logit-transformed study proportions

Stata

meta esize cases n, esize(logitprop)

R Package:metafor

metafor::escalc(measure = "PLO", xi = cases, ni = n, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Transformation definitions and back-transformation choices, especially double-arcsine, require care.

Raw study proportions and variances

Stata

meta esize cases n, esize(proportion)

R Package:metafor

metafor::escalc(measure = "PR", xi = cases, ni = n, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Transformation definitions and back-transformation choices, especially double-arcsine, require care.

Uncorrected Cohen standardized mean differences

Stata

meta esize n1 m1 sd1 n0 m0 sd0, esize(cohend)

R Package:metafor

metafor::escalc(measure = "SMD", m1i = m1, sd1i = sd1, n1i = n1, m2i = m0, sd2i = sd0, n2i = n0, data = data, correct = FALSE)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Sampling-variance estimators for standardized effects must be matched.

Bias-corrected standardized mean differences

Stata

meta esize n1 m1 sd1 n0 m0 sd0, esize(hedgesg)

R Package:metafor

metafor::escalc(measure = "SMD", m1i = m1, sd1i = sd1, n1i = n1, m2i = m0, sd2i = sd0, n2i = n0, data = data)

Differs from Stata metafor SMD uses the exact gamma-function Hedges correction. Stata hedgesg uses its approximation by default; specify esize(hedgesg, exact) to align that correction, and also match the sampling-variance formula.

Unstandardized mean differences

Stata

meta esize n1 m1 sd1 n0 m0 sd0, esize(mdiff)

R Package:metafor

metafor::escalc(measure = "MD", m1i = m1, sd1i = sd1, n1i = n1, m2i = m0, sd2i = sd0, n2i = n0, data = data, vtype = "HO")

Differs from Stata vtype=“HO” uses the pooled within-group variance, matching Stata esize(mdiff) default equal-variance sampling variance. metafor default vtype=“LS” instead uses separate group variances; use it with Stata unequal.

Raw correlations and sampling variances

Stata

meta esize r n, correlation

R Package:metafor

metafor::escalc(measure = "COR", ri = r, ni = n, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Correlations must be within (-1,1); sampling variance depends on transformation.

Fisher-z transformed correlations

Stata

meta esize r n, fisherz

R Package:metafor

metafor::escalc(measure = "ZCOR", ri = r, ni = n, data = data)

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Correlations must be within (-1,1); sampling variance depends on transformation.

Meta-regression on centered publication year

Stata

meta regress c.year

R Package:metafor

metafor::rma(yi = yi, vi = vi, mods = ~year, data = data, method = "REML")

Differs from Stata Uses year on its original scale, so the intercept refers to year zero as in the Stata command. Assumes the Stata declared model is random(REML); match its model declaration and standard-error options.

Categorical meta-regression with Knapp-Hartung inference

Stata

meta regress i.x, random(reml)

R Package:metafor

metafor::rma(yi, vi, mods = ~factor(x), data = data, method = "REML")

Differs from Stata Uses ordinary normal-reference REML meta-regression, as shown by the Stata command without se(khartung). Knapp-Hartung would require an explicit option in both systems. Moderator associations are study-level, not causal subgroup effects.

Random-effects meta-regression with moderator

Stata

meta regress x

R Package:metafor

metafor::rma(yi = yi, vi = vi, mods = ~x, data = data, method = "REML")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Meta-regression relates study-level summaries, not individual-level effects.

Exponentiate a pooled log-effect and interval

Stata

meta summarize, eform

R Package:metafor

exp(c(estimate = as.numeric(fit$b), lower = fit$ci.lb, upper = fit$ci.ub))

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Only appropriate when effects are on a log-ratio scale.

Leave-one-study-out pooled estimates

Stata

meta summarize, leaveoneout

R Package:metafor

metafor::leave1out(metafor::rma(yi, vi, data = data, method = "REML"))

Differs from Stata Assumes meta set used its default random(reml) declaration; metafor explicitly selects REML. A prior Stata common/fixed/random declaration changes the target. Match study order, missingness and heterogeneity estimation before comparing summaries.

Inverse-variance meta-analysis using EB

Stata

meta summarize, random(ebayes)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "EB")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Between-study variance estimators and confidence procedures must be matched; some R estimator names differ from Stata’s names.

Inverse-variance meta-analysis using HE

Stata

meta summarize, random(hedges)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "HE")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Between-study variance estimators and confidence procedures must be matched; some R estimator names differ from Stata’s names.

Random-effects pooled inference using z

Stata

meta summarize, random(reml)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "REML", test = "z")

Fixed workflow; adapt the named data columns explicitly. Only knha corresponds to a Knapp-Hartung correction; z/t are explicit inference alternatives.

Prediction interval for a new study’s true effect

Stata

meta summarize, random(reml) predinterval

R Package:metafor

stats::predict(metafor::rma(yi, vi, data = data, method = "REML"))

Differs from Stata The true-effect prediction interval differs from the pooled-mean confidence interval. Stata uses t(K-2); metafor defaults to a normal quantile. For Stata endpoints compute mu +/- qt(.975,K-2)*sqrt(tau2+se^2); changing metafor test=“t” uses K-p degrees of freedom and is not the same correction.

Random-effects pooled inference using knha

Stata

meta summarize, random(reml) se(khartung)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "REML", test = "knha")

Fixed workflow; adapt the named data columns explicitly. Only knha corresponds to a Knapp-Hartung correction; z/t are explicit inference alternatives.

Random-effects pooled inference using t

Stata

meta summarize, random(reml) tdistribution

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "REML", test = "t")

Fixed workflow; adapt the named data columns explicitly. Only knha corresponds to a Knapp-Hartung correction; z/t are explicit inference alternatives.

Inverse-variance meta-analysis using SJ

Stata

meta summarize, random(sjonkman)

R Package:metafor

metafor::rma(yi = yi, vi = vi, data = data, method = "SJ")

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Between-study variance estimators and confidence procedures must be matched; some R estimator names differ from Stata’s names.

Separate random-effects estimates by study subgroup

Stata

meta summarize, subgroup(x)

R Package:metafor

lapply(split(data, data$x), function(d) metafor::rma(yi, vi, data = d, method = "REML"))

Differs from Stata Fixed workflow; adapt the named data columns explicitly. Fits separate heterogeneity parameters; not the same as a shared-tau subgroup model.

Trim-and-fill sensitivity analysis

Stata

meta trimfill

R Package:metafor

metafor::trimfill(metafor::rma(yi, vi, data = data, method = "REML"))

Differs from Stata Assumes meta set used its default random(reml) declaration; metafor explicitly selects REML. A prior Stata common/fixed/random declaration changes the target. Match study order, missingness and heterogeneity estimation before comparing summaries.