Statalist The Stata Listserver


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

Re: st: question about svy commands


From   "Stas Kolenikov" <[email protected]>
To   [email protected]
Subject   Re: st: question about svy commands
Date   Tue, 7 Mar 2006 10:05:48 -0600

and -egen- does not allow for [pweights] -- that's the only thing you
would need to be concerned with when estimating the means based on the
survey data (for variances, you would need to take clustering,
stratification, finite population corrections and all this stuff into
account). You would need to do everything manually:

bysort state (personID) : g meanvar1 = sum(var1*pweight)
bysort state (personID) : g sumwt = sum(pweight)
bysort state (personID) : replace meanvar1 = meanvar1[_N]/sumwt[_N]
bysort state (personID) : replace sumwt = sumwt[_N]

You may need to figure out the -by- construct, it is very handy. If
you have dozens of variables to average out that way, you would need
to learn Stata's cycles (-foreach-). Nick's and Stephen's FAQ deals
with somewhat more complex case.

On 3/7/06, n j cox <[email protected]> wrote:
> -egen- always follows a syntax
>
> egen newvar = fcn() ...
>
> and I am not aware of a -egen- function -svymean()-.
>
> The FAQ
>
> "I want to calculate a variable containing weighted group summary
> statistics, but I do not want to collapse the data and egen does not
> support weights. How can I do this?"
>
> at http://www.stata.com/support/faqs/data/weighted.html
> should help.
>
> Nick
> [email protected]
>
>  >>> Anant Thaker
>
> [I am] a Stata SE/8 user. I have survey data that is organized at
> the individual level, roughly like this:
>
> Var1  Var2  State  Weight
> 1.
> 2.
> 3.
>
> I want to create a new variable, Var4, that has the mean of Var1 for
> whatever state the individual is in. For example, if the first
> observation is in New York, I want the new variable to have a Var4 that
> has the mean value of Var1 for NY. However, I need to incorporate the
> weights, so I was wondering if I should use the survey commands? Is
> there a way to do this? Is it something along the lines of
>
> egen var4 = svymean var1 [if var1==...
>
> *
> *   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