Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | AGAOGLU Enes <s1236623@sms.ed.ac.uk> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: Re: st: Subtracting observations by group |
Date | Fri, 21 Jun 2013 15:03:56 +0000 |
Thank you Nick, I added that extra condition and I now have what I want. On Fri, Jun 21, 2013 at 3:53 PM, Nick Cox <njcoxstata@gmail.com> wrote: > 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 > njcoxstata@gmail.com > > > On 21 June 2013 15:45, AGAOGLU Enes <s1236623@sms.ed.ac.uk> 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/ -- 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/