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: row wise summation in panel data for particular IDs


From   [email protected]
To   [email protected]
Subject   Re: st: row wise summation in panel data for particular IDs
Date   Sun, 09 Jan 2011 17:13:07 -0500

Forgot to add what I have already tried.
I used:

***
gen c=0
replace c=1 if id==1 | id==2
collapse (sum) var1, by (c year)
egen newid=group(id)
***

But, last line does not run, as old 'id' is already cleard. And, other variables, var2, var3...etc also do not show up any more.

I think there must be some other easier and more flexible way.


thx,
prabhat


Quoting [email protected]:

Dear all,

I am required to take into account the changes in boundary of cities
over a period so that all the information can be attributed to the
parent cities at the start of the time period. I have already tried but
could not find a similar case in previous threads.

This is a panel data , say with id, year and vars. I need to merge
(sum or weighted sum) two particular ids completely to form a new one.
For instance, I have:

id	year	var1   var2   var3
1	2001	40
1	2002	50
1	2003	60
2	2001	400
2	2002	500
2	2003	600
3	2001	4000
3	2002	5000
3	2003	6000


desired Output will be like (summing up corresponding values of var1 in
given year for id 1 and 2, keeping 3 intact and having the results in a
newly created id, say 4).

id	year	var1     var2   var3
1	2001	40
1	2002	50
1	2003	60
2	2001	400
2	2002	500
2	2003	600
3	2001	4000
3	2002	5000
3	2003	6000
4	2001	440
4	2002	550
4	2003	660

Any help will be appreciated.


Thanks.

Prabhat

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/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/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index