| ![](/includes/contimages/spacer.gif) |
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: RE: generating std. devs. using svyset
n Apr 26, 2007, at 10:43 AM, Maarten Buis wrote:
--- Leslie R Hinkson ([email protected]) wrote:
I've been having a problem with generating staandard deviations
for my
variables.
A nice overview of what is possible with survey statistics in Stata
is:
F. kreuter and R. Valliant (2007)
"A survey on survey statistics: What is done and can be done in
Stata".
The Stata Journal, 7(1), pp. 1-22.
If you don't have the Stata Journal (I should, but don't), try this
crude program. It is based on the fact that the population variance
is the average of the (obs - mean)^2
/********************************************************/
use http://www.stata-press.com/data/r9/nmihs, clear
local varlist "birthwgt age"
quietly foreach x of local varlist {
svy:mean `x'
// Get Mean
matrix m_`x'=e(b)
gen mean_`x'=m_`x'[1,1]
matrix list e(V)
// Generate (x - mean)^2
gen `x'_dsq=(`x'-mean_`x')^2
//Get Estimated Mean of (x - mean)^2
svy: mean `x'_dsq
matrix var_`x'=e(b)
//Compute SD
gen sd_`x'=sqrt(var_`x'[1,1])
}
foreach x of local varlist {
di _column (1) "`x'" _column(15) "Mean = " mean_`x' _column(40)
"SD = " sd_`x'
}
/********************************************************************/
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/