Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


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

st: Subtracting observations by group


From   AGAOGLU Enes <s1236623@sms.ed.ac.uk>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   st: Subtracting observations by group
Date   Fri, 21 Jun 2013 14:45:11 +0000

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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index