Why are there two ways to calculate the standard deviation of a binary variable? 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))
3.9318519

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. 
 A: *

*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.

A: 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.
