Statalist


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

RE: st: RE: combining panel data values


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: combining panel data values
Date   Tue, 21 Oct 2008 19:34:05 +0100

Your data structure is now clearer. Thanks for that. I gather that you
mean "add".

Here is one way to proceed: 

. l

     +-----------------------+
     | month   sales   brand |
     |-----------------------|
  1. |     1      25       1 |
  2. |     2      13       1 |
  3. |     3      19       1 |
  4. |     4      23       1 |
  5. |     1      21       2 |
     |-----------------------|
  6. |     2      17       2 |
  7. |     3      19       2 |
  8. |     4      26       2 |
  9. |     1      11       3 |
 10. |     2      19       3 |
     |-----------------------|
 11. |     3      19       3 |
 12. |     4      28       3 |
     +-----------------------+

. reshape wide sales, i(month) j(brand)
(note: j = 1 2 3)

Data                               long   ->   wide
------------------------------------------------------------------------
-----
Number of obs.                       12   ->       4
Number of variables                   3   ->       4
j variable (3 values)             brand   ->   (dropped)
xij variables:
                                  sales   ->   sales1 sales2 sales3
------------------------------------------------------------------------
-----

. l

     +----------------------------------+
     | month   sales1   sales2   sales3 |
     |----------------------------------|
  1. |     1       25       21       11 |
  2. |     2       13       17       19 |
  3. |     3       19       19       19 |
  4. |     4       23       26       28 |
     +----------------------------------+

. gen sales1and2 = sales1 + sales2

. l

     +---------------------------------------------+
     | month   sales1   sales2   sales3   sales1~2 |
     |---------------------------------------------|
  1. |     1       25       21       11         46 |
  2. |     2       13       17       19         30 |
  3. |     3       19       19       19         38 |
  4. |     4       23       26       28         49 |
     +---------------------------------------------+


Nick
[email protected] 

Sean Lunde

by combine, I mean that my data is organized like this:

Month | Sales | Brand

1	|	25	|	1
2	|	13	|	1
3	|	19	|	1
4	|	23	|	1
1	|	21	|	2
2	|	17	|	2
3	|	19	|	2
4	|	26	|	2
1	|	11	|	3
2	|	19	|	3
3	|	19	|	3
4	|	28	|	3

What I want to do, is combine the values of sales when brand is equal  
to 1 with the values when brand is equal to 2, creating a new brand,  
with observations for each month. However, I want to keep the data  
organized in the time periods.

On Oct 21, 2008, at 2:06 PM, Nick Cox wrote

> What does "combine" mean? If it means add, then know that
>
> gen z = x + y
>
> is the way to add two variables to produce a third.

Sean Lunde

> I am working with a set of panel data grouped by brand (the panel var)
> and date (the time var). I want to combine the values of some of the
> brand variables together,( e.g. combine the salesdollar value for
> brand x with salesdollar value for brand y). All of the variables I
> want to combine are numeric.
>

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index