Bookmark and Share

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: how do you subtract the value of one group from the value of another group?


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: how do you subtract the value of one group from the value of another group?
Date   Tue, 20 Aug 2013 00:34:03 +0100

This is the reverse of what you asked previously. In fact, unless you
are not explaining something you don't even have panel data. Perhaps
you should explain what is the panel identifier and why you (appear
to) have varying numbers of replicates.

Nick
[email protected]


On 19 August 2013 22:44, Ken Ning <[email protected]> wrote:
> Hi Nick,
>
> Thanks a lot for getting back to me.
>
> In fact, i have an unbalanced panel data and I calculate a value for
> each year in each group. I want the same group (e.g. group 1) in year
> 2 (e.g 2002) to have the value of the year 1 (2001) subtracted from it
> within the same group (i.e. 9-7, and 6-9) and repeat the same process
> for group 2 (12-11, 11-10 etc)
>
>
>
> group    year    value
> 1    2001    7
> 1    2001    7
> 1    2001    7
> 1    2001    7
> 1    2002    9
> 1    2002    9
> 1    2002    9
> 1    2002    9
> 1    2003    6
> 1    2003    6
> 1    2003    6
> 1    2003    6
>
> 2    2001    10
> 2    2001    10
> 2    2001    10
> 2    2002    11
> 2    2002    11
> 2    2002    11
> 2    2003    12
> 2    2003    12
> 2    2003    12
>
> Many thanks
>
> Ken
>
>
>
>
> On 19 August 2013 21:36, Nick Cox <[email protected]> wrote:
>> That wasn't my suggestion, which was geared to your example with just 2 groups.
>>
>> Now you tell us you have many groups. You need to tell us how
>> differences are defined.
>>
>> Your code looks _legal_, so I don't understand the error message.
>>
>> If people don't state the real problem, poor solutions are all too likely.
>>
>> Nick
>> [email protected]
>>
>>
>> On 19 August 2013 21:05, Ken Ning <[email protected]> wrote:
>>> Hi Nick,
>>>
>>> Thanks a lot for this.
>>>
>>> As I have many groups, I tried this following your suggestion
>>>
>>> bysort year (id) : gen diff = value[_n] - value[_n-1]
>>>
>>>
>>> but it says "factor variables and time-series operators not allowed"
>>>
>>> What did i do wrong?
>>>
>>> Many thanks
>>> Lutao
>>>
>>>
>>>
>>> On 19 August 2013 20:43, Ken Ning <[email protected]> wrote:
>>>> Hi statausers
>>>>
>>>> how do you subtract the value of one group from the value of another group?
>>>>
>>>> e.g. if i want to substract the value of group 2 (value= 11 in 2001
>>>> and 12 in 2002) from group1 (value= 7 in 2001 and 8 in 2002) year by
>>>> year? so this needs to be 11-7 and 12-8 and listed next to the value
>>>> of group 2
>>>>
>>>>
>>>>
>>>> id year value  (minus value)
>>>> 1 2001   7     .
>>>> 1 2001   7    .
>>>> 1 2001   7   .
>>>> 1 2002    8  .
>>>> 1 2002    8  .
>>>> 1 2002    8  .
>>>>
>>>> 2 2001   11     x (need to get)
>>>> 2 2001   11     x
>>>> 2 2001   11     x
>>>> 2 2002   12     x
>>>> 2 2002   12     x
>>>> 2 2002   12     x
>>>>
>>>> Many thanks
>>>> Ken
>>>> *
>>>> *   For searches and help try:
>>>> *   http://www.stata.com/help.cgi?search
>>>> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index