Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: panel - rowtotal
From
Benodet Karia <[email protected]>
To
<[email protected]>
Subject
RE: st: panel - rowtotal
Date
Sun, 14 Nov 2010 01:42:55 +0000
Hi Mitch,
Yes I have unique code for each unit.
I think the code you wrote is not exactly what I need. I thought rather than column, I need to do it by row because although the units are listed in the 2nd column (in panel format), what I am trying to do is just to sum the sales of particular units at each date. So, first, somewhere in the code, I need to define the unit codes that should be summed up (I will type these one by one from my list). And secondly, the code should do it for each date.
For example, I want to sum the sales of units A, B and C which seem at row10, 30 and 150 respectively at date1. When I write the unit codes, the sales in row 10, 30 and 150 (for date1) should be added as sum_ABC_date1.Similarly for date2, the sales of the same units (A, B, C) (say in row 300, 325 and 470) should be added as sum_ABC_date2 and so on. Then I can drop the A, B, C's and work with sum_ABC_datei ones. Obviously sum_ABC_datei's will be created as additional rows (not columns).
Hope I didnt explain it in a complex way?
bk
----------------------------------------
> Date: Sun, 14 Nov 2010 07:56:55 +0800
> Subject: Re: st: panel - rowtotal
> From: [email protected]
> To: [email protected]
>
> 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 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
> http://statadaily.wordpress.com
> http://www.facebook.com/pages/Stata-Daily/116477895082525
>
> *
> * 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/