Statalist


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

st: RE: Re: RE: Creating a variable (cumulative revenue by title)


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Re: RE: Creating a variable (cumulative revenue by title)
Date   Tue, 10 Feb 2009 21:00:13 -0000

Correct. But Mike's example was in general clear. 

Nick 
n.j.cox@durham.ac.uk 

Martin Weiss


"I take it that references to -wkndrev- in your examples are typos. "

As are the ones to "week"... Grrrr...

From: "Nick Cox" <n.j.cox@durham.ac.uk>

>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 
> n.j.cox@durham.ac.uk 
> 
> 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/



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