Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: -reshape-, or -by-?


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: -reshape-, or -by-?
Date   Thu, 10 Apr 2003 10:55:44 +0100

Richard Sherman

> I have a data set of country-years over EU countries that 
> looks roughly like this:
> 
> country	year	var1	var2	...
> 
> Austria	1995	1	2
> ...		...	...	...
> Austria	2000	3	4
> ...		...	...	...
> ...		...	...	...
> UK		1973	9	10
> ...		...	...	...
> UK		2000	11	12
> 
> As a getting-to-know-Stata assignment, I had my students 
> use this data to
> construct a data set with values of the variables summed 
> across the EU
> countries.  The idea was to create a data set that had the 
> total of each
> variable for the EU as a whole.
> 
> I had them use -reshape- and -egen rsum()- to do this.  
> This method first
> reshapes the data like this:
> 
> year	var1Austria	var2Austria ...	var1UK		var2UK	...
> 
> 1973	.		.			9		10
> ...
> 2000	3		4			11		12
> 
> and then sums across var1*, var2*, etc., using a -for any- 
> construction.
> 
> I added that there might be a simpler method (perhaps 
> involving -by-), but
> none of them took me up on this.  Is there a simpler way to 
> do this kind of
> thing (perhaps involving -by-)?

Nick Winter provided a concise -egen- solution. 

This is just to note that for this problem -- constructing 
a data set -- -collapse- is another way to do it. 

Nick 
[email protected] 
*
*   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