Ritu,
You were apparently misled by the appearance of proportions in my formula for the population SD of the \(Y's\).
I should have explained that the formula I gave for the group \(j\) population SD for the \(Y_i^j\) ,
\[
S_j = \sqrt{P_j\times(1 - P_j)} =\sqrt{P_j- P_j^2}
\]
is identical to the ordinary definition of the SD of the \(Y_i^j\) variables.
\[
S_{Y}^j = \sqrt{\sum (Y_i^j - \overline{Y}^j)^2
/N_j}\]
I used svy: prop in order to get the \(P_j\)s needed for the formula in an accessible vector, but I could have used svy: tab, which, without the count option, puts the same numbers into the matrix e(b). Also, the Mata formula I gave for \(S_j\) was unduly complex.
with output
The ":" in Mata is very handy, because it allows you to do ordinary arithmetic operations on all single elements of vectors and matrices.
You were apparently misled by the appearance of proportions in my formula for the population SD of the \(Y's\).
I should have explained that the formula I gave for the group \(j\) population SD for the \(Y_i^j\) ,
\[
S_j = \sqrt{P_j\times(1 - P_j)} =\sqrt{P_j- P_j^2}
\]
is identical to the ordinary definition of the SD of the \(Y_i^j\) variables.
\[
S_{Y}^j = \sqrt{\sum (Y_i^j - \overline{Y}^j)^2
/N_j}\]
I used svy: prop in order to get the \(P_j\)s needed for the formula in an accessible vector, but I could have used svy: tab, which, without the count option, puts the same numbers into the matrix e(b). Also, the Mata formula I gave for \(S_j\) was unduly complex.
Code:
use nhanes2, clear svy , subpop(if region==2): tab agegrp mata: m = st_matrix("e(b)")' sd= sqrt(m:-(m:*m)) sd end
Code:
: sd 1 +---------------+ 1 | .4551115421 | 2 | .404763378 | 3 | .3871052 | 4 | .3509172041 | 5 | .3333122444 | 6 | .2093370152 | +---------------+
The ":" in Mata is very handy, because it allows you to do ordinary arithmetic operations on all single elements of vectors and matrices.
Comment