Statalist


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

st: Creating a variable (cumulative revenue by title)


From   "Mike Kim" <argonomos@gmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Creating a variable (cumulative revenue by title)
Date   Tue, 10 Feb 2009 12:22:46 -0600

Dear all,

I have a question about creating a variable. The structure of my data is a little complicated. Here is an example.

wk title country wkrev crevc wkrevall crevall
1     X     A         10     10    10     10
2     X     A         20     30     20     30
4     X     A         30     60     30     60
5     X     B         40     40     40     100
1     Y     C         10     10     30     30
1     Y     D         20     20     30     30
2     Y     C         30     40     70     100
2     Y     D         40     60     70     100
4     Y     E         50     50     50     150

wk=week
wkrev=weekly revenue
crevc=cumulative revenue from each country up to the week (by title)
wkrevall=weekly revenue from all countries for each week (by title)
crevall=cumulative revenue from all country up to the week (by title)

My question is: how can I create the last variable "crevall"?

I created 'crevc' and 'wkrevall' by the following:

sort title country week
by title country: gen crevc=sum(wkndrev)

sort title week country
by title week: egen wkrevall=total(wkndrev)

Thank you in advance.
Mike.

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index