Bookmark and Share

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   Abu Camara <[email protected]>
To   [email protected]
Subject   Re: st: aggregation
Date   Tue, 19 Jun 2012 10:52:38 +0300

Thanks for the help.

I am looking for a table like below and I have modified your code a bit
where total is the mean over the BRICS countries. I am trying to aggregate
GDP growth of these countries to have a combined annual growth using the
weight as the weight variable.

I am getting the same result as before.
==================

. table  country_code year [aweight=weight], c(mean gdp_growth) row

		
year		
country_code       2005       2006       2007       2008       2009	2010	2011
		
Brazil      3.156      3.955      6.095      5.169      -.328	7.534	2.733
China      11.31     12.677     14.162      9.635      9.214	10.447	9.237
India      9.033       9.53      9.991      6.186      6.579	10.623	7.241
Russia      6.388      8.153      8.535      5.248       -7.8	4.3	4.3
South Africa      5.277      5.604      5.548      3.619     -1.537	2.89	3.148

Total   8.762289  9.9759976  11.207879  7.5822792  5.1602449	9.2256645	7.3804931

======================================================
On 19 June 2012 10:42, Maarten Buis <[email protected]> wrote:
> 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/



-- 
Best Wishes,

Abu Camara

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index