Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: How to calculate standardized difference in means with survey weighted data?


From   Steve Samuels <sjsamuels@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: How to calculate standardized difference in means with survey weighted data?
Date   Thu, 29 Mar 2012 00:32:45 -0400

Correction.

Lok Wong asked how to do this on March 4 and Shaun Scholes gave an incomplete solution on March 5. I supplied an answer, but unfortunately it was wrong.

I made an elementary mistake: I supposed that a pooled SD is the same as the SD of the pooled data. Here's a solution that creates and pools the separate SDs.


My apologies to all.

Steve
sjsamuels@gmail.com

*************CODE BEGINS*************
sysuse auto, clear

svyset _n [pw = turn]

// set up variable list
local vlist length weight

foreach v of varlist `vlist'{
qui svy: mean `v', over(foreign)
qui estat sd
local m1 = el(r(mean),1,1)
local m2 = el(r(mean),1,2)
local s1 = el(r(sd),1,1)
local s2 = el(r(sd),1,2)
local n1 = el(e(_N_subp),1,1)
local n2 = el(e(_N_subp),1,2)

local sdpool = /// Pooled SD
 sqrt((`n1'*(`s1')^2+`n2'*(`s2')^2) /(`n1'+`n2'))
local sdiff = (`m1'-`m2')/`sdpool'

di as result ///
 _column(3) `"Standardized Difference for `v': "' ///
 _column(38) " = " _column(42) `sdiff'
}
*******************************************
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index