Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Why can't I egen means with pweights?


From   Laura Schechter <[email protected]>
To   [email protected]
Subject   Re: st: Why can't I egen means with pweights?
Date   Wed, 23 Apr 2003 10:27:04 -0700 (PDT)

This is a response to Nick Cox's advice. The code you suggested actually
doesn't work because su doesn't allow for pweights either!
  Maybe I will try the next suggestion.
     Thanks anyway.
        Laura

On Wed, 23 Apr 2003, n j cox wrote:

> Laura Schechter wrote:
> 
> >    I have been trying to program a specific bootstrap in stata, and need
> > to use the weighted means of certain variables over time. Unfortunately,
> > it seems to me that the egen command doesn't work with weights. For now, I
> > have just been using the series of commands
> >    svymean varname [pweight=x], by(month)
> >    matrix e=e(est)
> >    generate ET=el(e,1,1) if month==1
> >    replace ET=el(e,1,2) if month==2
> >       etc. etc. etc.
> > But this is really slow, and it would be so convenient if the egen command
> > would work with weights so I could just say something like
> >     egen ET=mean(varname) [pweight=x], by(month)
> > Does anyone know a way of doing this??
> 
> The answer to your title question is: because weights
> were never part of the syntax of -egen-. I don't know why.
> 
> An answer to your end question is to program it
> directly. A similar problem is documented at
> "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?"
> http://www.stata.com/support/faqs/data/weighted.html
> 
> In your case -levels- is presumably unnecessary if -month-
> takes on values 1(1)12.
> 
> Hence
> 
> gen ET = .
> qui forval i = 1/12 {
> 	su varname [pweight=x] if month == `i', meanonly
> 	replace ET = r(mean) if month == `i'
> } 	
> 
> Nick
> [email protected]
> 
> *
> *   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/
> 

*
*   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