Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Merge data for two panels in a panel data set


From   "rado645-bg@yahoo.de" <rado645-bg@yahoo.de>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Merge data for two panels in a panel data set
Date   Mon, 26 Mar 2012 16:59:42 +0100 (BST)

Dear Erik,

thanks for helping me on that. I have adjusted your code but I struggle now with running one of the code lines:

collapse (sum) item1, by(collapseind date)

Since I have many variables (about 60), I would like to make the summation for all of them at once. I have tried with the following command following your suggestion:

collapse (sum) _all, by(collapseind date)

but I get the following message by Stata:

"collapseind may not be both target and by()"

I wonder if it is possible to overcome this. I also have some string variables. Is it possible to say Stata to keep the string variables only for the one firm that continues to carry the firm name after the merger (i.e. Firm 2)? 

Rado



----- Ursprüngliche Message -----
Von: Eric Booth <eric.a.booth@gmail.com>
An: statalist@hsphsun2.harvard.edu
CC: 
Gesendet: 16:48 Montag, 26.März 2012
Betreff: Re: st: Merge data for two panels in a panel data set

On Mar 26, 2012, at 9:35 AM, rado645-bg@yahoo.de wrote:

> Dear all,
> 
> I have two firms in a data set that merge at a given point of time. For a specific reason, I need to sum the observations over their balance sheet items in each period of time. Would that be possible in Stata? 
> 
> 
> The dataset looks like that:
> 
> Firm        Date    Item1    Item2    Item3
> 
> 
> Firm1     Date1   Item1    Item2    Item3
> 
> Firm2      Date1   Item1     Item2    Item3
> 
> Firm3      Date1  Item1    Item2     Item3
> 
> ...so on.
> 

If you want to add across item1-item3, then:

egen sum = rowtotal(Item1-Item3) 

will do it. See -help egen-. 





> I would like to merge in each period of time the data for firm 1 and firm 2 so the dataset will look like that: 
> 
> 
> The dataset looks like that:
> 
> Firm                  Date     Item1  Item2  Item3
> 
> 
> Merged_Firms    Date1  Item1  Item2  Item3
> 
> Firm3               Date1  Item1  Item2  Item3
> 


I think you are asking how to -collapse- just Firms 1 and 2 in each year of your dataset.  This example would need to be expanded to account for the total # of Firms you have in your data and how you want to -collapse- them, but it reproduces your example table above:

**********
clear
inp firm date item1
1 2007 45
2 2007 50
3 2007 99
end

g collapseind = 1 if inlist(firm, 1, 2)
replace collapseind = 0 if mi(collapseind)

collapse (sum) item1, by(collapseind date)
lab def x 0 "Firm 3" 1 "Merged Firms"
lab val collapseind x
li
**********


-Eric


__
Eric A. Booth
Public Policy Research Institute 
Texas A&M University
ebooth@ppri.tamu.edu
+979.845.6754





> I would like to thank for your consideration in advance.
> 
> Best,
> Rado
> 
> 
> *
> *   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?searchhttp://www.stata.com/support/statalist/faqhttp://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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index