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
Eric Booth <[email protected]>
To
"<[email protected]>" <[email protected]>
Subject
Re: st: row wise summation in panel data for particular IDs
Date
Sun, 9 Jan 2011 22:14:58 +0000
<>
Take a look at the responses to the thread here: http://www.stata.com/statalist/archive/2010-12/msg00887.html
If this is really what you want, you can also do this:
**********************!
clear
**setup**
inp id year var1
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
end
g var2 = int(abs(runiform()*10)) //create another var
**
preserve
collapse (sum) var1 var2 if id!=3, by(year)
g id = 4
sa using.dta, replace
restore
**
append using "using.dta"
l
*******
*******
**better yet use tabout to view sums for id 1 & 2:
**
cap which tabout
if _rc ssc install tabout //install -tabout-
**
tabout year using "sum_table.xls", ///
replace sum c(sum var1 sum var2) f(0c) ///
ptotal(both) h2(Summary Table)
di as smcl `"Click to View: {browse "sum_table.xls"}"'
**********************!
- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
Office: +979.845.6754
On Jan 9, 2011, at 3:57 PM, <[email protected]>
wrote:
> 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/