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: aggregation
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: aggregation
Date
Tue, 19 Jun 2012 09:42:00 +0200
On Tue, Jun 19, 2012 at 9:19 AM, Abu Camara wrote:
> Dear Statalist,
>
> I am doing some aggregation (total) for the BRICS countries. I am
> having different results with Stata if I use Excel. I did it manually
> and I get exactly the same result as Excel.
Here are two ways to get the weighted total by country:
*------------------- begin example ---------------------
clear
input ///
year gdp_growth str12 country weight
2005 3.2 Brazil 2.79
2006 4.0 Brazil 2.759
2007 6.1 Brazil 2.781
2008 5.2 Brazil 2.85
2009 -0.3 Brazil 2.866
2010 7.5 Brazil 2.931
2011 2.7 Brazil 2.908
2005 6.4 Russia 2.987
2006 8.2 Russia 3.073
2007 8.5 Russia 3.169
2008 5.2 Russia 3.25
2009 -7.8 Russia 3.024
2010 4.3 Russia 2.999
2011 4.3 Russia 3.021
2005 9.0 India 4.281
2006 9.5 India 4.46
2007 10.0 India 4.661
2008 6.2 India 4.822
2009 6.6 India 5.186
2010 10.6 India 5.455
2011 7.2 India 5.65
2005 11.3 China 9.445
2006 12.7 China 10.123
2007 14.2 China 10.98
2008 9.6 China 11.73
2009 9.2 China 12.926
2010 10.4 China 13.576
2011 9.2 China 14.322
2005 5.3 "South Africa" 0.714
2006 5.6 "South Africa" 0.718
2007 5.5 "South Africa" 0.72
2008 3.6 "South Africa" 0.727
2009 -1.5 "South Africa" 0.722
2010 2.9 "South Africa" 0.706
2011 3.1 "South Africa" 0.704
end
encode country , gen(country_code)
table country_code [aweight=weight], c(sum gdp_growth)
// alternatively
collapse (sum) gdp_growth [aweight=weight], by(country)
list
*-------------------- end example ----------------------
(For more on examples I sent to the Statalist see:
http://www.maartenbuis.nl/example_faq )
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/