Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Create cumulative sum by two different catagories


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Create cumulative sum by two different catagories
Date   Thu, 7 Dec 2006 22:00:59 -0000

This is a bit too much like a puzzle in which you 
have to guess the puzzle as well as the solution. 

The rules seem to be 

1. Ignore my typos. (The data for dif = 2, sector = 2
seem out of line.) 

2. Treat duplicates on -dif- and -sector- as if
they occurred just once. 

3. Then calculate cumulative sums over -sector-. 

On those guesses, I guess in turn 

bysort sector dif : gen CAAR = _n == 1 
by sector : replace CAAR = sum(CAAR * AAR) 
separate CAAR, by(sector) gen(CAAR_) 

In general, -by:- is indispensable. 

Nick 
[email protected] 

mai mai

> I am trying to get a cumulative sum of AAR below by sector group and
> diff group. So need to create four variables: the first (CAAR_1)
> containing the cumulative sum by dif if the firms were in sector 1,
> the second (CAAR_2) contains the cumulative sum by dif if the firms
> were in sector 2, and so on: I need it to do something like this:
> 
> dif   sector    AAR       CAAR_1   CAAR_2 ....CAAR_4
> 1         1        2.2         2.2            .
> 1         1        2.2         2.2            .
> 1         2        3.2         .              3.2
> 1         2        3.2         .              3.2
> 1         2        3.2         .              3.2
> 1         3        1.0         .               .
> 1         3        1.0         .               .
> 2         1        6.6         8.8            .
> 2         1        6.6         8.8            .
> 2         2        3.0         .               5.2
> 2         2        6.6         .               5.2
> 2         2        6.6         .               5.2
> 2         3        6.6         .                .
> 2         3        6.6         .                .
> 3         1        1.4        10.2            .
> 3         1        1.4        10.2            .
> 3         2        1.1        .                 6.3
> 3         2        1.1        .                 6.3
> 3         2        1.1        .                 6.3
> 3         3        1.4        .                   .
> 3         3        1.4        .                   .
> 
> 
> I cannot do by line because because the groups vary in number of
> sub_occupants. I need to do it by group, can you help me?

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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