Statistical distributions

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

betaden

Evaluate the beta density

Stata

display betaden(2,3,0.4)

R Package:stats

stats::dbeta(0.4, shape1=2, shape2=3)

binomial

Compute an inclusive binomial lower tail

Stata

display binomial(10,3,0.4)

R Package:stats

stats::pbinom(3, size=10, prob=0.4)

binomialp

Evaluate a binomial probability mass

Stata

display binomialp(10,3,0.4)

R Package:stats

stats::dbinom(3, size=10, prob=0.4)

binomialtail

Compute an inclusive binomial upper tail

Stata

display binomialtail(10,3,0.4)

R Package:stats

stats::pbinom(2, size=10, prob=0.4, lower.tail=FALSE)

Stata includes k in the upper tail; R lower.tail=FALSE excludes its q argument, so use k-1.

binormal

Evaluate a correlated bivariate normal probability

Stata

display binormal(0,0,0.4)

R Package:mvtnorm

as.numeric(mvtnorm::pmvnorm(upper=c(0,0),corr=matrix(c(1,0.4,0.4,1),2)))

Differs from Stata Evaluates a bivariate normal probability using mvtnorm numerical integration. Integration tolerance and numerical rounding differ from the Stata distribution function.

cauchy

Evaluate the Cauchy cumulative probability

Stata

display cauchy(1,2,3)

R Package:stats

stats::pcauchy(3, location=1, scale=2)

cauchyden

Evaluate the Cauchy density

Stata

display cauchyden(1,2,3)

R Package:stats

stats::dcauchy(3, location=1, scale=2)

cauchytail

Evaluate the Cauchy upper-tail probability

Stata

display cauchytail(1,2,3)

R Package:stats

stats::pcauchy(3, location=1, scale=2, lower.tail=FALSE)

chi2

Evaluate the chi-squared cumulative probability

Stata

display chi2(4,3)

R Package:stats

stats::pchisq(3, df=4)

chi2den

Evaluate the chi-squared density

Stata

display chi2den(4,3)

R Package:stats

stats::dchisq(3, df=4)

chi2tail

Evaluate the chi-squared upper-tail probability

Stata

display chi2tail(4,3)

R Package:stats

stats::pchisq(3, df=4, lower.tail=FALSE)

corr2data

Generate pseudo-data with exactly specified sample moments

Stata

corr2data x y, n(100)

R Package:MASS

stats::setNames(as.data.frame(MASS::mvrnorm(n=100,mu=c(0,0),Sigma=diag(2),empirical=TRUE)),c("x","y"))

Differs from Stata empirical=TRUE imposes the sample mean and covariance; such pseudo-data are not independent random draws.

drawnorm

Draw independent standard normal columns jointly

Stata

drawnorm x y, n(100)

R Package:MASS

stats::setNames(as.data.frame(MASS::mvrnorm(n=100,mu=c(0,0),Sigma=diag(2))),c("x","y"))

Differs from Stata Random streams differ; R returns a data frame of generated columns.

exponential

Evaluate the exponential cumulative probability

Stata

display exponential(2,3)

R Package:stats

stats::pexp(3, rate=1/2)

exponentialden

Evaluate the exponential density

Stata

display exponentialden(2,3)

R Package:stats

stats::dexp(3, rate=1/2)

exponentialtail

Evaluate the exponential upper-tail probability

Stata

display exponentialtail(2,3)

R Package:stats

stats::pexp(3, rate=1/2, lower.tail=FALSE)

F

Evaluate the F cumulative probability

Stata

display F(4,10,2)

R Package:stats

stats::pf(2, df1=4, df2=10)

Fden

Evaluate the F density

Stata

display Fden(4,10,2)

R Package:stats

stats::df(2, df1=4, df2=10)

Ftail

Evaluate the F upper-tail probability

Stata

display Ftail(4,10,2)

R Package:stats

stats::pf(2, df1=4, df2=10, lower.tail=FALSE)

gammaden

Evaluate the gamma density

Stata

display gammaden(3,1,0,2)

R Package:stats

stats::dgamma(2, shape=3)

Evaluate a shifted gamma density

Stata

display gammaden(3,2,1,5)

R Package:stats

stats::dgamma(5-1, shape=3, scale=2)

gammap

Evaluate the gamma cumulative probability

Stata

display gammap(3,2)

R Package:stats

stats::pgamma(2, shape=3)

gammaptail

Evaluate the gamma upper-tail probability

Stata

display gammaptail(3,2)

R Package:stats

stats::pgamma(2, shape=3, lower.tail=FALSE)

hypergeometric

Compute an inclusive hypergeometric lower tail

Stata

display hypergeometric(20,8,5,3)

R Package:stats

stats::phyper(3, m=8, n=12, k=5)

hypergeometricp

Evaluate a hypergeometric probability mass

Stata

display hypergeometricp(20,8,5,3)

R Package:stats

stats::dhyper(3, m=8, n=12, k=5)

ibeta

Evaluate the beta cumulative probability

Stata

display ibeta(2,3,0.4)

R Package:stats

stats::pbeta(0.4, shape1=2, shape2=3)

ibetatail

Evaluate the beta upper-tail probability

Stata

display ibetatail(2,3,0.4)

R Package:stats

stats::pbeta(0.4, shape1=2, shape2=3, lower.tail=FALSE)

invbinomial

Solve a binomial CDF for its success probability

Stata

display invbinomial(10,3,0.5)

R Package:stats

stats::qbeta(0.5, shape1=4, shape2=7, lower.tail=FALSE)

These Stata inverse functions solve for a distribution parameter, not a discrete outcome quantile.

invbinomialtail

Solve an inclusive binomial tail for success probability

Stata

display invbinomialtail(10,3,0.5)

R Package:stats

stats::qbeta(0.5, shape1=3, shape2=8)

These Stata inverse functions solve for a distribution parameter, not a discrete outcome quantile.

invcauchy

Find the Cauchy 90th percentile

Stata

display invcauchy(1,2,0.9)

R Package:stats

stats::qcauchy(0.9, location=1, scale=2)

invcauchytail

Find a Cauchy upper-tail critical value

Stata

display invcauchytail(1,2,0.9)

R Package:stats

stats::qcauchy(0.9, location=1, scale=2, lower.tail=FALSE)

invchi2

Find the chi-squared 90th percentile

Stata

display invchi2(4,0.9)

R Package:stats

stats::qchisq(0.9, df=4)

invchi2tail

Find a chi-squared upper-tail critical value

Stata

display invchi2tail(4,0.9)

R Package:stats

stats::qchisq(0.9, df=4, lower.tail=FALSE)

invexponential

Find the exponential 90th percentile

Stata

display invexponential(2,0.9)

R Package:stats

stats::qexp(0.9, rate=1/2)

invexponentialtail

Find a exponential upper-tail critical value

Stata

display invexponentialtail(2,0.9)

R Package:stats

stats::qexp(0.9, rate=1/2, lower.tail=FALSE)

invF

Find the F 90th percentile

Stata

display invF(4,10,0.9)

R Package:stats

stats::qf(0.9, df1=4, df2=10)

invFtail

Find a F upper-tail critical value

Stata

display invFtail(4,10,0.9)

R Package:stats

stats::qf(0.9, df1=4, df2=10, lower.tail=FALSE)

invgammap

Find the gamma 90th percentile

Stata

display invgammap(3,0.9)

R Package:stats

stats::qgamma(0.9, shape=3)

invgammaptail

Find a gamma upper-tail critical value

Stata

display invgammaptail(3,0.9)

R Package:stats

stats::qgamma(0.9, shape=3, lower.tail=FALSE)

invibeta

Find the beta 90th percentile

Stata

display invibeta(2,3,0.9)

R Package:stats

stats::qbeta(0.9, shape1=2, shape2=3)

invibetatail

Find a beta upper-tail critical value

Stata

display invibetatail(2,3,0.9)

R Package:stats

stats::qbeta(0.9, shape1=2, shape2=3, lower.tail=FALSE)

invlogistic

Convert probability to log odds

Stata

display invlogistic(0.8)

R Package:stats

stats::qlogis(0.8)

Find the logistic 90th percentile

Stata

display invlogistic(1,2,0.9)

R Package:stats

stats::qlogis(0.9, location=1, scale=2)

invlogistictail

Find a logistic upper-tail critical value

Stata

display invlogistictail(1,2,0.9)

R Package:stats

stats::qlogis(0.9, location=1, scale=2, lower.tail=FALSE)

invnbinomial

Solve a negative-binomial CDF for success probability

Stata

display invnbinomial(4,3,0.5)

R Package:stats

stats::qbeta(0.5, shape1=4, shape2=4)

These Stata inverse functions solve for a distribution parameter, not a discrete outcome quantile.

invnbinomialtail

Solve a negative-binomial tail for success probability

Stata

display invnbinomialtail(4,3,0.5)

R Package:stats

stats::qbeta(0.5, shape1=4, shape2=3, lower.tail=FALSE)

These Stata inverse functions solve for a distribution parameter, not a discrete outcome quantile.

invnchi2

Find a nchi2 noncentral critical value

Stata

display invnchi2(4,2,0.9)

R Package:stats

stats::qchisq(0.9, df=4, ncp=2)

invnchi2tail

Find a nchi2 noncentral upper-tail critical value

Stata

display invnchi2tail(4,2,0.9)

R Package:stats

stats::qchisq(0.9, df=4, ncp=2, lower.tail=FALSE)

invnF

Find a nF noncentral critical value

Stata

display invnF(4,20,2,0.9)

R Package:stats

stats::qf(0.9, df1=4, df2=20, ncp=2)

invnFtail

Find a nF noncentral upper-tail critical value

Stata

display invnFtail(4,20,2,0.9)

R Package:stats

stats::qf(0.9, df1=4, df2=20, ncp=2, lower.tail=FALSE)

invnibeta

Find a nibeta noncentral critical value

Stata

display invnibeta(2,3,2,0.9)

R Package:stats

stats::qbeta(0.9, shape1=2, shape2=3, ncp=2)

invnormal

Find the standard normal 90th percentile

Stata

display invnormal(0.9)

R Package:stats

stats::qnorm(0.9)

invnt

Find a nt noncentral critical value

Stata

display invnt(20,2,0.9)

R Package:stats

stats::qt(0.9, df=20, ncp=2)

invnttail

Find a nt noncentral upper-tail critical value

Stata

display invnttail(20,2,0.9)

R Package:stats

stats::qt(0.9, df=20, ncp=2, lower.tail=FALSE)

invpoisson

Solve a Poisson CDF for its mean

Stata

display invpoisson(3,0.5)

R Package:stats

stats::qgamma(0.5, shape=4, lower.tail=FALSE)

These Stata inverse functions solve for a distribution parameter, not a discrete outcome quantile.

invpoissontail

Solve an inclusive Poisson tail for its mean

Stata

display invpoissontail(3,0.5)

R Package:stats

stats::qgamma(0.5, shape=3)

These Stata inverse functions solve for a distribution parameter, not a discrete outcome quantile.

invt

Find the Student t 90th percentile

Stata

display invt(10,0.9)

R Package:stats

stats::qt(0.9, df=10)

invttail

Find a Student t upper-tail critical value

Stata

display invttail(10,0.9)

R Package:stats

stats::qt(0.9, df=10, lower.tail=FALSE)

invtukeyprob

Find a Tukey simultaneous-comparison critical value

Stata

display invtukeyprob(4,20,0.95)

R Package:stats

stats::qtukey(0.95, nmeans=4, df=20)

Differs from Stata Uses the studentized-range quantile from qtukey. R and Stata implement different numerical approximations; tested inputs differed by about 2.5e-8, so compare within numerical tolerance rather than exact equality.

invweibull

Find the Weibull 90th percentile

Stata

display invweibull(2,3,0.9)

R Package:stats

stats::qweibull(0.9, shape=2, scale=3)

invweibullph

Find a PH Weibull percentile

Stata

display invweibullph(2,0.5,0.9)

R Package:stats

stats::qweibull(0.9, shape=2, scale=0.5^(-1/2))

invweibullphtail

Find a PH Weibull upper-tail quantile

Stata

display invweibullphtail(2,0.5,0.1)

R Package:stats

stats::qweibull(0.1, shape=2, scale=0.5^(-1/2), lower.tail=FALSE)

invweibulltail

Find a Weibull upper-tail critical value

Stata

display invweibulltail(2,3,0.9)

R Package:stats

stats::qweibull(0.9, shape=2, scale=3, lower.tail=FALSE)

lncauchyden

Evaluate a Cauchy log density

Stata

display lncauchyden(1,2,3)

R Package:stats

stats::dcauchy(3, location=1, scale=2, log=TRUE)

lnigammaden

Evaluate an inverse-gamma log density

Stata

display lnigammaden(3,2,4)

R Package:stats

stats::dgamma(1/4,shape=3,rate=2,log=TRUE)-2*log(4)

Differs from Stata Uses the reciprocal-gamma change of variables with its log-Jacobian. Match Stata shape and scale parameterization; numerical tail underflow can differ.

lnmvnormalden

Evaluate a multivariate normal log density

Stata

matrix M = (0,0)
matrix V = I(2)
matrix X = (1,2)
display lnmvnormalden(M,V,X)

R Package:mvtnorm

mvtnorm::dmvnorm(x=c(1,2),mean=c(0,0),sigma=diag(2),log=TRUE)

Differs from Stata Fixed example uses mean M=(0,0), covariance V=I(2), and evaluation vector X=(1,2).

lnnormal

Compute a stable extreme normal log probability

Stata

display lnnormal(-8)

R Package:stats

stats::pnorm(-8, log.p=TRUE)

lnnormalden

Evaluate a normal log density with location and scale

Stata

display lnnormalden(3,1,2)

R Package:stats

stats::dnorm(3, mean=1, sd=2, log=TRUE)

logistic

Convert log odds to probability

Stata

display logistic(0.7)

R Package:stats

stats::plogis(0.7)
1 more examples and alternatives

Evaluate the logistic cumulative probability

Stata

display logistic(1,2,3)

R Package:stats

stats::plogis(3, location=1, scale=2)

logisticden

Evaluate the logistic density

Stata

display logisticden(1,2,3)

R Package:stats

stats::dlogis(3, location=1, scale=2)

logistictail

Evaluate the logistic upper-tail probability

Stata

display logistictail(1,2,3)

R Package:stats

stats::plogis(3, location=1, scale=2, lower.tail=FALSE)

nbetaden

Evaluate the nibeta noncentral density

Stata

display nbetaden(2,3,2,0.4)

R Package:stats

stats::dbeta(0.4, shape1=2, shape2=3, ncp=2)

nbinomial

Compute an inclusive nbinomial lower tail

Stata

display nbinomial(4,3,0.6)

R Package:stats

stats::pnbinom(3, size=4, prob=0.6)

nbinomialp

Evaluate a nbinomial probability mass

Stata

display nbinomialp(4,3,0.6)

R Package:stats

stats::dnbinom(3, size=4, prob=0.6)

nbinomialtail

Compute an inclusive nbinomial upper tail

Stata

display nbinomialtail(4,3,0.6)

R Package:stats

stats::pnbinom(2, size=4, prob=0.6, lower.tail=FALSE)

Stata includes k in the upper tail; R lower.tail=FALSE excludes its q argument, so use k-1.

nchi2

Evaluate the nchi2 noncentral CDF

Stata

display nchi2(4,2,3)

R Package:stats

stats::pchisq(3, df=4, ncp=2)

nchi2den

Evaluate the nchi2 noncentral density

Stata

display nchi2den(4,2,3)

R Package:stats

stats::dchisq(3, df=4, ncp=2)

nchi2tail

Evaluate the nchi2 noncentral upper tail

Stata

display nchi2tail(4,2,3)

R Package:stats

stats::pchisq(3, df=4, ncp=2, lower.tail=FALSE)

nF

Evaluate the nF noncentral CDF

Stata

display nF(4,20,2,1.5)

R Package:stats

stats::pf(1.5, df1=4, df2=20, ncp=2)

nFden

Evaluate the nF noncentral density

Stata

display nFden(4,20,2,1.5)

R Package:stats

stats::df(1.5, df1=4, df2=20, ncp=2)

nFtail

Evaluate the nF noncentral upper tail

Stata

display nFtail(4,20,2,1.5)

R Package:stats

stats::pf(1.5, df1=4, df2=20, ncp=2, lower.tail=FALSE)

nibeta

Evaluate the nibeta noncentral CDF

Stata

display nibeta(2,3,2,0.4)

R Package:stats

stats::pbeta(0.4, shape1=2, shape2=3, ncp=2)

normal

Evaluate the standard normal cumulative probability

Stata

display normal(0.7)

R Package:stats

stats::pnorm(0.7)

normalden

Evaluate the standard normal density

Stata

display normalden(0.7)

R Package:stats

stats::dnorm(0.7)

Evaluate a normal density with location and scale

Stata

display normalden(3,1,2)

R Package:stats

stats::dnorm(3, mean=1, sd=2)

npnchi2

Solve a noncentral chi-squared probability for noncentrality

Stata

display npnchi2(4,8,0.5)

R Package:stats

stats::uniroot(function(ncp) stats::pchisq(8,df=4,ncp=ncp)-0.5,c(0,50),tol=1e-10)$root

Differs from Stata Numerically inverts the noncentral chi-square CDF over the displayed noncentrality bracket. Other inputs may need a wider bracket; Stata performs its own domain validation and inversion.

npnF

Solve a noncentral F probability for noncentrality

Stata

display npnF(4,20,2,0.5)

R Package:stats

stats::uniroot(function(ncp) stats::pf(2,df1=4,df2=20,ncp=ncp)-0.5,c(0,50),tol=1e-10)$root

Differs from Stata Numerically inverts the noncentral F CDF over the displayed bracket. Other inputs can require a different bracket; solver tolerances differ from Stata.

npnt

Solve a noncentral t probability for noncentrality

Stata

display npnt(20,2,0.5)

R Package:stats

stats::uniroot(function(ncp) stats::pt(2,df=20,ncp=ncp)-0.5,c(0,4),tol=1e-10)$root

Differs from Stata Numerically inverts the noncentral t CDF over the displayed bracket. Negative or larger noncentralities require different bounds; solver tolerances differ from Stata.

nt

Evaluate the nt noncentral CDF

Stata

display nt(20,2,1.5)

R Package:stats

stats::pt(1.5, df=20, ncp=2)

nttail

Evaluate the nt noncentral upper tail

Stata

display nttail(20,2,1.5)

R Package:stats

stats::pt(1.5, df=20, ncp=2, lower.tail=FALSE)

poisson

Compute an inclusive poisson lower tail

Stata

display poisson(2,3)

R Package:stats

stats::ppois(3, lambda=2)

poissonp

Evaluate a poisson probability mass

Stata

display poissonp(2,3)

R Package:stats

stats::dpois(3, lambda=2)

poissontail

Compute an inclusive poisson upper tail

Stata

display poissontail(2,3)

R Package:stats

stats::ppois(2, lambda=2, lower.tail=FALSE)

Stata includes k in the upper tail; R lower.tail=FALSE excludes its q argument, so use k-1.

rbeta

Simulate rbeta variates

Stata

generate draw = rbeta(2,3)

R Package:stats

stats::rbeta(1000,2,3)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rbinomial

Simulate rbinomial variates

Stata

generate draw = rbinomial(10,0.4)

R Package:stats

stats::rbinom(1000,10,0.4)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rcauchy

Simulate rcauchy variates

Stata

generate draw = rcauchy(1,2)

R Package:stats

stats::rcauchy(1000,1,2)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rchi2

Simulate rchi2 variates

Stata

generate draw = rchi2(4)

R Package:stats

stats::rchisq(1000,4)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rexponential

Simulate rexponential variates

Stata

generate draw = rexponential(2)

R Package:stats

stats::rexp(1000,rate=1/2)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rgamma

Simulate rgamma variates

Stata

generate draw = rgamma(3,2)

R Package:stats

stats::rgamma(1000,shape=3,scale=2)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rhypergeometric

Simulate rhypergeometric variates

Stata

generate draw = rhypergeometric(20,8,5)

R Package:stats

stats::rhyper(1000,m=8,n=12,k=5)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rlogistic

Simulate rlogistic variates

Stata

generate draw = rlogistic(1,2)

R Package:stats

stats::rlogis(1000,location=1,scale=2)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rnbinomial

Simulate rnbinomial variates

Stata

generate draw = rnbinomial(4,0.6)

R Package:stats

stats::rnbinom(1000,size=4,prob=0.6)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rpoisson

Simulate rpoisson variates

Stata

generate draw = rpoisson(2)

R Package:stats

stats::rpois(1000,lambda=2)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rt

Simulate rt variates

Stata

generate draw = rt(20)

R Package:stats

stats::rt(1000,df=20)

Differs from Stata The same seed does not produce matching draws across Stata and R.

rweibull

Simulate rweibull variates

Stata

generate draw = rweibull(2,3)

R Package:stats

stats::rweibull(1000,shape=2,scale=3)

Differs from Stata The same seed does not produce matching draws across Stata and R.

t

Evaluate the Student t cumulative probability

Stata

display t(10,1.2)

R Package:stats

stats::pt(1.2, df=10)

tden

Evaluate the Student t density

Stata

display tden(10,1.2)

R Package:stats

stats::dt(1.2, df=10)

ttail

Evaluate the Student t upper-tail probability

Stata

display ttail(10,1.2)

R Package:stats

stats::pt(1.2, df=10, lower.tail=FALSE)

tukeyprob

Evaluate a studentized-range cumulative probability

Stata

display tukeyprob(4,20,3)

R Package:stats

stats::ptukey(3, nmeans=4, df=20)

weibull

Evaluate a shifted Weibull cumulative probability

Stata

display weibull(2,3,1,5)

R Package:stats

stats::pweibull(5-1, shape=2, scale=3)

Evaluate the Weibull cumulative probability

Stata

display weibull(2,3,4)

R Package:stats

stats::pweibull(4, shape=2, scale=3)

weibullden

Evaluate the Weibull density

Stata

display weibullden(2,3,4)

R Package:stats

stats::dweibull(4, shape=2, scale=3)

weibullph

Use the proportional-hazards Weibull parameterization

Stata

display weibullph(2,0.5,3)

R Package:stats

stats::pweibull(3, shape=2, scale=0.5^(-1/2))

weibullphden

Evaluate a PH Weibull density

Stata

display weibullphden(2,0.5,3)

R Package:stats

stats::dweibull(3, shape=2, scale=0.5^(-1/2))

weibullphtail

Evaluate a PH Weibull survivor probability

Stata

display weibullphtail(2,0.5,3)

R Package:stats

stats::pweibull(3, shape=2, scale=0.5^(-1/2), lower.tail=FALSE)

weibulltail

Evaluate the Weibull upper-tail probability

Stata

display weibulltail(2,3,4)

R Package:stats

stats::pweibull(4, shape=2, scale=3, lower.tail=FALSE)