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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: collapse and weights


From   Austin Nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: collapse and weights
Date   Mon, 26 Nov 2012 18:36:28 +0100

Tomáš Houška <xbender@gmail.com>:
Your goal is a bit hard to understand from the description--are you
saying you want the sum of q and the q-weighted mean of price?
Like:
g one=1
collapse (sum) sum=one (mean) price [fweight=q], by(prod_group)

On Sun, Nov 25, 2012 at 9:44 AM, Tomáš Houška <xbender@gmail.com> wrote:
> Dear Statalist,
>
> I have data containing weekly information on prices and quantities of
> sales of several products. These products can be divided into few
> groups and I would like to create for each group 1) an weighted
> average weekly price for the group where weight is the amounts of sale
> of each product in the group and 2) sum of sales of the products that
> belong to particular group. I will end up with average price and total
> sales for the given product group.
>
> But if I use
> -- collapse (sum) q (mean) price [fweight=q], by(prod_group) --
> the weights get applied both to the average and the sum, which is not
> correct. I havent been able to come up with a solution how to bracket
> the stata command. Could someone please give me some guidance?
> Thank you!
> Tomas (PhD student)

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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