Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: algorithmic question : running sum and computations


From   Francesco <[email protected]>
To   [email protected]
Subject   st: algorithmic question : running sum and computations
Date   Fri, 17 Aug 2012 12:30:45 +0200

Dear Statalist,

I am stuck with a little algorithmic problem and I cannot find an
simple (or elegant) solution...

I have a panel dataset as (date in days) :

ID    DATE    PRODUCT QUANTITY
1       1           A           10
1       2           A           -10

1       1           B            100
1       2           B            -50

1       4           C            15
1       8           C            100
1       9           C            -115

1      10          C            10
1      11          C            -10



and I would like to know the average time (in days) it takes for an
individual in order to complete a full round trip (the variation in
quantity is zero)
For example, for the first id we can see that there we have

ID PRODUCT delta_DATE delta_QUANTITY
1         A               1=2-1                  0=10-10
1         C               5=4-9                  0=15+100-115
1         C               1=11-10               0=10-10

so on average individual 1 takes (1+5+1)/3=2.3 days to complete a full
round trip. Indeed I can discard product B because there is no round
trip, that is 100-50 is not equal to zero.

My question is therefore ... do you have an idea obtain this simply in
Stata ? I have to average across thousands of individuals... :)

Many, many thanks for your help and/or suggestions
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index