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: Subtracting observations by group


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Subtracting observations by group
Date   Fri, 21 Jun 2013 15:53:39 +0100

You said what you wanted, but you didn't say where to put it.

Here's one way to approach it.

bysort date (group) : gen price1M3 = price[1] - price[3]

That way, the same difference will be repeated. You will want
something more limited but that's just an extra condition.
Nick
[email protected]


On 21 June 2013 15:45, AGAOGLU Enes <[email protected]> wrote:
> Dear Stata-listers,
>
> I have the following dataset and I would like to subtract price by groups.
>
> date group price
> 2010m1 1 10
> 2010m2 1 15
> 2010m3 1 12
> 2010m1 2 9
> 2010m2 2 21
> 2010m3 2 15
> 2010m1 3 8
> 2010m2 3 20
> 2010m3 3 16
>
> For instance, if I want to subtract group 1's prices from group 3's prices, the new variable should be the following:
>
> newvar
> 2
> -5
> -4
>
> Since observations are in the same variable(price), I couldn't figure out how to do it. I tried to create a new variable only for group 1 and group 3, but then it looked like the following. Thus, I couldn't subtracted g1 from g3.
>
> g1 g3
> 10 .
> 15 .
> 12 .
> . 8
> . 20
> . 16
>
> Thank you in advance for any help,
>
> -Enes
>
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
>
> *
> *   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