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

# Re: st: panel - rowtotal

 From Mitch Abdon <[email protected]> To [email protected] Subject Re: st: panel - rowtotal Date Sun, 14 Nov 2010 07:56:55 +0800

```Hi,

This is easier if you have unique code for each unit. Use -total-
instead of -rowtotal-. -rowtotal- adds the values of varlist in a row,
not the values in a variable (column). After generating a unique
variable for each unit , try the following:

egen totalsales=total(sales), by(date units)

Or, since your going to drop the duplicate units after the generating
the common sum, you may use -collapse-:

collapse (sum) totalsales=sales, by(date units)
Warning: -collapse- literally collapses your data. Make sure you have
save your raw data before doing this.

On Sun, Nov 14, 2010 at 4:29 AM, Benodet Karia <[email protected]> wrote:
> Dear All,
>
> I have a panel dataset which shows the sales of the marketing units at particular dates. I have the dates in the first column, codes of the marketing units in the second column and sales of each unit in the third column. Some marketing units have affiliates. The data shows the sales of the marketing units and their affiliates seperately. I just need to sum the sales of the main unit and its affiliates at each date.
>
> For example, say the code of main unit is A, and the codes of the affilliates are B and C. All I need to do is to sum the sales of A, B and C at date1. Then I'll do the same for date2, date3.. etc. Finally, I'll drop B and C. So the sales of unit A will be replaced by A+B+C.
>
> Basicly I tried the commands "foreach date {" "egen units=rowtotal(sales) if code=="A" | code=="B" | code=="C"" but couldnt be successful. Anyone can guide this poor starter student?
>
>
> PS: In some dates, I dont have data for B and C. Rather than zero sales, I simply dont see the data about B and C on some dates. I mean should it be a balanced panel to run the code?
>
> Thanks, bk
>
> *
> *   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/
>

--
Best,
Mitch

Arnelyn Abdon
+639178034402