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/