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

st: -reshape-, or -by-?


From   Richard Sherman <[email protected]>
To   [email protected]
Subject   st: -reshape-, or -by-?
Date   Wed, 09 Apr 2003 10:38:36 -0400

Dear statalist,

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-)?

Thanks for your help,

Richard


-----------------------------------------------
Richard Sherman
Assistant Professor of Political Science
Maxwell School of Citizenship and Public Affairs
Syracuse University
Syracuse NY 13244-1090  USA
tel. 315-443-9119	fax  315-443-9082
http://www.maxwell.syr.edu/maxpages/faculty/sherman
*
*   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