Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: centralizing survey data


From   "Stas Kolenikov" <[email protected]>
To   [email protected]
Subject   Re: st: centralizing survey data
Date   Mon, 5 Mar 2007 15:41:35 -0600

your program should have a required -replace- option, so that the user
realizes that the existing data values are overwritten :))

On 3/5/07, Austin Nichols <[email protected]> wrote:
Stephan and Stas--
The svy commands run a bit slow, so if you have a large number of
variables to operate on, I recommend using -summ- with aweights, which
gives the same mean in a shorter time... then replace x=x-r(mean).
Note that the command -center- with aweights would also work (-ssc
install center-).

prog drop _all
prog cntrlize
 syntax [varlist] [fw aw pw iw]
 if "`weight'"=="pweight" local weight="aw"
 foreach v of local varlist {
  su `v' [`weight'`exp'], meanonly
  replace `v'=`v'-r(mean)
 }
end
webuse nhanes2, clear
su height weight [aw=finalwgt]
qui cntrlize height weight [pw=finalwgt]
su height weight [aw=finalwgt]

prog stdize
 syntax [varlist] [fw aw pw iw]
 if "`weight'"=="pweight" local weight="aw"
 foreach v of local varlist {
  su `v' [`weight'`exp']
  replace `v'=(`v'-r(mean))/r(sd)
 }
end
su bp* [aw=finalwgt]
qui stdize bp* [pw=finalwgt]
su bp* [aw=finalwgt]

On 3/5/07, Stas Kolenikov <[email protected]> wrote:
> svyset whatever
> svy: mean x
> gen dx = x-_b[x]
> or whatever -mean- leaves behind in Stata memory -- type -ereturn list- to see.
>
> On 3/5/07, Stephan F. Groschwitz <[email protected]> wrote:
> > I'm also fairly new to stata and apologize in advance if this
> > question has been answered before and I can't find it.
> > I have a data set with survey data, and I'd like to centralize a
> > couple variables.
> > Unfortunately the svy: command does not work with egen varmean=mean
> > (var). Is there any other way to pass the weighted means into a
> > constant for centralizing purposes?
*
*   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/


--
Stas Kolenikov
http://stas.kolenikov.name
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index