I've always been told that the standard deviation of a binary variable is sqrt(npq). However, there also appears to be a different way to calculate it:

. sysuse auto, clear
(1978 Automobile Data)

. sum foreign

    Variable |        Obs        Mean    Std. Dev.       Min        Max
     foreign |         74    .2972973    .4601885          0          1

. di sqrt(74*.2972973*(1-.2972973))

The terminology is confusing. How can the standard deviation be both 3.9 and .46?

Same thing for the mean. The mean formula I've seen in textbooks is np, but isn't p the mean? Like for this variable, the mean is .2972973, which is also p. np is more like the "number of successes" rather than the mean.

  • 3
    $\begingroup$ 1) where did you tell the software that the variable is binary in contrast to e.g. numeric? 2) I think you are mixing binary variables and the the sum of binary variables (= binomial). $\endgroup$
    – Michael M
    Commented May 24, 2020 at 18:17
  • $\begingroup$ I don't know? I'm not really sure what's happening. I know that reporting .4601885 is a fairly common way to report standard deviations for binaries in reports. Can you clarify (2)? How can the SD be greater than 1? It's not possible for the value to be greater than 1. Ultimately, I'm trying to determine what sd to use when I convert a regression coefficient to standardized values. Should I be using 3 or .46 for s_x? $\endgroup$
    – Hutchins
    Commented May 25, 2020 at 2:53
  • $\begingroup$ It's starting to sound like I'm calculating the SD for the bernoulli random variable, not binomial. Is that correct? $\endgroup$
    – Hutchins
    Commented May 25, 2020 at 5:19

2 Answers 2

  • For a Bernoulli variable $Ber(p)$, $p$ is the mean and sd $\sqrt{p(1-p)}$
  • If you have i.i.d. Bernoulli variable $X_1, \cdots, X_n \sim Ber(p)$, you can sum them up: the random variable $X_1 + \cdots + X_n$ has mean $np$ and sd $\sqrt{np(1-p)}$ (which I suppose is what you heard) - this is the binomial distribution $B(n, p)$.
  • But your data your showed very likely refers to the empirical statistics of your $n$ samples $X_1, \cdots, X_n$ of Bernoulli variable instead instead. So the "mean" in your formula refers to the sample mean $\frac{X_1 + \cdots + X_n}{n}$, which is an estimator of $p$; and the standard deviation refers to the sample s.d., which is an estimator of s.d. of Bernoulli variable, which is $\sqrt{p(1-p)}$. This is also why others said you may be confusing binary variable and binomial distribution in the comments.

Now let's do the comparison you intended to do:

  • the sample mean .2972973 estimates $p$ like you said.
  • the sample s.d. .4601885 estimates $\sqrt{p(1-p)}$. If we pretend $p = .2972973$, then $\sqrt{.2972973 (1 - .2972973)} \approx 0.457$ that is pretty close.
  • $\begingroup$ I'm not sure what you are saying tbh. (1) why do you have two different SD formulas? (2) how do I tell if my random variable is Bernoulli? (3) How should I report this binary variable? $\endgroup$
    – Hutchins
    Commented May 25, 2020 at 2:55
  • $\begingroup$ actually isn't that second SD the SE? And for the first, why isn't it sqrt(npq)? Why'd you remove the n? $\endgroup$
    – Hutchins
    Commented May 25, 2020 at 4:33
  • $\begingroup$ "Wrong" is maybe not the right word in item three. $\endgroup$
    – Michael M
    Commented May 25, 2020 at 5:06
  • 1
    $\begingroup$ I updated the answer since I noticed I had something wrong yesterday. $\endgroup$
    – Pig
    Commented May 25, 2020 at 19:57
  • $\begingroup$ For posterity, Stata computes the sample variance and not the mean variance, so the formula used there is sqrt(.2972973*(1-.2972973)*74/73) = .4570685 which is exactly what's shown in the question $\endgroup$ Commented Feb 19, 2022 at 4:42

You could use Wolfram website to study the 'binomial distribution' and the Bernoulli random variable.

The previous answer says that if you are adding up numerous random variables, each of which is Bernoulli distributed, then the resulting mean follows a Binomial Distribution. This binomial distribution has 2, not 1 parameters. One parameter is p but the other one is n. Therefore, the n appears in the formula for its mean. See also: https://mathworld.wolfram.com/BernoulliDistribution.html compared that image and algebra with Binomial at: https://mathworld.wolfram.com/BinomialDistribution.html

Probably one should ideally know that the distribution of a mean (or sum) is not the same as the distribution of the individual components. This truth underlies the problem you had in grasping the comment.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.