How do I calculate a weighted standard deviation? In Excel? So, I have a data set of percentages like so:
100   /   10000   = 1% (0.01)
2     /     5     = 40% (0.4)
4     /     3     = 133% (1.3) 
1000  /   2000    = 50% (0.5)

I want to find the standard deviation of the percentages, but weighted for their data volume. ie, the first and last data points should dominate the calculation.
How do I do that? And is there a simple way to do it in Excel?
 A: =SQRT(SUM(G7:G16*(H7:H16-(SUMPRODUCT(G7:G16,H7:H16)/SUM(G7:G16)))^2)/
     ((COUNTIFS(G7:G16,"<>0")-1)/COUNTIFS(G7:G16,"<>0")*SUM(G7:G16)))

Column G are weights, Column H are values
A: The formula for weighted standard deviation is:
$$ \sqrt{ \frac{ \sum_{i=1}^N w_i (x_i - \bar{x}^*)^2 }{ \frac{(M-1)}{M} \sum_{i=1}^N w_i } },$$
where
$N$ is the number of observations.
$M$ is the number of nonzero weights.
$w_i$ are the weights
$x_i$ are the observations.
$\bar{x}^*$ is the weighted mean.
Remember that the formula for weighted mean is:
$$\bar{x}^* = \frac{\sum_{i=1}^N w_i x_i}{\sum_{i=1}^N w_i}.$$
Use the appropriate weights to get the desired result. In your case I would suggest to use $\frac{\mbox{Number of cases in segment}}{\mbox{Total number of cases}}$.
To do this in Excel, you need to calculate the weighted mean first. Then calculate the $(x_i - \bar{x}^*)^2$ in a separate column. The rest must be very easy.
A: The formulae are available various places, including Wikipedia.
The key is to notice that it depends on what the weights mean.  In particular, you will get different answers if the weights are frequencies (i.e. you are just trying to avoid adding up your whole sum), if the weights are in fact the variance of each measurement, or if they're just some external values you impose on your data.
In your case, it superficially looks like the weights are frequencies but they're not.  You generate your data from frequencies, but it's not a simple matter of having 45 records of 3 and 15 records of 4 in your data set.  Instead, you need to use the last method.  (Actually, all of this is rubbish--you really need to use a more sophisticated model of the process that is generating these numbers!  You apparently do not have something that spits out Normally-distributed numbers, so characterizing the system with the standard deviation is not the right thing to do.)
In any case, the formula for variance (from which you calculate standard deviation in the normal way) with "reliability" weights is
$${ \sum {w_i (x_i - x^*)^2} \over {\sum w_i - {\sum w_i^2 \over \sum w_i }} }$$
where $x^* = \sum w_i x_i / \sum w_i$ is the weighted mean.
You don't have an estimate for the weights, which I'm assuming you want to take to be proportional to reliability.  Taking percentages the way you are is going to make analysis tricky even if they're generated by a Bernoulli process, because if you get a score of 20 and 0, you have infinite percentage.  Weighting by the inverse of the SEM is a common and sometimes optimal thing to do.  You should perhaps use a Bayesian estimate or Wilson score interval.
A: If we treat weights like probabilities, then we build them as follows:
$$p_i=\frac{v_i}{\sum_iv_i},$$
where $v_i$ - data volume.
Next, obviously the weighted mean is $$\hat\mu=\sum_ip_ix_i,$$
and the variance:$$\hat\sigma^2=\sum_ip_i(x_i-\hat\mu)^2$$
A: Late in the day I know, but in reference to Whuber's insistance on an authoritative justification for the (M-1)/M term for an unbiased estimate, perhaps Prof. James Kirchner's justification, download currently available at http://seismo.berkeley.edu/~kirchner/Toolkits/Toolkit_12.pdf, which references 
Bevington, P. R., Data Reduction and Error Analysis for the Physical Sciences, 336 pp.,
McGraw-Hill, 1969

will do?
Prof. Kirchner distinguishes between 


*

*"Case I" in which some points are more important than others (hence the weighting) but the uncertainties associated with each point are assumed to be the same 

*"Case II" in which the points are equally important but the uncertainties associated with each point are not the same.


For FabioSpaghetti's comment from yesterday, the above linked paper also shows how to calculate the standard error.
A: Option Explicit

Function wsdv(vals As Range, wates As Range)
Dim i, xV, xW, y As Integer
Dim wi, xi, WgtAvg, N
Dim sumProd, SUMwi

    sumProd = 0
    SUMwi = 0
    N = vals.Count  ' number of values to determine W Standard Deviation
    xV = vals.Column  ' Column number of first value element
    xW = wates.Column  ' Column number of first weight element
    y = vals.Row - 1  ' Row number of the values and weights

    WgtAvg = WorksheetFunction.SumProduct(vals, wates) / WorksheetFunction.Sum(wates)

    For i = 1 To N  ' step through the elements, calculating the sum of values and the sumproduct
        wi = ActiveSheet.Cells(i + y, xW).Value  ' (i+y, xW) is the cell containing the weight element
        SUMwi = SUMwi + wi
        xi = ActiveSheet.Cells(i + y, xV).Value  ' (i+y, xV) is the cell containing the value element
        sumProd = sumProd + wi * (xi - WgtAvg) ^ 2
    Next i

    wsdv = (sumProd / SUMwi * N / (N - 1)) ^ (1 / 2)  ' output of weighted standard deviation

End Function

