[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Data transformation
From
Keith Dear <[email protected]>
To
[email protected]
Subject
Re: st: Data transformation
Date
Mon, 12 Nov 2007 21:43:28 +1100
clear
input Accidentnr vehiclenr weight cost
1 0 1000 35000
1 1 1500 150000
2 0 1200 150000
2 1 1700 750000
end
bys Accidentnr: egen othersweight=sum(weight)
bys Accidentnr: egen otherscost=sum(cost)
replace othersweight=othersweight-weight
replace otherscost=otherscost-cost
rename weight ownweight
rename cost owncost
At 09:19 PM 12/11/2007, you wrote:
=====================Dear all.
I have a dataset concerning accidents involving two vehicles that I have
in two formats, wide and long like this:
long:
Accidentnr vehiclenr weight cost
1 0 1000 35000
1 1 1500 150000
2 0 1200 150000
2 1 1700 750000
wide:
Accidentnr weight0 weight1 cost0 cost1
1 1000 1500 35000 150000
2 1200 1700 150000 750000
Now I whould like to transform the data to a long format but with
information also concering the other vehicle involved in each accident
like this:
Accidentnr vehiclenr ownweight othersweight owncost
otherscost
1 0 1000 1500
35000 150000
1 1 1500 1000
150000 35000
2 0 1200 1700
150000 750000
2 1 1700 1200
750000 150000
Any suggestions on how this can be done?
Best Regards
Lina Jonsson
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
Keith Dear
8 Ord Street, Forrest
ACT 2603, Australia
Tel: 02 6273 2208
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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 |