<>
"I take it that references to -wkndrev- in your examples are typos. "
As are the ones to "week"... Grrrr...
HTH
Martin
_______________________
----- Original Message -----
From: "Nick Cox" <[email protected]>
To: <[email protected]>
Sent: Tuesday, February 10, 2009 9:53 PM
Subject: st: RE: Creating a variable (cumulative revenue by title)
I take it that references to -wkndrev- in your examples are typos.
Here is one way to do it:
bysort title wk : egen crevall = total(wkrev)
by title wk : gen tag = _n == 1
by title : replace crevall = sum(tag * crevall)
Nick
[email protected]
Mike Kim
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)
*
* 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/
*
* 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/