Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: Re: st: RE: RE: Data management


From   n j cox <[email protected]>
To   [email protected]
Subject   Re: Re: st: RE: RE: Data management
Date   Wed, 21 Mar 2007 18:30:13 +0000

As I understand it, each -tvol- is repeated for each
-id year- combination, but you want to use its value
just once. That's a little tricky, but it looks all
downhill from there.

egen tag = tag(id year)
egen tsum = total(tag * tvol), by(year)
gen tshare1 = tvol / tsum
gen tshare2 = tvol / (tsum - tvol)

Nick
[email protected]

Roy,Suryadipta

I am actually trying to generate the last three
columns (tsum, tshare1, tshare2). Their formulae are given
below the data:

id year	oid    did     dist tvol     tsum tshare1 tshare2
1 2000	1	2	5	1	6	0.17	0.2
1 2000	1	3	10	1	6	0.17	0.2
1 2000	1	4	15	1	6	0.17	0.2
1 2001	1	2	5	2	4	0.5	1
1 2001	1	3	10	2	4	0.5	1
1 2001	1	4	15	2	4	0.5	1
1 2002	1	2	5	3	17	0.18  0.21
1 2002	1	3	10	3	17	0.18  0.21
1 2002	1	4	15	3	17	0.18  0.21
2 2001	2	1	5	2	4	0.5	1
2 2001	2	3	4	2	4	0.5	1
2 2001	2	4	2	2	4	0.5	1
2 2002	2	1	5	4	17	0.24  0.31
2 2002	2	3	4	4	17	0.24  0.31
2 2002	2	4	2	4	17	0.24  0.31
4 2000	4	1	15	5	6	0.83	5
4 2000	4	2	2	5	6	0.83	5
4 2000	4	3	5	5	6	0.83	5
4 2001	4	1	15		4		
4 2001	4	2	2		4		
4 2001	4	3	5		4		
4 2002	4	1	15	10	17	0.59  1.43
4 2002	4	2	2	10	17	0.59  1.43
4 2002	4	3	5	10	17	0.59  1.43

tsum= sum of tvol for all id-s on any particular year;
tshare1= tvol/tsum;
tshare2=tvol/(tsum-tvol).
*
*   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