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]

From |
"Philip Ryan" <[email protected]> |

To |
<[email protected]> |

Subject |
RE: st: RE: Calculating average value using STATA program language |

Date |
Mon, 12 Sep 2011 14:35:11 +0930 |

Suryadipta You are welcome, and, as Steve says, welcome to the List. Stata is such a rich environment that it is sometimes a challenge to arrive at what, in retrospect, seems a straightforward way of manipulating data for your purpose. My advice is that time spent reading - all the way through! - both the User Guide and the Data Management Volumes of the official documentation is time extraordinarily well spent. You will get an feeling for what is possible that will repay you many times over. Phil Philip Ryan University of Adelaide -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Suryadipta Roy Sent: Monday, 12 September 2011 2:20 PM To: [email protected] Subject: Re: st: RE: Calculating average value using STATA program language Phil, -collapse- works great. I spent quite some time with the loops today! Thank you so much! Best regards, Suryadipta. On Mon, Sep 12, 2011 at 12:10 AM, Philip Ryan <[email protected]> wrote: > <<>> > > Instead of -foreach- or -forvalues- loops, try using -collapse-, for > example: > > collapse (sum) sum_imp=imports (mean) avg_imp=imports, by(importer exporter > isic) > > Phil > > Philip Ryan > University of Adelaide > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Suryadipta Roy > Sent: Monday, 12 September 2011 1:17 PM > To: [email protected] > Subject: st: Calculating average value using STATA program language > > Hello everyone, > I am a newbie in terms of writing STATA codes, and intend to get that > corrected pretty soon. Meanwhile, I was wondering if any one could > help me with the following. I have been trying use foreach/forvalues > without any success for some time. Any help/suggestion/hint is greatly > appreciated. > > importer exporter year isic imports sum_import > avg_import > AUS FRA 1979 311 8 24 12 > AUS FRA 1980 311 16 24 12 > AUS FRA 1979 313 0 0 0 > AUS FRA 1980 313 0 0 0 > AUS GAB 1979 369 0 0 0 > AUS GBR 1976 311 10 30 10 > AUS GBR 1977 311 20 30 10 > AUS GBR 1978 311 0 30 10 > AUT CAN 1977 312 10 10 10 > AUT CAN 1978 390 20 20 20 > FRA AUS 1976 311 5 10 5 > FRA AUS 1977 311 5 10 5 > FRA AUT 1980 369 4 4 4 > > In the hypothetical dataset above, I am trying to create the last two > columns (sum_import, and avg_import) from the "imports" column. For > the first column, the idea is to calculate the sum of imports e.g. > from FRA to AUS for each industry category (isic). Thus for the isic > category 311, the sum of imports in 1979 and 1980 is 8 + 16 = 24, and > the average in the two years is 12. Similarly, there were no trade > between AUS and GAB in 1979 for the industry category 369, and hence > the sum and the average value of imports = 0. The actual dataset has > over 200 countries covering data from 1976 - 1980 and I am trying to > calculate the average of the imports between 1976- 1980 in each > industry category. There are 28 such industry categories. > > I remain grateful for any help. > > Sincerely, > Suryadipta. > * > * 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/ > > * > * 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/ > * * 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/ * * 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/

**References**:**st: Calculating average value using STATA program language***From:*Suryadipta Roy <[email protected]>

**Re: st: RE: Calculating average value using STATA program language***From:*Suryadipta Roy <[email protected]>

- Prev by Date:
**Re: st: estadd margins with multiple outcome models** - Next by Date:
**Re: st: Counting observations between dates by group** - Previous by thread:
**Re: st: RE: Calculating average value using STATA program language** - Next by thread:
**Re: st: Calculating average value using STATA program language** - Index(es):