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: generate a column of a summary statistic conditioning on the comparison of the values in two other columns


From   Ronnie Babigumira <rb.glists@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: generate a column of a summary statistic conditioning on the comparison of the values in two other columns
Date   Wed, 5 Dec 2012 17:53:38 +0100

David,
I think you will be more likely to get help if you can show some data http://www.stata.com/support/faqs/resources/statalist-faq/#stata

Ronnie 

-- 
010100100110111101101110011011100110100101100101




On Wednesday 5. December 2012 at 17.29, David Peng wrote:

> I have a dataset with four variables, A, B, C, and D. A is a variable
> representing the customer number. B is the main variable of interest
> (in this case the dollar amount of a customer order). C is the date a
> customer order was placed and D is the date the same customer order
> was delivered.
> 
> I would like to generate a column of summary statistic (let's say I
> want the mean) in the table. Basically, for each customer order, I
> would like to generate a mean value of the dollar amount for all of
> the orders placed by a customer prior to the date the order is placed.
> 
> For each observation (i.e., a cusomer order) in the data table, I
> would like to get:
> 
> bysort A: egen mean_dollar_amount=mean(B) if B is associated with a
> delivery date D that is earlier than the order date C of the customer
> order in question.
> 
> 
> As an example, if I have an obervation representing an order placed by
> the customer x with the order date of 12/30/2011, I would like to
> generate the mean of the dollar amount for all of the orders that were
> delivered earlier than the order date of 12/30/2011 for the order
> mentioned above. I need a mean value like this for each observation
> (i.e., customer order) in the data.
> 
> Thanks in advance for your help.
> *
> * 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/



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